PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/extra/combinators/tuple/tuple.factor

http://github.com/abeaumont/factor
Unknown | 29 lines | 21 code | 8 blank | 0 comment | 0 complexity | 0ce6565de6ade4aba3850d5a773e146e MD5 | raw file
 1! (c)2009 Joe Groff bsd license
 2USING: accessors assocs classes.tuple generalizations kernel
 3locals quotations sequences ;
 4IN: combinators.tuple
 5
 6<PRIVATE
 7
 8:: (tuple-slot-quot) ( slot assoc n -- quot )
 9    slot name>> assoc at [
10        slot initial>> :> initial
11        { n ndrop initial } >quotation
12    ] unless* ;
13
14PRIVATE>
15
16MACRO:: nmake-tuple ( class assoc n -- )
17    class all-slots [ assoc n (tuple-slot-quot) ] map :> quots
18    class <wrapper> :> \class
19    { quots n ncleave \class boa } >quotation ;
20    
21: make-tuple ( x class assoc -- tuple )
22    1 nmake-tuple ; inline
23
24: 2make-tuple ( x y class assoc -- tuple )
25    2 nmake-tuple ; inline
26
27: 3make-tuple ( x y z class assoc -- tuple )
28    3 nmake-tuple ; inline
29