factor/extra/shuffle/shuffle.factor

40 lines
1.0 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2007 Chris Double, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences namespaces math inference.transforms
2008-05-15 00:23:12 -04:00
combinators macros quotations math.ranges fry ;
2007-09-20 18:09:08 -04:00
IN: shuffle
MACRO: npick ( n -- ) 1- dup saver [ dup ] rot [ r> swap ] n*quot 3append ;
MACRO: ndup ( n -- ) dup [ npick ] curry n*quot ;
MACRO: nrot ( n -- ) 1- dup saver swap [ r> swap ] n*quot append ;
MACRO: -nrot ( n -- ) 1- dup [ swap >r ] n*quot swap restorer append ;
MACRO: ndrop ( n -- ) [ drop ] n*quot ;
: nnip ( n -- ) swap >r ndrop r> ; inline
2008-05-15 00:23:12 -04:00
MACRO: ntuck ( n -- ) 2 + '[ dup , -nrot ] ;
2007-09-20 18:09:08 -04:00
: 2swap ( x y z t -- z t x y ) rot >r rot r> ; inline
: nipd ( a b c -- b c ) rot drop ; inline
: 3nip ( a b c d -- d ) 3 nnip ; inline
2008-02-12 12:59:50 -05:00
: 4nip ( a b c d e -- e ) 4 nnip ; inline
2007-09-20 18:09:08 -04:00
: 4dup ( a b c d -- a b c d a b c d ) 4 ndup ; inline
2007-12-09 18:49:33 -05:00
: 4drop ( a b c d -- ) 3drop drop ; inline
2007-09-20 18:09:08 -04:00
: tuckd ( x y z -- z x y z ) 2 ntuck ; inline
2008-02-03 04:48:29 -05:00
MACRO: nrev ( n -- quot )
[ 1+ ] map
reverse
[ [ -nrot ] curry ] map concat ;