Add ncleave combinator to generalizations
parent
1e1640abb3
commit
474b718337
|
@ -1,5 +1,5 @@
|
||||||
USING: help.syntax help.markup kernel sequences quotations
|
USING: help.syntax help.markup kernel sequences quotations
|
||||||
math arrays ;
|
math arrays combinators ;
|
||||||
IN: generalizations
|
IN: generalizations
|
||||||
|
|
||||||
HELP: nsequence
|
HELP: nsequence
|
||||||
|
@ -234,6 +234,18 @@ HELP: napply
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
HELP: ncleave
|
||||||
|
{ $values { "quots" "a sequence of quotations" } { "n" integer } }
|
||||||
|
{ $description "A generalization of " { $link cleave } " and " { $link 2cleave } " that can work for any quotation arity."
|
||||||
|
}
|
||||||
|
{ $examples
|
||||||
|
"Some core words expressed in terms of " { $link ncleave } ":"
|
||||||
|
{ $table
|
||||||
|
{ { $link cleave } { $snippet "1 ncleave" } }
|
||||||
|
{ { $link 2cleave } { $snippet "2 ncleave" } }
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
HELP: mnswap
|
HELP: mnswap
|
||||||
{ $values { "m" integer } { "n" integer } }
|
{ $values { "m" integer } { "n" integer } }
|
||||||
{ $description "Swaps the top " { $snippet "m" } " stack elements with the " { $snippet "n" } " elements directly underneath." }
|
{ $description "Swaps the top " { $snippet "m" } " stack elements with the " { $snippet "n" } " elements directly underneath." }
|
||||||
|
@ -269,6 +281,7 @@ $nl
|
||||||
{ $subsection nslip }
|
{ $subsection nslip }
|
||||||
{ $subsection nkeep }
|
{ $subsection nkeep }
|
||||||
{ $subsection napply }
|
{ $subsection napply }
|
||||||
|
{ $subsection ncleave }
|
||||||
"Generalized quotation construction:"
|
"Generalized quotation construction:"
|
||||||
{ $subsection ncurry }
|
{ $subsection ncurry }
|
||||||
{ $subsection nwith } ;
|
{ $subsection nwith } ;
|
||||||
|
|
|
@ -69,6 +69,10 @@ MACRO: ncurry ( n -- )
|
||||||
MACRO: nwith ( n -- )
|
MACRO: nwith ( n -- )
|
||||||
[ with ] n*quot ;
|
[ with ] n*quot ;
|
||||||
|
|
||||||
|
MACRO: ncleave ( quots n -- )
|
||||||
|
[ '[ _ '[ _ _ nkeep ] ] map [ ] join ] [ '[ _ ndrop ] ] bi
|
||||||
|
compose ;
|
||||||
|
|
||||||
MACRO: napply ( n -- )
|
MACRO: napply ( n -- )
|
||||||
2 [a,b]
|
2 [a,b]
|
||||||
[ [ 1- ] [ ] bi '[ _ ntuck _ nslip ] ]
|
[ [ 1- ] [ ] bi '[ _ ntuck _ nslip ] ]
|
||||||
|
|
Loading…
Reference in New Issue