]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/channels/examples/examples.factor
factor: trim using lists
[factor.git] / basis / channels / examples / examples.factor
index 1e51fb06d8f68106bef94558503014e69635edc8..fb312a56d34ecbfd6e4d9e35501523417e88b8df 100644 (file)
@@ -2,44 +2,42 @@
 ! See http://factorcode.org/license.txt for BSD license.
 !
 ! Examples of using channels
-USING: kernel threads channels math namespaces
-locals sequences ;
+USING: kernel threads channels math sequences ;
 IN: channels.examples
 
 : (counter) ( channel n -- )
-    [ swap to ] 2keep 1+ (counter) ;
-    
+    [ swap to ] 2keep 1 + (counter) ;
+
 : counter ( channel -- )
-    2 (counter) ;    
+    2 (counter) ;
 
 : counter-test ( -- n1 n2 n3 )
-    <channel> dup [ counter ] curry "Counter" spawn drop 
+    <channel> dup [ counter ] curry "Counter" spawn drop
     [ from ] keep [ from ] keep from ;
 
 : filter ( send prime recv -- )
-    #! Receives numbers from the 'send' channel,
-    #! filters out all those divisible by 'prime',
-    #! and sends to the 'recv' channel.
+    ! Receives numbers from the 'send' channel,
+    ! filters out all those divisible by 'prime',
+    ! and sends to the 'recv' channel.
     [
-        from swap dupd mod zero? not [ swap to ] [ 2drop ] if     
+        from swap dupd mod zero? not [ swap to ] [ 2drop ] if
     ] 3keep filter ;
 
 :: (sieve) ( prime c -- )
-    [let | p [ c from ] 
-           newc [ <channel> ] |
-        p prime to
-        [ newc p c filter ] "Filter" spawn drop
-        prime newc (sieve)
-    ] ;
+    c from :> p
+    <channel> :> newc
+    p prime to
+    [ newc p c filter ] "Filter" spawn drop
+    prime newc (sieve) ;
 
-: sieve ( prime -- ) 
-    #! Send prime numbers to 'prime' channel
+: sieve ( prime -- )
+    ! Send prime numbers to 'prime' channel
     <channel> dup [ counter ] curry "Counter" spawn drop
     (sieve) ;
 
 : sieve-test ( -- seq )
     <channel> dup [ sieve ] curry "Sieve" spawn drop
-    V{ } clone swap 
+    V{ } clone swap
     [ from swap push ] 2keep
     [ from swap push ] 2keep
     [ from swap push ] 2keep