]> gitweb.factorcode.org Git - factor.git/commitdiff
lazy-lists: add LAZY: word
authorchris.double <chris.double@double.co.nz>
Sat, 7 Oct 2006 06:30:28 +0000 (06:30 +0000)
committerchris.double <chris.double@double.co.nz>
Sat, 7 Oct 2006 06:30:28 +0000 (06:30 +0000)
contrib/lazy-lists/lazy.factor [new file with mode: 0644]
contrib/lazy-lists/lazy.facts [new file with mode: 0644]
contrib/lazy-lists/load.factor

diff --git a/contrib/lazy-lists/lazy.factor b/contrib/lazy-lists/lazy.factor
new file mode 100644 (file)
index 0000000..8b6813e
--- /dev/null
@@ -0,0 +1,20 @@
+! Copyright (C) 2004 Chris Double.
+! See http://factorcode.org/license.txt for BSD license.
+!
+USING: kernel sequences words inference namespaces math parser ;
+IN: lazy-lists
+
+: stack-effect-in ( quot word -- n )
+  stack-effect dup [ 
+    nip effect-in length 
+  ] [ 
+    drop infer first 
+  ] if ;
+
+: make-lazy-quot ( word quot -- quot )
+  [
+    dup , swap stack-effect-in [ \ curry , ] times \ <promise> , 
+  ] [ ] make ;
+
+: LAZY: ( -- object object object )
+  CREATE dup reset-generic [ dupd make-lazy-quot define-compound ] f ; parsing
diff --git a/contrib/lazy-lists/lazy.facts b/contrib/lazy-lists/lazy.facts
new file mode 100644 (file)
index 0000000..5f30950
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2006 Chris Double.
+! See http://factorcode.org/license.txt for BSD license.
+
+USING: help lazy-lists ;
+
+HELP: LAZY:
+{ $syntax "LAZY: word definition... ;" } 
+{ $values { "word" "a new word to define" } { "definition" "a word definition" } }
+{ $description "Creates a lazy word in the current vocabulary. When executed the word will return a " { $link <promise> } " that when forced, executes the word definition. Any values on the stack that are required by the word definition are captured along with the promise." } 
+{ $examples
+  { $example "LAZY: my-add ( a b -- c ) + ;\n1 2 my-add force ." }
+}
+{ $see-also force promise-with promise-with2 } ;
index 084e73c2fd49aacca8ecf3a966d794927eb5c1b7..382242b0d8039bd36b0d4c0cca90ca3b1fe1b033 100644 (file)
@@ -4,6 +4,8 @@
 PROVIDE: contrib/lazy-lists { 
     "lists.factor"
     "lists.facts"
+    "lazy.factor"
+    "lazy.facts"
     "lazy-io.factor"
     "lazy-io.facts"
     "examples.factor"