42 lines
1.1 KiB
Factor
42 lines
1.1 KiB
Factor
! Copyright (C) 2007 Chris Double, Doug Coleman.
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
USING: kernel sequences namespaces math inference.transforms
|
|
combinators macros quotations math.ranges bake ;
|
|
|
|
IN: shuffle
|
|
|
|
: 2dip -rot 2slip ; inline
|
|
|
|
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
|
|
|
|
MACRO: ntuck ( n -- ) 2 + [ dup , -nrot ] bake ;
|
|
|
|
: 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
|
|
|
|
: 4nip ( a b c d e -- e ) 4 nnip ; inline
|
|
|
|
: 4dup ( a b c d -- a b c d a b c d ) 4 ndup ; inline
|
|
|
|
: 4drop ( a b c d -- ) 3drop drop ; inline
|
|
|
|
: tuckd ( x y z -- z x y z ) 2 ntuck ; inline
|
|
|
|
MACRO: nrev ( n -- quot )
|
|
[ 1+ ] map
|
|
reverse
|
|
[ [ -nrot ] curry ] map concat ;
|