2 USING: kernel combinators words quotations arrays sequences locals macros
3 shuffle generalizations fry ;
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9 : >quot ( obj -- quot ) dup word? [ 1quotation ] when ;
11 : >quots ( seq -- seq ) [ >quot ] map ;
13 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15 :: [ncleave] ( SEQ N -- quot )
16 SEQ >quots [ [ N nkeep ] curry ] map concat [ N ndrop ] append >quotation ;
18 MACRO: ncleave ( seq n -- quot ) [ncleave] ;
20 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24 : [narr] ( seq n -- quot ) over length '[ _ _ ncleave _ narray ] ;
26 MACRO: narr ( seq n -- array ) [narr] ;
28 MACRO: 0arr ( seq -- array ) 0 [narr] ;
29 MACRO: 1arr ( seq -- array ) 1 [narr] ;
30 MACRO: 2arr ( seq -- array ) 2 [narr] ;
31 MACRO: 3arr ( seq -- array ) 3 [narr] ;
33 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
35 MACRO: <arr> ( seq -- )
36 [ >quots ] [ length ] bi
37 '[ _ cleave _ narray ] ;
39 MACRO: <2arr> ( seq -- )
40 [ >quots ] [ length ] bi
41 '[ _ 2cleave _ narray ] ;
43 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45 : {1} ( x -- {x} ) 1array ; inline
46 : {2} ( x y -- {x,y} ) 2array ; inline
47 : {3} ( x y z -- {x,y,z} ) 3array ; inline
51 : {bi} ( x p q -- {p(x),q(x)} ) bi {2} ; inline
53 : {tri} ( x p q r -- {p(x),q(x),r(x)} ) tri {3} ; inline
55 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
57 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
59 MACRO: <arr*> ( seq -- )
60 [ >quots ] [ length ] bi
61 '[ _ spread _ narray ] ;
63 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65 : {bi*} ( x y p q -- {p(x),q(y)} ) bi* {2} ; inline
66 : {tri*} ( x y z p q r -- {p(x),q(y),r(z)} ) tri* {3} ; inline