]> gitweb.factorcode.org Git - factor.git/blob - basis/shuffle/shuffle.factor
assocs: Make map-index-as support seq or assoc exemplars and move map-index, map...
[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 sequences.generalizations hashtables kernel
5 locals locals.backend macros make math parser sequences ;
6 IN: shuffle
7
8 MACRO: shuffle-effect ( effect -- )
9     [ out>> ] [ in>> H{ } zip-index-as ] bi
10     [
11         [ nip assoc-size , \ narray , ]
12         [ [ at \ swap \ nth [ ] 3sequence ] curry map , \ cleave , ] 2bi
13     ] [ ] make ;
14
15 SYNTAX: shuffle(
16     ")" parse-effect suffix! \ shuffle-effect suffix! ;
17
18 : tuck ( x y -- y x y ) swap over ; inline deprecated
19
20 : spin ( x y z -- z y x ) swap rot ; inline deprecated
21
22 : roll ( x y z t -- y z t x ) [ rot ] dip swap ; inline deprecated
23
24 : -roll ( x y z t -- t x y z ) swap [ -rot ] dip ; inline deprecated
25
26 : 2swap ( x y z t -- z t x y ) 2 2 mnswap ; inline