]> gitweb.factorcode.org Git - factor.git/blob - basis/shuffle/shuffle.factor
build-from-source: no need to initialize a symbol to f
[factor.git] / basis / shuffle / shuffle.factor
1 ! Copyright (C) 2007 Chris Double, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs combinators effects.parser
4 generalizations kernel sequences sequences.generalizations ;
5 IN: shuffle
6
7 MACRO: shuffle-effect ( effect -- quot )
8     [ in>> H{ } zip-index-as ] [ out>> ] bi
9     [ drop assoc-size '[ _ narray ] ]
10     [ [ of '[ _ swap nth ] ] with map ] 2bi
11     '[ @ _ cleave ] ;
12
13 SYNTAX: shuffle(
14     ")" parse-effect suffix! \ shuffle-effect suffix! ;
15
16 : 2swap ( x y z t -- z t x y ) 2 2 mnswap ; inline
17
18 : 2pick ( x y z t -- x y z t x y ) reach reach ; inline
19
20 : 5roll ( a b c d e -- b c d e a ) [ roll ] dip swap ; inline
21
22 : 6roll ( a b c d e f -- b c d e f a ) [ roll ] 2dip rot ; inline
23
24 : 7roll ( a b c d e f g -- b c d e f g a ) [ roll ] 3dip roll ; inline
25
26 : 8roll ( a b c d e f g h -- b c d e f g h a ) [ roll ] 4dip 5roll ; inline
27
28 : 2reach ( w x y z -- w x y z w x ) reach reach ; inline
29
30 : nipdd ( w x y z -- x y z ) roll drop ; inline