]> gitweb.factorcode.org Git - factor.git/commitdiff
Refactor fry a bit, to add extension points for locals
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 28 Nov 2008 03:55:20 +0000 (21:55 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 28 Nov 2008 03:55:20 +0000 (21:55 -0600)
basis/fry/fry-docs.factor
basis/fry/fry.factor

index b5d1b8d8d21708fcdfd8c91d6d15d6c82e44b1a2..a982ecdd7d4a03613761b154c4ce91b45d6cb854 100644 (file)
@@ -75,12 +75,6 @@ ARTICLE: "fry.philosophy" "Fried quotation philosophy"
     "[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
@@ -92,7 +86,6 @@ $nl
 "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
index ac036f58ad261ad45cc5b5979d3f3c3d994e73d1..f84ad233cd8b5c1b9420e3efb0eb950b3d209fe8 100644 (file)
@@ -28,11 +28,6 @@ M: >r/r>-in-fry-error summary
     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 )
@@ -41,15 +36,21 @@ M: callable count-inputs [ count-inputs ] sigma ;
 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