1 ! Copyright (C) 2007 Chris Double, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel sequences namespaces math inference.transforms
4 combinators macros quotations math.ranges bake ;
8 : 2dip -rot 2slip ; inline
10 MACRO: npick ( n -- ) 1- dup saver [ dup ] rot [ r> swap ] n*quot 3append ;
12 MACRO: ndup ( n -- ) dup [ npick ] curry n*quot ;
14 MACRO: nrot ( n -- ) 1- dup saver swap [ r> swap ] n*quot append ;
16 MACRO: -nrot ( n -- ) 1- dup [ swap >r ] n*quot swap restorer append ;
18 MACRO: ndrop ( n -- ) [ drop ] n*quot ;
20 : nnip ( n -- ) swap >r ndrop r> ; inline
22 MACRO: ntuck ( n -- ) 2 + [ dup , -nrot ] bake ;
24 : 2swap ( x y z t -- z t x y ) rot >r rot r> ; inline
26 : nipd ( a b c -- b c ) rot drop ; inline
28 : 3nip ( a b c d -- d ) 3 nnip ; inline
30 : 4nip ( a b c d e -- e ) 4 nnip ; inline
32 : 4dup ( a b c d -- a b c d a b c d ) 4 ndup ; inline
34 : 4drop ( a b c d -- ) 3drop drop ; inline
36 : tuckd ( x y z -- z x y z ) 2 ntuck ; inline
38 MACRO: nrev ( n -- quot )
41 [ [ -nrot ] curry ] map concat ;