Paste: parallel combinator: "banana"

Author: jn
Mode: factor
Date: Mon, 5 Jan 2009 09:33:20
Plain Text |
Here are the semantics:

           S (| F |)  ==  S F
       S (| F , G |)  ==  S F { S G } peek
   S (| F , G , H |)  ==  S F { S G } peek { S H } peek
                      ..

Here are some examples:

               5 (| sq , neg |)  ==  25 -5
                4 3 (| + , * |)  ==  7 12
           1 2 (| nip , drop |)  ==  2 1        ! same as 'swap'
   { 2 3 4 } (| rest , first |)  ==  { 3 4 } 2  ! same as 'unclip'

Here is the implementation:

   : infra-seq ( seq seq -- seq )
       [ [ with-datastack peek ] curry keep ] each drop ;
   : datastack-tail ( x -- x seq )
       [ datastack ] dip swap ;
   : parallel ( seq -- )
       datastack-tail [ unclip dip ] dip swap infra-seq ;

   ! "banana syntax" for 'parallel':
   ! (| F , G |) == { [ F ] [ G ] } parallel
   : |) ;
   : (| \ |)
       [ \ , 1array split [ >quotation ] map ] parse-literal
       \ parallel suffix ; parsing

New Annotation

Summary:
Author:
Mode:
Body: