Created
November 1, 2011 18:48
-
-
Save missingfaktor/1331510 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| USING: math.ranges io.encodings.utf8 xml concurrency.combinators ; | |
| ! 1. Multiply Each Item in a List by 2 | |
| 10 [1,b] [ 2 * ] map | |
| ! 2. Sum a List of Numbers | |
| 1000 [1,b] sum | |
| ! 3. Verify if Exists in a String | |
| : word-list ( -- seq ) { "Factor" "Concatenative" "Point-free" } ; | |
| : tweet ( -- str ) "This is an example tweet that talks about Factor." ; | |
| word-list [ tweet subseq? ] any? | |
| ! 4. Read in a File | |
| "F:/data.txt" utf8 file-contents | |
| "F:/data.txt" utf8 file-lines | |
| ! 5. Happy birthday to you! | |
| 4 [1,b] [ "Happy birthday " swap 3 = "dear Pradnya!" "to you!" ? append ] map [ . ] each | |
| ! Or: (suggested by @abeaumont on #concatenative) | |
| "Happy birthday " 4 [ 2 = "dear Pradnya!" "to you!" ? append . ] with each-integer | |
| ! 6. Partition List of Numbers as per the Predicate | |
| { 49 58 76 82 88 90 } [ 60 < ] partition | |
| ! 7. Fetch and Parse an XML web service | |
| "http://search.twitter.com/search.atom?&q=factor" <pull-xml> | |
| ! 8. Find minimum (or maximum) in a List | |
| { 14 35 -7 46 98 } infimum | |
| { 14 35 -7 46 98 } supremum | |
| ! 9. Parallel Processing | |
| data-list [ process-item ] parallel-map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment