HELP: @\r
{ $description "Fry specifier. Splices a quotation into the fried quotation." } ;\r
\r
-HELP: _\r
-{ $description "Fry specifier. Shifts all fry specifiers to the left down by one stack position." } ;\r
-\r
HELP: fry\r
{ $values { "quot" quotation } { "quot'" quotation } }\r
{ $description "Outputs a quotation that when called, fries " { $snippet "quot" } " by taking values from the stack and substituting them in." }\r
"{ 8 13 14 27 } [ even? ] 5 [ dup ] swap [ ? ] curry 3compose map"\r
"{ 8 13 14 27 } [ even? dup 5 ? ] map"\r
}\r
-"Occurrences of " { $link _ } " have the effect of enclosing all code to their left in a quotation passed to " { $link dip } ". The following four lines are equivalent:"\r
-{ $code \r
- "{ 10 20 30 } 1 '[ , _ / ] map"\r
- "{ 10 20 30 } 1 [ [ ] curry dip / ] curry map"\r
- "{ 10 20 30 } 1 [ swap / ] curry map"\r
- "{ 10 20 30 } [ 1 swap / ] map"\r
-}\r
-"For any quotation body " { $snippet "X" } ", the following two are equivalent:"\r
-{ $code\r
- "[ [ X ] dip ]"\r
- "'[ X _ ]"\r
-}\r
"Here are some built-in combinators rewritten in terms of fried quotations:"\r
{ $table\r
{ { $link literalize } { $snippet ": literalize '[ , ] ;" } }\r
{ { $link slip } { $snippet ": slip '[ @ , ] call ;" } }\r
- { { $link dip } { $snippet ": dip '[ @ _ ] call ;" } }\r
{ { $link curry } { $snippet ": curry '[ , @ ] ;" } }\r
- { { $link with } { $snippet ": with swapd '[ , _ @ ] ;" } }\r
{ { $link compose } { $snippet ": compose '[ @ @ ] ;" } }\r
{ { $link bi@ } { $snippet ": bi@ tuck '[ , @ , @ ] call ;" } }\r
} ;\r
{ $code\r
"'[ 3 , + 4 , / ]"\r
"[let | a [ ] b [ ] | [ 3 a + 4 b / ] ]"\r
-}\r
-"The " { $link _ } " fry specifier has no direct analogue in " { $vocab-link "locals" } ", however closure conversion together with the " { $link dip } " combinator achieve the same effect:"\r
-{ $code\r
- "'[ , 2 + , * _ / ]"\r
- "[let | a [ ] b [ ] | [ [ a 2 + b * ] dip / ] ]"\r
} ;\r
\r
ARTICLE: "fry.limitations" "Fried quotation limitations"\r
"Fried quotations contain zero or more " { $emphasis "fry specifiers" } ":"\r
{ $subsection , }\r
{ $subsection @ }\r
-{ $subsection _ }\r
"When a fried quotation is being evaluated, values are consumed from the stack and spliced into the quotation from right to left."\r
{ $subsection "fry.examples" }\r
{ $subsection "fry.philosophy" }\r