Add nsequence
parent
38b65e00f4
commit
33eee7638b
basis/generalizations
|
@ -2,6 +2,16 @@ USING: help.syntax help.markup kernel sequences quotations
|
|||
math arrays ;
|
||||
IN: generalizations
|
||||
|
||||
HELP: nsequence
|
||||
{ $values { "n" integer } { "seq" "an exemplar" } }
|
||||
{ $description "A generalization of " { $link 2sequence } ", "
|
||||
{ $link 3sequence } ", and " { $link 4sequence } " "
|
||||
"that constructs a sequence from the top " { $snippet "n" } " elements of the stack."
|
||||
}
|
||||
{ $examples
|
||||
{ $example "CHAR: f CHAR: i CHAR: s CHAR: h 4 \"\" nsequence ." "\"fish\"" }
|
||||
} ;
|
||||
|
||||
HELP: narray
|
||||
{ $values { "n" integer } }
|
||||
{ $description "A generalization of " { $link 1array } ", "
|
||||
|
@ -9,6 +19,8 @@ HELP: narray
|
|||
"that constructs an array from the top " { $snippet "n" } " elements of the stack."
|
||||
} ;
|
||||
|
||||
{ nsequence narray } related-words
|
||||
|
||||
HELP: firstn
|
||||
{ $values { "n" integer } }
|
||||
{ $description "A generalization of " { $link first } ", "
|
||||
|
@ -127,11 +139,15 @@ HELP: nkeep
|
|||
{ $see-also keep nslip } ;
|
||||
|
||||
ARTICLE: "generalizations" "Generalized shuffle words and combinators"
|
||||
"A number of stack shuffling words and combinators for use in "
|
||||
"The " { $vocab-link "generalizations" } " vocabulary defines a number of stack shuffling words and combinators for use in "
|
||||
"macros where the arity of the input quotations depends on an "
|
||||
"input parameter."
|
||||
$nl
|
||||
"Generalized sequence operations:"
|
||||
{ $subsection narray }
|
||||
{ $subsection nsequence }
|
||||
{ $subsection firstn }
|
||||
"Generated stack shuffle operations:"
|
||||
{ $subsection ndup }
|
||||
{ $subsection npick }
|
||||
{ $subsection nrot }
|
||||
|
@ -139,6 +155,7 @@ ARTICLE: "generalizations" "Generalized shuffle words and combinators"
|
|||
{ $subsection nnip }
|
||||
{ $subsection ndrop }
|
||||
{ $subsection nrev }
|
||||
"Generalized combinators:"
|
||||
{ $subsection ndip }
|
||||
{ $subsection nslip }
|
||||
{ $subsection nkeep }
|
||||
|
|
|
@ -5,10 +5,13 @@ USING: kernel sequences sequences.private namespaces math
|
|||
math.ranges combinators macros quotations fry arrays ;
|
||||
IN: generalizations
|
||||
|
||||
MACRO: narray ( n -- quot )
|
||||
[ <reversed> ] [ '[ , f <array> ] ] bi
|
||||
MACRO: nsequence ( n seq -- quot )
|
||||
[ drop <reversed> ] [ '[ , , new-sequence ] ] 2bi
|
||||
[ '[ @ [ , swap set-nth-unsafe ] keep ] ] reduce ;
|
||||
|
||||
MACRO: narray ( n -- quot )
|
||||
'[ , { } nsequence ] ;
|
||||
|
||||
MACRO: firstn ( n -- )
|
||||
dup zero? [ drop [ drop ] ] [
|
||||
[ [ '[ , _ nth-unsafe ] ] map ]
|
||||
|
|
Loading…
Reference in New Issue