]> gitweb.factorcode.org Git - factor.git/blob - basis/shuffle/shuffle.factor
0ff41edec621ffc1b74d33f0603b722539cc0228
[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 generalizations
4 hashtables kernel locals locals.backend macros make math
5 parser sequences ;
6 IN: shuffle
7
8 <PRIVATE
9
10 : >index-assoc ( sequence -- assoc )
11     dup length zip >hashtable ;
12
13 PRIVATE>
14
15 MACRO: shuffle-effect ( effect -- )
16     [ out>> ] [ in>> >index-assoc ] bi
17     [
18         [ nip assoc-size , \ narray , ]
19         [ [ at \ swap \ nth [ ] 3sequence ] curry map , \ cleave , ] 2bi
20     ] [ ] make ;
21
22 SYNTAX: shuffle(
23     ")" parse-effect suffix! \ shuffle-effect suffix! ;
24
25 : tuck ( x y -- y x y ) swap over ; inline deprecated
26
27 : spin ( x y z -- z y x ) swap rot ; inline deprecated
28
29 : roll ( x y z t -- y z t x ) [ rot ] dip swap ; inline deprecated
30
31 : -roll ( x y z t -- t x y z ) swap [ -rot ] dip ; inline deprecated
32
33 : 2swap ( x y z t -- z t x y ) 2 2 mnswap ; inline
34
35 : 4dup ( a b c d -- a b c d a b c d ) 4 ndup ; inline
36
37 : 4drop ( a b c d -- ) 3drop drop ; inline