curry ( obj quot -- curry )
Factor documentation > Factor handbook > The language > Combinators > Compositional combinators
Prev:Examples of compositional combinator usage
Next:compose ( quot1 quot2 -- compose )


Vocabulary
kernel

Inputs and outputs
objan object
quota callable
currya curry


Word description
Partial application. Outputs a callable which first pushes obj and then calls quot.

Class description
The class of objects created by curry. These objects print identically to quotations and implement the sequence protocol, however they only use two cells of storage; a reference to the object and a reference to the underlying quotation.

Notes
Even if obj is a word, it will be pushed as a literal.

This operation is efficient and does not copy the quotation.

Examples
USING: kernel prettyprint ; 5 [ . ] curry .
[ 5 . ]

USING: kernel prettyprint see ; \ = [ see ] curry .
[ \ = see ]

USING: kernel math prettyprint sequences ; { 1 2 3 } 2 [ - ] curry map .
{ -1 0 1 }


See also
literalize, <wrapper>, \, W{

Definition
IN: kernel

TUPLE: curry { obj read-only } { quot read-only } ;


USING: classes.tuple.private quotations slots ;

IN: kernel

: curry ( obj quot -- curry )
dup callable? [ \ callable bad-slot-value ] unless
{ curry 2 1 tuple 258304024774 curry 258276683045 }
<tuple-boa> ; flushable


Methods
USING: accessors compiler.tree.propagation.call-effect kernel ;

M: curry add-quot-to-history quot>> add-quot-to-history ;


USING: accessors compiler.tree.propagation.call-effect kernel ;

M: curry already-inlined-quot? quot>> already-inlined-quot? ;


USING: accessors compiler.tree.propagation.call-effect kernel ;

M: curry cached-effect quot>> cached-effect curry-effect* ;


USING: kernel quotations.private ;

M: curry call uncurry call ;


USING: accessors kernel math sequences ;

M: curry length quot>> length 1 + ;


USING: accessors kernel math quotations sequences ;

M: curry nth
over 0 =
[ nip obj>> literalize ] [ [ 1 - ] dip quot>> nth ] if ;


USING: kernel prettyprint.custom ;

M: curry pprint* pprint-object ;


USING: kernel prettyprint.custom ;

M: curry pprint-delims drop \ [ \ ] ;