Paste: produce-sum

Author: jon
Mode: factor
Date: Thu, 17 Sep 2009 15:57:16
Plain Text |

: sum-push ( elt vector -- )
    [ pop + ] keep push ;

: my-push ( elt vector -- )
    dup empty? [ push ] [ sum-push ] if ; inline

: my-accumulator ( quot -- quot' vec )
    V{ } clone [ [ my-push ] curry compose ] keep ; inline

: produce-sum ( pred: ( -- ? ) quot: ( -- elt ) -- sum )
    my-accumulator [ while ] dip first ; inline

New Annotation

Summary:
Author:
Mode:
Body: