]> gitweb.factorcode.org Git - factor.git/commitdiff
update terms of fry–locals peace treaty
authorJoe Groff <arcata@gmail.com>
Sat, 7 Nov 2009 19:03:46 +0000 (13:03 -0600)
committerJoe Groff <arcata@gmail.com>
Sat, 7 Nov 2009 19:03:46 +0000 (13:03 -0600)
basis/fry/fry.factor
basis/locals/fry/fry.factor

index 991ab764208360aab911e82d2a3508e76cccfc68..42518528dc942038f0e04ced60b4b53a660183e9 100644 (file)
@@ -8,7 +8,7 @@ IN: fry
 
 ERROR: >r/r>-in-fry-error ;
 
-DEFER: fry
+GENERIC: fry ( quot -- quot' )
 
 <PRIVATE
 
@@ -24,8 +24,10 @@ M: callable count-inputs [ count-inputs ] map-sum ;
 M: fry-specifier count-inputs drop 1 ;
 M: object count-inputs drop 0 ;
 
+MIXIN: fried
 PREDICATE: fried-callable < callable
     count-inputs 0 > ;
+INSTANCE: fried-callable fried
 
 : convert-curry ( quot -- quot' )
     [ [ [ ] curry compose ] ] [
@@ -43,6 +45,15 @@ PREDICATE: fried-callable < callable
     { _ } split convert-curries
     spread>quot ;
 
+: [ncurry] ( quot n -- quot )
+    {
+        { 0 [ [ ] ] }
+        { 1 [ [ curry ] ] }
+        { 2 [ [ 2curry ] ] }
+        { 3 [ [ 3curry ] ] }
+        [ \ curry <repetition> ]
+    } case curry ;
+
 : [ndip] ( quot n -- quot' )
     {
         { 0 [ \ call [ ] 2sequence ] }
@@ -85,13 +96,13 @@ TUPLE: dredge-fry-state
     [ in-quot>> swap tail-slice ] [ quot>> ] bi push-all ; inline recursive
 
 : dredge-fry ( n dredge-fry -- )
-    2dup in-quot>> [ fried-callable? ] find-from
+    2dup in-quot>> [ fried? ] find-from
     [ (dredge-fry-subquot) ]
     [ drop (dredge-fry-simple) ] if* ; inline recursive
 
 PRIVATE>
 
-: fry ( quot -- quot' )
+M: callable fry ( quot -- quot' )
     0 swap <dredge-fry>
     [ dredge-fry ] [
         [ prequot>> >quotation ]
index ff6a491a79d7e2d13e8df2687633fa71ac1dba71..30336c45e952870a0b24114c3011691e0bc5ba36 100644 (file)
@@ -1,18 +1,21 @@
 ! Copyright (C) 2007, 2008 Slava Pestov, Eduardo Cavazos.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors fry fry.private generalizations kernel
-locals.types make sequences ;
+locals.types sequences ;
 IN: locals.fry
 
 ! Support for mixing locals with fry
 
 M: let count-inputs body>> count-inputs ;
-
 M: lambda count-inputs body>> count-inputs ;
 
-M: lambda deep-fry
-    clone [ shallow-fry swap ] change-body
-    [ [ vars>> length ] keep '[ _ _ mnswap @ ] , ] [ drop [ncurry] % ] 2bi ;
+M: lambda fry
+    clone [ [ count-inputs ] [ fry ] bi ] change-body
+    [ [ vars>> length ] keep '[ _ _ mnswap _ call ] ]
+    [ drop [ncurry] [ call ] compose ] 2bi ;
+
+M: let fry
+    clone [ fry ] change-body ;
 
-M: let deep-fry
-    clone [ fry '[ @ call ] ] change-body , ;
+INSTANCE: lambda fried
+INSTANCE: let    fried