"[let | a [ ] b [ ] | [ 3 a + 4 b / ] ]"\r
} ;\r
\r
-ARTICLE: "fry.limitations" "Fried quotation limitations"\r
-"As with " { $vocab-link "locals" } ", fried quotations cannot contain " { $link >r } " and " { $link r> } ". This is not a real limitation in practice, since " { $link dip } " can be used instead."\r
-$nl\r
-"An error thrown if a fried quotation contains calls to " { $link >r } " and " { $link r> } ":"\r
-{ $subsection >r/r>-in-fry-error } ;\r
-\r
ARTICLE: "fry" "Fried quotations"\r
"The " { $vocab-link "fry" } " vocabulary implements " { $emphasis "fried quotation" } ". Conceptually, fried quotations are quotations with ``holes'' (more formally, " { $emphasis "fry specifiers" } "), and the holes are filled in when the fried quotation is pushed on the stack."\r
$nl\r
"The holes are filled in with the top of stack going in the rightmost hole, the second item on the stack going in the second hole from the right, and so on."\r
{ $subsection "fry.examples" }\r
{ $subsection "fry.philosophy" }\r
-{ $subsection "fry.limitations" }\r
"Fry is implemented as a parsing word which reads a quotation and scans for occurrences of " { $link _ } " and " { $link @ } "; these words are not actually executed, and doing so raises an error (this can happen if they're accidentally used outside of a fry)."\r
$nl\r
"Fried quotations can also be constructed without using a parsing word; this is useful when meta-programming:"\r
dup { >r r> load-locals get-local drop-locals } intersect
empty? [ >r/r>-in-fry-error ] unless ;
-: shallow-fry ( quot -- quot' )
- check-fry
- [ dup \ @ = [ drop [ _ call ] ] [ 1array ] if ] map concat
- { _ } split [ length 1- [ncurry] ] [ spread>quot ] bi prefix ;
-
PREDICATE: fry-specifier < word { _ @ } memq? ;
GENERIC: count-inputs ( quot -- n )
M: fry-specifier count-inputs drop 1 ;
M: object count-inputs drop 0 ;
+GENERIC: deep-fry ( obj -- )
+
+: shallow-fry ( quot -- quot' curry# )
+ check-fry
+ [ [ deep-fry ] each ] [ ] make
+ [ dup \ @ = [ drop [ _ call ] ] [ 1array ] if ] map concat
+ { _ } split [ spread>quot ] [ length 1- ] bi ;
+
PRIVATE>
-: fry ( quot -- quot' )
- [
- [
- dup callable? [
- [ count-inputs \ _ <repetition> % ] [ fry % ] bi
- ] [ , ] if
- ] each
- ] [ ] make shallow-fry ;
+: fry ( quot -- quot' ) shallow-fry [ncurry] swap prefix ;
+
+M: callable deep-fry
+ [ count-inputs \ _ <repetition> % ] [ fry % ] bi ;
+
+M: object deep-fry , ;
: '[ \ ] parse-until fry over push-all ; parsing