factor/basis/shuffle/shuffle.factor

18 lines
562 B
Factor

! Copyright (C) 2007 Chris Double, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs combinators effects.parser fry
generalizations kernel macros make sequences
sequences.generalizations ;
IN: shuffle
MACRO: shuffle-effect ( effect -- quot )
[ in>> H{ } zip-index-as ] [ out>> ] bi
[ drop assoc-size '[ _ narray ] ]
[ [ of '[ _ swap nth ] ] with map ] 2bi
'[ @ _ cleave ] ;
SYNTAX: shuffle(
")" parse-effect suffix! \ shuffle-effect suffix! ;
: 2swap ( x y z t -- z t x y ) 2 2 mnswap ; inline