compose ( quot1 quot2 -- compose )
Factor documentation > Factor handbook > The language > Combinators > Compositional combinators
Prev:curry ( obj quot -- curry )
Next:2curry ( obj1 obj2 quot -- curry )


Vocabulary
kernel

Inputs and outputs
quot1a callable
quot2a callable
composea compose


Word description
Quotation composition. Outputs a callable which calls quot1 followed by quot2.

Notes
The following two lines are equivalent:
compose call append call

However, compose runs in constant time, and the optimizing compiler is able to compile code which calls composed quotations.

See also
prepose

Definition
IN: kernel

TUPLE: compose { first read-only } { second read-only } ;


USING: classes.tuple.private quotations slots ;

IN: kernel

: compose ( quot1 quot2 -- compose )
[ dup callable? [ \ callable bad-slot-value ] unless ] dip
dup callable? [ \ callable bad-slot-value ] unless
{ compose 2 1 tuple 258304024774 compose 366639970744 }
<tuple-boa> ; flushable


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

M: compose add-quot-to-history
[ first>> add-quot-to-history ]
[ second>> add-quot-to-history ] bi ;


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

M: compose already-inlined-quot?
[ first>> already-inlined-quot? ]
[ second>> already-inlined-quot? ] bi or ;


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

M: compose cached-effect
[ first>> ] [ second>> ] bi [ cached-effect ] bi@
compose-effects* ;


USING: kernel quotations.private ;

M: compose call uncompose [ call ] dip call ;


USING: accessors kernel math sequences ;

M: compose length [ first>> length ] [ second>> length ] bi + ;


USING: kernel prettyprint.custom ;

M: compose pprint* pprint-object ;


USING: kernel prettyprint.custom ;

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


USING: accessors kernel sequences ;

M: compose virtual-exemplar first>> ;


USING: accessors kernel math sequences ;

M: compose virtual@
2dup first>> length <
[ first>> ] [ [ first>> length - ] [ second>> ] bi ] if ;