combinators.smart: "keep-inputs" combinator
parent
16c90d29e5
commit
1b89e1a26f
|
@ -106,11 +106,21 @@ HELP: append-outputs-as
|
|||
|
||||
{ append-outputs append-outputs-as } related-words
|
||||
|
||||
HELP: drop-outputs
|
||||
{ $values { "quot" quotation } }
|
||||
{ $description "Calls a quotation and drops any values it leaves on the stack." } ;
|
||||
|
||||
HELP: keep-inputs
|
||||
{ $values { "quot" quotation } }
|
||||
{ $description "Calls a quotation and preserves any values it takes off the stack." } ;
|
||||
|
||||
{ drop-outputs keep-inputs } related-words
|
||||
|
||||
ARTICLE: "combinators.smart" "Smart combinators"
|
||||
"A " { $emphasis "smart combinator" } " is a macro which reflects on the stack effect of an input quotation. The " { $vocab-link "combinators.smart" } " vocabulary implements a few simple smart combinators which look at the static stack effects of input quotations and generate code which produces or consumes the relevant number of stack values." $nl
|
||||
"Call a quotation and discard all output values:"
|
||||
"Call a quotation and discard all output values or preserve all input values:"
|
||||
{ $subsection drop-outputs }
|
||||
{ $subsection keep-inputs }
|
||||
"Take all input values from a sequence:"
|
||||
{ $subsection input<sequence }
|
||||
"Store all output values to a sequence:"
|
||||
|
|
|
@ -7,6 +7,9 @@ IN: combinators.smart
|
|||
MACRO: drop-outputs ( quot -- quot' )
|
||||
dup infer out>> '[ @ _ ndrop ] ;
|
||||
|
||||
MACRO: keep-inputs ( quot -- quot' )
|
||||
dup infer in>> '[ _ _ nkeep ] ;
|
||||
|
||||
MACRO: output>sequence ( quot exemplar -- newquot )
|
||||
[ dup infer out>> ] dip
|
||||
'[ @ _ _ nsequence ] ;
|
||||
|
|
Loading…
Reference in New Issue