]> gitweb.factorcode.org Git - factor.git/commitdiff
fry: adding the ability to fry words to be executed
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 11 Jan 2022 19:13:54 +0000 (11:13 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 11 Jan 2022 19:13:54 +0000 (11:13 -0800)
IN: scratchpad \ + '[ 1 2 @ ] .
'[ 1 2 + ]

core/fry/fry-tests.factor
core/fry/fry.factor

index 6218e9d9ad8bd212f36b8b70192f82f13e37098e..36ca310c1ba6a55d6e60f040bda4bf2d3cb35a86 100644 (file)
@@ -11,6 +11,7 @@ SYMBOLS: a b c d e f g h ;
 { [ 1 ] } [ 1 '[ _ ] ] unit-test
 { [ 1 ] } [ [ 1 ] '[ @ ] ] unit-test
 { [ 1 2 ] } [ [ 1 ] [ 2 ] '[ @ @ ] ] unit-test
+{ [ 1 2 + ] } [ \ + '[ 1 2 @ ] ] unit-test
 
 { [ 1 2 a ] } [ 1 2 '[ _ _ a ] ] unit-test
 { [ 1 2 ] } [ 1 2 '[ _ _ ] ] unit-test
index 5c39197d5a22571a0f4fe508b4678c11401f52fe..06b4ede19f5e55879afe47d98e8b01e2b8a20ef4 100644 (file)
@@ -58,10 +58,13 @@ INSTANCE: fried-sequence fried
 : (make-curry) ( tail quot -- quot' )
     swap [ncurry] curry [ compose ] compose ;
 
+: ?compose ( obj1 obj2 -- compose )
+    [ dup word? [ 1quotation ] when ] bi@ compose ;
+
 : make-compose ( consecutive quot -- consecutive' quot' )
     [ [ [ ] ] [ [ncurry] ] if-zero ]
-    [ [ [ compose ] ] [ [ compose compose ] curry ] if-empty ]
-    bi* compose 0 swap ;
+    [ [ [ ?compose ] ] [ [ ?compose ?compose ] curry ] if-empty ]
+    bi* ?compose 0 swap ;
 
 : make-curry ( consecutive quot -- consecutive' quot' )
     [ 1 + ] dip [ [ ] ] [ (make-curry) 0 swap ] if-empty ;