rename nths to switches

add ?nth* and nths to sequences.lib
db4
Doug Coleman 2008-03-06 17:10:56 -06:00
parent 635749a50b
commit 61c77e616f
1 changed files with 9 additions and 3 deletions

View File

@ -140,13 +140,13 @@ PRIVATE>
: strings ( alphabet length -- seqs )
>r dup length r> number-strings map-alphabet ;
: nths ( nths seq -- subseq )
! nths is a sequence of ones and zeroes
: switches ( seq1 seq -- subseq )
! seq1 is a sequence of ones and zeroes
>r [ length ] keep [ nth 1 = ] curry subset r>
[ nth ] curry { } map-as ;
: power-set ( seq -- subsets )
2 over length exact-number-strings swap [ nths ] curry map ;
2 over length exact-number-strings swap [ switches ] curry map ;
: push-either ( elt quot accum1 accum2 -- )
>r >r keep swap r> r> ? push ; inline
@ -214,3 +214,9 @@ PRIVATE>
: attempt-each ( seq quot -- result )
(each) iterate-prep (attempt-each-integer) ; inline
: ?nth* ( n seq -- elt/f ? )
2dup bounds-check? [ nth-unsafe t ] [ 2drop f f ] if ; flushable
: nths ( indices seq -- seq' )
[ swap nth ] with map ;