Paste: reduce+ again

Author: randy
Mode: factor
Date: Sun, 10 May 2009 20:19:05
Plain Text |
: reduce+ ( obj items-seq quot: ( obj item -- obj ) -- obj ) ! mutates an obj based on quot and items
    over empty?
    [ 2drop ] ! leaves obj on the stack
    [ dup [ unclip swap ] 2dip swapd [ call ] 2dip  ! obj rest quot
    reduce+ ] if ; inline

Annotation: a bit simpler

Author: rand
Mode: factor
Date: Sun, 10 May 2009 20:26:51
Plain Text |
: reduce+ ( obj items-seq quot: ( obj item -- obj ) -- obj ) ! mutates an obj based on quot and items
    over empty?
    [ 2drop ] ! leaves obj on the stack
    [ [ unclip swap ] dip tuck 2slip  ! obj rest quot
    reduce+ ] if ; inline

Annotation: --

Author: r
Mode: factor
Date: Tue, 12 May 2009 20:54:14
Plain Text |
: reduce+ ( obj items-seq quot: ( obj item -- obj ) -- obj ) ! mutates an obj based on quot and items
    over empty?
    [ 2drop ] ! leaves obj on the stack
    [ [ [ first ] [ rest ] bi ] dip tuck 2slip  ! obj rest quot
    reduce+ ] if ; inline

Annotation: curried version

Author: randy
Mode: factor
Date: Tue, 12 May 2009 21:09:55
Plain Text |
: reduce+ ( obj items quot -- obj' )
    '[ _ curry ] map (reduce+) drop ;

: (reduce+) ( obj quot-items -- obj' quot-items )
    dup empty? [ unclip swap [ call ] dip (reduce+) ] unless ; recursive

Annotation: uh, +inline

Author: k
Mode: factor
Date: Tue, 12 May 2009 21:22:49
Plain Text |

: (reduce+) ( obj quot-items -- obj' quot-items )
    dup empty? [ unclip swap [ call ] dip (reduce+) ] unless ; inline recursive

: reduce+ ( obj items quot -- obj' )
    '[ _ curry ] map (reduce+) drop ; inline

New Annotation

Summary:
Author:
Mode:
Body: