1 ! Copyright (C) 2022 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators generalizations kernel math sequences ;
6 MACRO: stack-nth ( n -- quot )
11 : stack-set-nth ( obj n -- quot )
12 [ '[ drop _ ] ] dip ndip ; inline
14 : stack-exchange ( m n -- quot )
15 [ [ stack-nth ] [ '[ _ stack-nth ] dip ] bi* ] 2keep
17 [ stack-set-nth ] 2dip stack-set-nth ;
19 : stack-filter ( n quot: ( obj -- ? ) -- quot' )
20 selector [ '[ _ ] replicate spread ] dip ; inline
22 : stack-map ( n quot: ( obj -- obj' ) -- quot' )
23 '[ _ ] replicate spread ; inline