Skip to content

Commit

Permalink
sequences.generalizations: adding (nsequence).
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed May 19, 2019
1 parent 53d404a commit 86046dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Expand Up @@ -11,6 +11,7 @@ IN: sequences.generalizations.tests
{ "a" } [ { "a" } 1 firstn ] unit-test

{ [ 1 2 ] } [ 1 2 2 [ ] nsequence ] unit-test
{ { 1 2 3 4 5 } } [ 1 2 3 4 5 { 0 0 0 0 0 } 5 (nsequence) ] unit-test

{ { 1 2 3 4 } } [ { 1 } { 2 } { 3 } { 4 } 4 nappend ] unit-test
{ V{ 1 2 3 4 } } [ { 1 } { 2 } { 3 } { 4 } 4 V{ } nappend-as ] unit-test
Expand Down
10 changes: 6 additions & 4 deletions basis/sequences/generalizations/generalizations.factor
@@ -1,11 +1,13 @@
! Copyright (C) 2009 Joe Groff.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences sequences.private math
combinators macros math.order math.ranges quotations fry effects
memoize.private generalizations ;
USING: combinators fry generalizations kernel macros math
math.order memoize.private sequences sequences.private ;
IN: sequences.generalizations

MACRO: nsequence ( n seq -- quot )
MACRO: (nsequence) ( n -- quot )
<iota> reverse [ '[ [ _ swap set-nth-unsafe ] keep ] ] map concat ;

MACRO: nsequence ( n exemplar -- quot )
[ [nsequence] ] keep '[ @ _ like ] ;

MACRO: narray ( n -- quot )
Expand Down

0 comments on commit 86046dc

Please sign in to comment.