]> gitweb.factorcode.org Git - factor.git/commitdiff
Get all of contrib/ and examples/ to load
authorslava <slava@factorcode.org>
Mon, 13 Nov 2006 05:16:22 +0000 (05:16 +0000)
committerslava <slava@factorcode.org>
Mon, 13 Nov 2006 05:16:22 +0000 (05:16 +0000)
29 files changed:
TODO.FACTOR.txt
contrib/coroutines.factor [deleted file]
contrib/coroutines/coroutines.factor [new file with mode: 0644]
contrib/coroutines/load.factor [new file with mode: 0644]
contrib/coroutines/tests.factor [new file with mode: 0644]
contrib/lazy-lists/lazy.factor
contrib/splay-trees.factor [deleted file]
contrib/splay-trees/load.factor [new file with mode: 0644]
contrib/splay-trees/splay-trees.factor [new file with mode: 0644]
contrib/splay-trees/tests.factor [new file with mode: 0644]
examples/factorbot.factor
examples/lcd.factor
examples/levenshtein.factor [deleted file]
examples/levenshtein/levenshtein.factor [new file with mode: 0644]
examples/levenshtein/load.factor [new file with mode: 0644]
examples/levenshtein/tests.factor [new file with mode: 0644]
examples/mandel.factor [deleted file]
examples/mandel/load.factor [new file with mode: 0644]
examples/mandel/mandel.factor [new file with mode: 0644]
examples/mandel/tests.factor [new file with mode: 0644]
examples/print-dataflow.factor [deleted file]
examples/print-dataflow/load.factor [new file with mode: 0644]
examples/print-dataflow/print-dataflow.factor [new file with mode: 0644]
examples/print-dataflow/tests.factor [new file with mode: 0644]
examples/raytracer.factor
examples/turing.factor
library/compiler/inference/inference.factor
library/tools/completion.factor
library/words.factor

index 33ac362c76aec819eb15a00b03d13ae93f3265fe..3850f31aa4797952b3c1cb5b25f9e710a4c2570b 100644 (file)
@@ -1,3 +1,5 @@
+- workspace window takes too long to come up
+
 + 0.87:
 
 - live search: timer delay would be nice
@@ -45,6 +47,7 @@
 
 + compiler/ffi:
 
+- recompile get/set/>n/n>/ndrop if needed
 - %allot-bignum-signed-2 is broken on both platforms
 - cross-word type inference
 - callback scheduling issue
diff --git a/contrib/coroutines.factor b/contrib/coroutines.factor
deleted file mode 100644 (file)
index 10aa89f..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-! Copyright (C) 2005 Chris Double.
-! 
-! Redistribution and use in source and binary forms, with or without
-! modification, are permitted provided that the following conditions are met:
-! 
-! 1. Redistributions of source code must retain the above copyright notice,
-!    this list of conditions and the following disclaimer.
-! 
-! 2. Redistributions in binary form must reproduce the above copyright notice,
-!    this list of conditions and the following disclaimer in the documentation
-!    and/or other materials provided with the distribution.
-! 
-! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-!
-IN: coroutines
-USING: kernel generic ;
-
-TUPLE: coroutine resumecc exitcc ;
-
-: cocreate ( quot -- co )
-  #! Create a new coroutine, which will execute the quotation
-  #! when resumed. The quotation will have the coroutine
-  #! on the stack and an initial value (received from coresume)
-  #! when first resumed. ie. The quotation should have stack
-  #! effect ( co value -- ).
-  f f <coroutine> dup rot curry over set-coroutine-resumecc ;
-
-: coresume ( v co -- result )
-  #! Resume a coroutine with 'v' as the first item on the
-  #! stack. The result placed on the stack is that of the 
-  #! topmost argument on the stack when coyield is called
-  #! within the coroutine.
-  [ 
-    over set-coroutine-exitcc
-    coroutine-resumecc call
-  ] callcc1 rot drop ;
-
-: coyield ( v co -- result )
-  #! Suspend a coroutine, leaving the value 'v' on the 
-  #! stack when control is passed to the 'coresume' caller.
-  [  
-    [ continue-with ] curry
-    over set-coroutine-resumecc  
-    coroutine-exitcc continue-with
-  ] callcc1 rot drop ;
-
-USE: prettyprint
-USE: sequences
-
-: test1 ( list -- co )
-  [ swap [ over coyield 2drop ] each f swap coyield ] cocreate ; 
-  
-: test2 ( -- co )
-  [ 1 over coyield drop 2 over coyield drop 3 over coyield ] cocreate ;
-
-test2 f swap coresume . f swap coresume . f swap coresume . drop
-
-: test3 ( -- co )
-  [ [ 1 2 3 ] [ over coyield drop ] each ] cocreate ;
-
-test3 f swap coresume . f swap coresume . f swap coresume . drop
-
-PROVIDE: contrib/coroutines ;
-
diff --git a/contrib/coroutines/coroutines.factor b/contrib/coroutines/coroutines.factor
new file mode 100644 (file)
index 0000000..de2fbaa
--- /dev/null
@@ -0,0 +1,54 @@
+! Copyright (C) 2005 Chris Double.
+! 
+! Redistribution and use in source and binary forms, with or without
+! modification, are permitted provided that the following conditions are met:
+! 
+! 1. Redistributions of source code must retain the above copyright notice,
+!    this list of conditions and the following disclaimer.
+! 
+! 2. Redistributions in binary form must reproduce the above copyright notice,
+!    this list of conditions and the following disclaimer in the documentation
+!    and/or other materials provided with the distribution.
+! 
+! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+!
+IN: coroutines
+USING: kernel generic ;
+
+TUPLE: coroutine resumecc exitcc ;
+
+: cocreate ( quot -- co )
+  #! Create a new coroutine, which will execute the quotation
+  #! when resumed. The quotation will have the coroutine
+  #! on the stack and an initial value (received from coresume)
+  #! when first resumed. ie. The quotation should have stack
+  #! effect ( co value -- ).
+  f f <coroutine> dup rot curry over set-coroutine-resumecc ;
+
+: coresume ( v co -- result )
+  #! Resume a coroutine with 'v' as the first item on the
+  #! stack. The result placed on the stack is that of the 
+  #! topmost argument on the stack when coyield is called
+  #! within the coroutine.
+  [ 
+    over set-coroutine-exitcc
+    coroutine-resumecc call
+  ] callcc1 rot drop ;
+
+: coyield ( v co -- result )
+  #! Suspend a coroutine, leaving the value 'v' on the 
+  #! stack when control is passed to the 'coresume' caller.
+  [  
+    [ continue-with ] curry
+    over set-coroutine-resumecc  
+    coroutine-exitcc continue-with
+  ] callcc1 rot drop ;
diff --git a/contrib/coroutines/load.factor b/contrib/coroutines/load.factor
new file mode 100644 (file)
index 0000000..7bd1aea
--- /dev/null
@@ -0,0 +1,3 @@
+PROVIDE: contrib/coroutines
+{ +files+ { "coroutines.factor" } }
+{ +tests+ { "tests.factor" } } ;
diff --git a/contrib/coroutines/tests.factor b/contrib/coroutines/tests.factor
new file mode 100644 (file)
index 0000000..1608a1e
--- /dev/null
@@ -0,0 +1,15 @@
+IN: temporary
+USING: coroutines kernel sequences prettyprint ;
+
+: test1 ( list -- co )
+  [ swap [ over coyield 2drop ] each f swap coyield ] cocreate ; 
+  
+: test2 ( -- co )
+  [ 1 over coyield drop 2 over coyield drop 3 over coyield ] cocreate ;
+
+test2 f swap coresume . f swap coresume . f swap coresume . drop
+
+: test3 ( -- co )
+  [ [ 1 2 3 ] [ over coyield drop ] each ] cocreate ;
+
+test3 f swap coresume . f swap coresume . f swap coresume . drop
index 8b6813eb939b0e8fc89d5709bca3762d6f8567f5..7b96bfa37b788168c608cb3d40dee2c42b437e79 100644 (file)
@@ -8,7 +8,7 @@ IN: lazy-lists
   stack-effect dup [ 
     nip effect-in length 
   ] [ 
-    drop infer first 
+    drop infer effect-in length nip
   ] if ;
 
 : make-lazy-quot ( word quot -- quot )
diff --git a/contrib/splay-trees.factor b/contrib/splay-trees.factor
deleted file mode 100644 (file)
index baa97fe..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-! Copyright (c) 2005 Mackenzie Straight.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: splay-trees
-USING: kernel math sequences ;
-
-TUPLE: splay-tree r ;
-TUPLE: splay-node v k l r ;
-
-C: splay-tree ;
-
-: rotate-right
-    dup splay-node-l
-    [ splay-node-r swap set-splay-node-l ] 2keep
-    [ set-splay-node-r ] keep ;
-
-: rotate-left
-    dup splay-node-r
-    [ splay-node-l swap set-splay-node-r ] 2keep
-    [ set-splay-node-l ] keep ;
-
-: link-right ( left right key node -- left right key node )
-    swap >r [ swap set-splay-node-l ] 2keep
-    nip dup splay-node-l r> swap ;
-
-: link-left ( left right key node -- left right key node )
-    swap >r rot [ set-splay-node-r ] 2keep
-    drop dup splay-node-r swapd r> swap ;
-
-: cmp 2dup splay-node-k <=> ;
-
-: lcmp 2dup splay-node-l splay-node-k <=> ;
-
-: rcmp 2dup splay-node-r splay-node-k <=> ;
-
-DEFER: (splay)
-
-: splay-left
-    dup splay-node-l [
-        lcmp 0 < [ rotate-right ] when
-        dup splay-node-l [ link-right (splay) ] when
-    ] when ;
-
-: splay-right
-    dup splay-node-r [
-        rcmp 0 > [ rotate-left ] when
-        dup splay-node-r [ link-left (splay) ] when
-    ] when ;
-
-: (splay) ( left right key node -- left right key node )
-    cmp dup 0 <
-    [ drop splay-left ] [ 0 > [ splay-right ] when ] if ;
-
-: assemble ( head left right node -- root )
-    [ splay-node-r swap set-splay-node-l ] keep
-    [ splay-node-l swap set-splay-node-r ] keep
-    [ swap splay-node-l swap set-splay-node-r ] 2keep
-    [ swap splay-node-r swap set-splay-node-l ] keep ;
-
-: splay-at ( key node -- node )
-    >r >r T{ splay-node } dup dup r> r> (splay) nip assemble ;
-
-: splay ( key tree -- )
-    [ splay-tree-r splay-at ] keep set-splay-tree-r ;
-
-: splay-split ( key tree -- node node )
-    2dup splay splay-tree-r cmp 0 < [
-        nip dup splay-node-l swap f over set-splay-node-l
-    ] [
-        nip dup splay-node-r swap f over set-splay-node-r swap
-    ] if ;
-
-: (get-splay) ( key tree -- node )
-    2dup splay splay-tree-r cmp 0 = [ nip ] [ 2drop f ] if ;
-
-: get-largest ( node -- node )
-    dup [ dup splay-node-r [ nip get-largest ] when* ] when ;
-
-: splay-largest
-    dup [ dup get-largest splay-node-k swap splay-at ] when ;
-
-: splay-join ( n2 n1 -- node )
-    splay-largest [ [ set-splay-node-r ] keep ] [ drop f ] if* ;
-
-: (remove-splay) ( key tree -- )
-    tuck (get-splay) [
-        dup splay-node-r swap splay-node-l splay-join
-        swap set-splay-tree-r
-    ] [ drop ] if* ;
-
-: (set-splay) ( value key tree -- )
-    2dup (get-splay) [ 2nip set-splay-node-v ] [
-       2dup splay-split rot >r <splay-node> r> set-splay-tree-r
-    ] if* ;
-
-: new-root ( value key tree -- )
-    >r f f <splay-node> r> set-splay-tree-r ;
-
-: set-splay ( value key tree -- )
-    dup splay-tree-r [ (set-splay) ] [ new-root ] if ;
-
-: get-splay ( key tree -- value )
-    dup splay-tree-r [
-        (get-splay) dup [ splay-node-v ] when
-    ] [
-        2drop f
-    ] if ;
-
-: remove-splay ( key tree -- )
-    dup splay-tree-r [ (remove-splay) ] [ 2drop ] if ;
-
-USING: namespaces words ;
-
-<splay-tree> "foo" set
-all-words [ dup word-name "foo" get set-splay ] each
-all-words [ word-name "foo" get get-splay drop ] each
-
-PROVIDE: contrib/splay-trees ;
diff --git a/contrib/splay-trees/load.factor b/contrib/splay-trees/load.factor
new file mode 100644 (file)
index 0000000..8ad41bb
--- /dev/null
@@ -0,0 +1,3 @@
+PROVIDE: contrib/splay-trees
+{ +files+ { "splay-trees.factor" } }
+{ +tests+ { "tests.factor" } } ;
diff --git a/contrib/splay-trees/splay-trees.factor b/contrib/splay-trees/splay-trees.factor
new file mode 100644 (file)
index 0000000..d9cd0a3
--- /dev/null
@@ -0,0 +1,109 @@
+! Copyright (c) 2005 Mackenzie Straight.
+! See http://factor.sf.net/license.txt for BSD license.
+IN: splay-trees
+USING: kernel math sequences ;
+
+TUPLE: splay-tree r ;
+TUPLE: splay-node v k l r ;
+
+C: splay-tree ;
+
+: rotate-right
+    dup splay-node-l
+    [ splay-node-r swap set-splay-node-l ] 2keep
+    [ set-splay-node-r ] keep ;
+
+: rotate-left
+    dup splay-node-r
+    [ splay-node-l swap set-splay-node-r ] 2keep
+    [ set-splay-node-l ] keep ;
+
+: link-right ( left right key node -- left right key node )
+    swap >r [ swap set-splay-node-l ] 2keep
+    nip dup splay-node-l r> swap ;
+
+: link-left ( left right key node -- left right key node )
+    swap >r rot [ set-splay-node-r ] 2keep
+    drop dup splay-node-r swapd r> swap ;
+
+: cmp 2dup splay-node-k <=> ;
+
+: lcmp 2dup splay-node-l splay-node-k <=> ;
+
+: rcmp 2dup splay-node-r splay-node-k <=> ;
+
+DEFER: (splay)
+
+: splay-left
+    dup splay-node-l [
+        lcmp 0 < [ rotate-right ] when
+        dup splay-node-l [ link-right (splay) ] when
+    ] when ;
+
+: splay-right
+    dup splay-node-r [
+        rcmp 0 > [ rotate-left ] when
+        dup splay-node-r [ link-left (splay) ] when
+    ] when ;
+
+: (splay) ( left right key node -- left right key node )
+    cmp dup 0 <
+    [ drop splay-left ] [ 0 > [ splay-right ] when ] if ;
+
+: assemble ( head left right node -- root )
+    [ splay-node-r swap set-splay-node-l ] keep
+    [ splay-node-l swap set-splay-node-r ] keep
+    [ swap splay-node-l swap set-splay-node-r ] 2keep
+    [ swap splay-node-r swap set-splay-node-l ] keep ;
+
+: splay-at ( key node -- node )
+    >r >r T{ splay-node } dup dup r> r> (splay) nip assemble ;
+
+: splay ( key tree -- )
+    [ splay-tree-r splay-at ] keep set-splay-tree-r ;
+
+: splay-split ( key tree -- node node )
+    2dup splay splay-tree-r cmp 0 < [
+        nip dup splay-node-l swap f over set-splay-node-l
+    ] [
+        nip dup splay-node-r swap f over set-splay-node-r swap
+    ] if ;
+
+: (get-splay) ( key tree -- node )
+    2dup splay splay-tree-r cmp 0 = [ nip ] [ 2drop f ] if ;
+
+: get-largest ( node -- node )
+    dup [ dup splay-node-r [ nip get-largest ] when* ] when ;
+
+: splay-largest
+    dup [ dup get-largest splay-node-k swap splay-at ] when ;
+
+: splay-join ( n2 n1 -- node )
+    splay-largest [ [ set-splay-node-r ] keep ] [ drop f ] if* ;
+
+: (remove-splay) ( key tree -- )
+    tuck (get-splay) [
+        dup splay-node-r swap splay-node-l splay-join
+        swap set-splay-tree-r
+    ] [ drop ] if* ;
+
+: (set-splay) ( value key tree -- )
+    2dup (get-splay) [ 2nip set-splay-node-v ] [
+       2dup splay-split rot >r <splay-node> r> set-splay-tree-r
+    ] if* ;
+
+: new-root ( value key tree -- )
+    >r f f <splay-node> r> set-splay-tree-r ;
+
+: set-splay ( value key tree -- )
+    dup splay-tree-r [ (set-splay) ] [ new-root ] if ;
+
+: get-splay ( key tree -- value )
+    dup splay-tree-r [
+        (get-splay) dup [ splay-node-v ] when
+    ] [
+        2drop f
+    ] if ;
+
+: remove-splay ( key tree -- )
+    dup splay-tree-r [ (remove-splay) ] [ 2drop ] if ;
diff --git a/contrib/splay-trees/tests.factor b/contrib/splay-trees/tests.factor
new file mode 100644 (file)
index 0000000..38c5d79
--- /dev/null
@@ -0,0 +1,5 @@
+USING: splay-trees namespaces sequences kernel namespaces words ;
+
+<splay-tree> "foo" set
+all-words [ dup word-name "foo" get set-splay ] each
+all-words [ word-name "foo" get get-splay drop ] each
index a9c804fb340b68ebc7e3dcd0070a4ed3c88434a6..db4d5ee2f44c81d9e0e0e47966502543f7a284cc 100644 (file)
@@ -32,7 +32,7 @@ SYMBOL: receiver
 : join ( chan -- )
     "JOIN " irc-write irc-print ;
 
-GENERIC: handle-irc
+GENERIC: handle-irc ( line -- )
 PREDICATE: string privmsg " " split1 nip "PRIVMSG" head? ;
 PREDICATE: string ping "PING" head? ;
 
@@ -112,3 +112,5 @@ IN: factorbot-commands
     drop speaker get "slava" = [ disconnect ] when ;
 
 PROVIDE: examples/factorbot ;
+
+MAIN: examples/factorbot factorbot ;
index 07bf8de26d40fa459f6c0b57b9ba52b770c7aa58..32e07193abd8cc72c314fd945194031f306abc67 100644 (file)
@@ -13,6 +13,6 @@ USING: sequences kernel math io ;
 : lcd ( digit-str -- )
     3 [ 2dup lcd-row terpri ] repeat drop ;
 
-"31337" lcd
-
 PROVIDE: examples/lcd ;
+
+MAIN: examples/lcd "31337" lcd ;
diff --git a/examples/levenshtein.factor b/examples/levenshtein.factor
deleted file mode 100644 (file)
index 84faa36..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-! Copyright (C) 2006 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: arrays compiler help io kernel math namespaces sequences
-test words ;
-IN: levenshtein
-
-: <matrix> ( m n -- matrix )
-    [ drop 0 <array> ] map-with ; inline
-
-: matrix-> nth nth ; inline
-: ->matrix nth set-nth ; inline
-
-SYMBOL: d
-
-: ->d ( n i j -- ) d get ->matrix ; inline
-: d-> ( i j -- n ) d get matrix-> ; inline
-
-SYMBOL: costs
-
-: init-d ( str1 str2 -- )
-    [ length 1+ ] 2apply 2dup <matrix> d set
-    [ 0 over ->d ] each
-    [ dup 0 ->d ] each ; inline
-
-: compute-costs ( str1 str2 -- )
-    >array [
-        swap >array [ = 0 1 ? ] map-with
-    ] map-with costs set ; inline
-
-: levenshtein-step ( i j -- )
-    [ 1+ d-> 1+ ] 2keep
-    [ >r 1+ r> d-> 1+ ] 2keep
-    [ d-> ] 2keep
-    [ costs get matrix-> + min min ] 2keep
-    >r 1+ r> 1+ ->d ; inline
-
-: levenshtein-result ( -- n ) d get peek peek ; inline
-
-: levenshtein ( str1 str2 -- n )
-    [
-        2dup init-d
-        2dup compute-costs
-        [ length ] 2apply [
-            swap [ swap levenshtein-step ] each-with
-        ] each-with
-        levenshtein-result
-    ] with-scope ; compiled
-
-[ 3 ] [ "sitting" "kitten" levenshtein ] unit-test
-[ 3 ] [ "kitten" "sitting" levenshtein ] unit-test
-[ 1 ] [ "freshpak" "freshpack" levenshtein ] unit-test
-[ 1 ] [ "freshpack" "freshpak" levenshtein ] unit-test
-
-: fancy-apropos ( str -- )
-    all-words
-    [ [ word-name levenshtein ] keep 2array ] map-with
-    [ first 3 <= ] subset
-    natural-sort [
-        second [ word-name ] keep [ help ] write-outliner
-        terpri
-    ] each ;
-
-PROVIDE: examples/levenshtein ;
diff --git a/examples/levenshtein/levenshtein.factor b/examples/levenshtein/levenshtein.factor
new file mode 100644 (file)
index 0000000..8aab1d9
--- /dev/null
@@ -0,0 +1,55 @@
+! Copyright (C) 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: arrays help io kernel math namespaces sequences words ;
+IN: levenshtein
+
+: <matrix> ( m n -- matrix )
+    [ drop 0 <array> ] map-with ; inline
+
+: matrix-> nth nth ; inline
+: ->matrix nth set-nth ; inline
+
+SYMBOL: d
+
+: ->d ( n i j -- ) d get ->matrix ; inline
+: d-> ( i j -- n ) d get matrix-> ; inline
+
+SYMBOL: costs
+
+: init-d ( str1 str2 -- )
+    [ length 1+ ] 2apply 2dup <matrix> d set
+    [ 0 over ->d ] each
+    [ dup 0 ->d ] each ; inline
+
+: compute-costs ( str1 str2 -- )
+    >array [
+        swap >array [ = 0 1 ? ] map-with
+    ] map-with costs set ; inline
+
+: levenshtein-step ( i j -- )
+    [ 1+ d-> 1+ ] 2keep
+    [ >r 1+ r> d-> 1+ ] 2keep
+    [ d-> ] 2keep
+    [ costs get matrix-> + min min ] 2keep
+    >r 1+ r> 1+ ->d ; inline
+
+: levenshtein-result ( -- n ) d get peek peek ; inline
+
+: levenshtein ( str1 str2 -- n )
+    [
+        2dup init-d
+        2dup compute-costs
+        [ length ] 2apply [
+            swap [ swap levenshtein-step ] each-with
+        ] each-with
+        levenshtein-result
+    ] with-scope ;
+
+: fancy-apropos ( str -- )
+    all-words
+    [ [ word-name levenshtein ] keep 2array ] map-with
+    [ first 3 <= ] subset
+    natural-sort [
+        second [ word-name ] keep [ help ] write-outliner
+        terpri
+    ] each ;
diff --git a/examples/levenshtein/load.factor b/examples/levenshtein/load.factor
new file mode 100644 (file)
index 0000000..57ebc7f
--- /dev/null
@@ -0,0 +1,3 @@
+PROVIDE: examples/levenshtein
+{ +files+ { "levenshtein.factor" } }
+{ +tests+ { "tests.factor" } } ;
diff --git a/examples/levenshtein/tests.factor b/examples/levenshtein/tests.factor
new file mode 100644 (file)
index 0000000..7dd649b
--- /dev/null
@@ -0,0 +1,9 @@
+! Copyright (C) 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: levenshtein
+USING: test ;
+
+[ 3 ] [ "sitting" "kitten" levenshtein ] unit-test
+[ 3 ] [ "kitten" "sitting" levenshtein ] unit-test
+[ 1 ] [ "freshpak" "freshpack" levenshtein ] unit-test
+[ 1 ] [ "freshpack" "freshpak" levenshtein ] unit-test
diff --git a/examples/mandel.factor b/examples/mandel.factor
deleted file mode 100644 (file)
index a1bb7a4..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-! Run this file to write a Mandelbrot fractal to "mandel.ppm".
-
-IN: mandel
-USING: arrays compiler io kernel math namespaces sequences
-strings test ;
-
-: max-color 360 ; inline
-: zoom-fact 0.8 ; inline
-: width 640 ; inline
-: height 480 ; inline
-: nb-iter 40 ; inline
-: center -0.65 ; inline
-
-: f_ ( h s v i -- f ) >r swap rot >r 2dup r> 6 * r> - ;
-: p ( v s x -- v p x ) >r dupd neg 1 + * r> ;
-: q ( v s f -- q ) * neg 1 + * ;
-: t_ ( v s f -- t_ ) neg 1 + * neg 1 + * ;
-
-: mod-cond ( p vector -- )
-    #! Call p mod q'th entry of the vector of quotations, where
-    #! q is the length of the vector. The value q remains on the
-    #! stack.
-    [ dupd length mod ] keep nth call ;
-
-: hsv>rgb ( h s v -- r g b )
-    pick 6 * >fixnum {
-        [ f_ t_ p swap     ( v p t ) ]
-        [ f_ q  p -rot     ( q v p ) ]
-        [ f_ t_ p swapd    ( p v t ) ]
-        [ f_ q  p rot      ( p q v ) ]
-        [ f_ t_ p swap rot ( t p v ) ]
-        [ f_ q  p          ( v p q ) ]
-    } mod-cond ;
-
-[ 1/2 1/2 1/2 ] [ 0 0 1/2 hsv>rgb ] unit-test
-
-[ 1/2 1/4 1/4 ] [ 0 1/2 1/2 hsv>rgb ] unit-test
-[ 1/3 2/9 2/9 ] [ 0 1/3 1/3 hsv>rgb ] unit-test
-
-[ 24/125 1/5 4/25 ] [ 1/5 1/5 1/5 hsv>rgb ] unit-test
-[ 29/180 1/6 5/36 ] [ 1/5 1/6 1/6 hsv>rgb ] unit-test
-
-[ 6/25 2/5 38/125 ] [ 2/5 2/5 2/5 hsv>rgb ] unit-test
-[ 8/25 4/5 64/125 ] [ 2/5 3/5 4/5 hsv>rgb ] unit-test
-
-[ 6/25 48/125 3/5 ] [ 3/5 3/5 3/5 hsv>rgb ] unit-test
-[ 0 0 0 ] [ 3/5 1/5 0 hsv>rgb ] unit-test
-
-[ 84/125 4/25 4/5 ] [ 4/5 4/5 4/5 hsv>rgb ] unit-test
-[ 7/15 1/3 1/2 ] [ 4/5 1/3 1/2 hsv>rgb ] unit-test
-
-[ 5/6 5/36 5/6 ] [ 5/6 5/6 5/6 hsv>rgb ] unit-test
-[ 1/6 0 1/6 ] [ 5/6 1 1/6 hsv>rgb ] unit-test
-
-[ 1 0 0 ] [ 1 1 1 hsv>rgb ] unit-test
-[ 1/6 1/9 1/9 ] [ 1 1/3 1/6 hsv>rgb ] unit-test
-
-: scale 255 * >fixnum ; inline
-
-: scale-rgb ( r g b -- n )
-    rot scale rot scale rot scale 3array ;
-
-: sat 0.85 ; inline
-: val 0.85 ; inline
-
-: <color-map> ( nb-cols -- map )
-    dup [
-        360 * swap 1+ / 360 / sat val
-        hsv>rgb scale-rgb
-    ] map-with ;
-
-: iter ( c z nb-iter -- x )
-    over absq 4.0 >= over zero? or
-    [ 2nip ] [ 1- >r sq dupd + r> iter ] if ; inline
-
-SYMBOL: cols
-
-: x-inc width 200000 zoom-fact * / ; inline
-: y-inc height 150000 zoom-fact * / ; inline
-
-: c ( i j -- c )
-    >r
-    x-inc * center real x-inc width 2 / * - + >float
-    r>
-    y-inc * center imaginary y-inc height 2 / * - + >float
-    rect> ; inline
-
-: render ( -- )
-    height [
-        width [
-            2dup swap c 0 nb-iter iter dup zero? [
-                drop "\0\0\0"
-            ] [
-                cols get [ length mod ] keep nth
-            ] if %
-        ] repeat
-    ] repeat ;
-
-: ppm-header ( w h -- )
-    "P6\n" % swap # " " % # "\n255\n" % ;
-
-: sbuf-size width height * 3 * 100 + ;
-
-: run ( -- string )
-    [
-        sbuf-size <sbuf> building set
-        width height ppm-header
-        nb-iter max-color min <color-map> cols set
-        render
-        building get >string
-    ] with-scope ;
-
-: run>file ( file -- )
-    "Generating " write dup write "..." print
-    <file-writer> [ run write ] with-stream ;
-
-[ "mandel.pnm" run>file ] time
-
-PROVIDE: examples/mandel ;
diff --git a/examples/mandel/load.factor b/examples/mandel/load.factor
new file mode 100644 (file)
index 0000000..26a695b
--- /dev/null
@@ -0,0 +1,8 @@
+PROVIDE: examples/mandel
+{ +files+ { "mandel.factor" } }
+{ +tests+ { "tests.factor" } } ;
+
+USE: mandel
+USE: test
+
+MAIN: examples/mandel [ "mandel.pnm" run>file ] time ;
diff --git a/examples/mandel/mandel.factor b/examples/mandel/mandel.factor
new file mode 100644 (file)
index 0000000..761ea05
--- /dev/null
@@ -0,0 +1,92 @@
+! Run this file to write a Mandelbrot fractal to "mandel.ppm".
+
+IN: mandel
+USING: arrays compiler io kernel math namespaces sequences
+strings test ;
+
+: max-color 360 ; inline
+: zoom-fact 0.8 ; inline
+: width 640 ; inline
+: height 480 ; inline
+: nb-iter 40 ; inline
+: center -0.65 ; inline
+
+: f_ >r swap rot >r 2dup r> 6 * r> - ;
+: p ( v s x -- v p x ) >r dupd neg 1 + * r> ;
+: q ( v s f -- q ) * neg 1 + * ;
+: t_ ( v s f -- t_ ) neg 1 + * neg 1 + * ;
+
+: mod-cond ( p vector -- )
+    #! Call p mod q'th entry of the vector of quotations, where
+    #! q is the length of the vector. The value q remains on the
+    #! stack.
+    [ dupd length mod ] keep nth call ;
+
+: hsv>rgb ( h s v -- r g b )
+    pick 6 * >fixnum {
+        [ f_ t_ p swap     ] ! v p t
+        [ f_ q  p -rot     ] ! q v p
+        [ f_ t_ p swapd    ] ! p v t
+        [ f_ q  p rot      ] ! p q v
+        [ f_ t_ p swap rot ] ! t p v
+        [ f_ q  p          ] ! v p q
+    } mod-cond ;
+
+: scale 255 * >fixnum ; inline
+
+: scale-rgb ( r g b -- n )
+    rot scale rot scale rot scale 3array ;
+
+: sat 0.85 ; inline
+: val 0.85 ; inline
+
+: <color-map> ( nb-cols -- map )
+    dup [
+        360 * swap 1+ / 360 / sat val
+        hsv>rgb scale-rgb
+    ] map-with ;
+
+: iter ( c z nb-iter -- x )
+    over absq 4.0 >= over zero? or
+    [ 2nip ] [ 1- >r sq dupd + r> iter ] if ; inline
+
+SYMBOL: cols
+
+: x-inc width 200000 zoom-fact * / ; inline
+: y-inc height 150000 zoom-fact * / ; inline
+
+: c ( i j -- c )
+    >r
+    x-inc * center real x-inc width 2 / * - + >float
+    r>
+    y-inc * center imaginary y-inc height 2 / * - + >float
+    rect> ; inline
+
+: render ( -- )
+    height [
+        width [
+            2dup swap c 0 nb-iter iter dup zero? [
+                drop "\0\0\0"
+            ] [
+                cols get [ length mod ] keep nth
+            ] if %
+        ] repeat
+    ] repeat ;
+
+: ppm-header ( w h -- )
+    "P6\n" % swap # " " % # "\n255\n" % ;
+
+: sbuf-size width height * 3 * 100 + ;
+
+: run ( -- string )
+    [
+        sbuf-size <sbuf> building set
+        width height ppm-header
+        nb-iter max-color min <color-map> cols set
+        render
+        building get >string
+    ] with-scope ;
+
+: run>file ( file -- )
+    "Generating " write dup write "..." print
+    <file-writer> [ run write ] with-stream ;
diff --git a/examples/mandel/tests.factor b/examples/mandel/tests.factor
new file mode 100644 (file)
index 0000000..fddc691
--- /dev/null
@@ -0,0 +1,25 @@
+IN: mandel
+USE: test
+
+[ 1/2 1/2 1/2 ] [ 0 0 1/2 hsv>rgb ] unit-test
+
+[ 1/2 1/4 1/4 ] [ 0 1/2 1/2 hsv>rgb ] unit-test
+[ 1/3 2/9 2/9 ] [ 0 1/3 1/3 hsv>rgb ] unit-test
+
+[ 24/125 1/5 4/25 ] [ 1/5 1/5 1/5 hsv>rgb ] unit-test
+[ 29/180 1/6 5/36 ] [ 1/5 1/6 1/6 hsv>rgb ] unit-test
+
+[ 6/25 2/5 38/125 ] [ 2/5 2/5 2/5 hsv>rgb ] unit-test
+[ 8/25 4/5 64/125 ] [ 2/5 3/5 4/5 hsv>rgb ] unit-test
+
+[ 6/25 48/125 3/5 ] [ 3/5 3/5 3/5 hsv>rgb ] unit-test
+[ 0 0 0 ] [ 3/5 1/5 0 hsv>rgb ] unit-test
+
+[ 84/125 4/25 4/5 ] [ 4/5 4/5 4/5 hsv>rgb ] unit-test
+[ 7/15 1/3 1/2 ] [ 4/5 1/3 1/2 hsv>rgb ] unit-test
+
+[ 5/6 5/36 5/6 ] [ 5/6 5/6 5/6 hsv>rgb ] unit-test
+[ 1/6 0 1/6 ] [ 5/6 1 1/6 hsv>rgb ] unit-test
+
+[ 1 0 0 ] [ 1 1 1 hsv>rgb ] unit-test
+[ 1/6 1/9 1/9 ] [ 1 1/3 1/6 hsv>rgb ] unit-test
diff --git a/examples/print-dataflow.factor b/examples/print-dataflow.factor
deleted file mode 100644 (file)
index 9879d22..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-IN: print-dataflow
-USING: generic hashtables inference io kernel kernel-internals
-math namespaces prettyprint sequences styles vectors words
-test optimizer ;
-
-! A simple tool for turning dataflow IR into quotations, for
-! debugging purposes.
-
-GENERIC: node>quot ( ? node -- )
-
-TUPLE: comment node text ;
-
-M: comment pprint*
-    "( " over comment-text " )" append3
-    swap comment-node presented associate
-    styled-text ;
-
-: comment, ( ? node text -- )
-    rot [ <comment> , ] [ 2drop ] if ;
-
-: values% ( prefix values -- )
-    [
-        swap %
-        dup value? [
-            value-literal unparse %
-        ] [
-            "@" % #
-        ] if
-    ] each-with ;
-
-: effect-str ( node -- str )
-    [
-        " " over node-in-d values%
-        " r: " over node-in-r values%
-        " --" %
-        " " over node-out-d values%
-        " r: " swap node-out-r values%
-    ] "" make 1 tail ;
-
-M: #shuffle node>quot
-    >r drop t r> dup effect-str "#shuffle: " swap append comment, ;
-
-M: #push node>quot nip >#push< % ;
-
-DEFER: dataflow>quot
-
-: #call>quot ( ? node -- )
-    dup node-param dup
-    [ , dup effect-str comment, ] [ 3drop ] if ;
-
-M: #call node>quot #call>quot ;
-
-M: #call-label node>quot #call>quot ;
-
-M: #label node>quot
-    [ "#label: " over node-param word-name append comment, ] 2keep
-    node-child swap dataflow>quot , \ call ,  ;
-
-M: #if node>quot
-    [ "#if" comment, ] 2keep
-    node-children [ swap dataflow>quot ] map-with % \ if , ;
-
-M: #dispatch node>quot
-    [ "#dispatch" comment, ] 2keep
-    node-children [ swap dataflow>quot ] map-with , \ dispatch , ;
-
-M: #return node>quot
-    dup node-param unparse "#return " swap append comment, ;
-
-M: object node>quot dup class word-name comment, ;
-
-: (dataflow>quot) ( ? node -- )
-    dup [
-        2dup node>quot node-successor (dataflow>quot)
-    ] [
-        2drop
-    ] if ;
-
-: dataflow>quot ( node ? -- quot )
-    [ swap (dataflow>quot) ] [ ] make ;
-
-: dataflow. ( quot ? -- )
-    #! Print dataflow IR for a quotation. Flag indicates if
-    #! annotations should be printed or not.
-    >r dataflow optimize r> dataflow>quot . ;
-
-[ ] [ [ 2 ] t dataflow. ] unit-test
-[ ] [ [ 3 + ] t dataflow. ] unit-test
-[ ] [ [ drop ] t dataflow. ] unit-test
-[ ] [ [ [ sq ] [ abs ] if ] t dataflow. ] unit-test
-[ ] [ [ { [ sq ] [ abs ] } dispatch ] t dataflow. ] unit-test
-[ ] [ \ unify-values word-def t dataflow. ] unit-test
-[ ] [ [ 0 0 / ] t dataflow. ] unit-test
diff --git a/examples/print-dataflow/load.factor b/examples/print-dataflow/load.factor
new file mode 100644 (file)
index 0000000..5979f16
--- /dev/null
@@ -0,0 +1,3 @@
+PROVIDE: examples/print-dataflow
+{ +files+ { "print-dataflow.factor" } }
+{ +tests+ { "tests.factor" } } ;
diff --git a/examples/print-dataflow/print-dataflow.factor b/examples/print-dataflow/print-dataflow.factor
new file mode 100644 (file)
index 0000000..4abb99c
--- /dev/null
@@ -0,0 +1,85 @@
+IN: print-dataflow
+USING: generic hashtables inference io kernel kernel-internals
+math namespaces prettyprint sequences styles vectors words
+optimizer ;
+
+! A simple tool for turning dataflow IR into quotations, for
+! debugging purposes.
+
+GENERIC: node>quot ( ? node -- )
+
+TUPLE: comment node text ;
+
+M: comment pprint*
+    "( " over comment-text " )" append3
+    swap comment-node presented associate
+    styled-text ;
+
+: comment, ( ? node text -- )
+    rot [ <comment> , ] [ 2drop ] if ;
+
+: values% ( prefix values -- )
+    [
+        swap %
+        dup value? [
+            value-literal unparse %
+        ] [
+            "@" % #
+        ] if
+    ] each-with ;
+
+: effect-str ( node -- str )
+    [
+        " " over node-in-d values%
+        " r: " over node-in-r values%
+        " --" %
+        " " over node-out-d values%
+        " r: " swap node-out-r values%
+    ] "" make 1 tail ;
+
+M: #shuffle node>quot
+    >r drop t r> dup effect-str "#shuffle: " swap append comment, ;
+
+M: #push node>quot nip >#push< % ;
+
+DEFER: dataflow>quot
+
+: #call>quot ( ? node -- )
+    dup node-param dup
+    [ , dup effect-str comment, ] [ 3drop ] if ;
+
+M: #call node>quot #call>quot ;
+
+M: #call-label node>quot #call>quot ;
+
+M: #label node>quot
+    [ "#label: " over node-param word-name append comment, ] 2keep
+    node-child swap dataflow>quot , \ call ,  ;
+
+M: #if node>quot
+    [ "#if" comment, ] 2keep
+    node-children [ swap dataflow>quot ] map-with % \ if , ;
+
+M: #dispatch node>quot
+    [ "#dispatch" comment, ] 2keep
+    node-children [ swap dataflow>quot ] map-with , \ dispatch , ;
+
+M: #return node>quot
+    dup node-param unparse "#return " swap append comment, ;
+
+M: object node>quot dup class word-name comment, ;
+
+: (dataflow>quot) ( ? node -- )
+    dup [
+        2dup node>quot node-successor (dataflow>quot)
+    ] [
+        2drop
+    ] if ;
+
+: dataflow>quot ( node ? -- quot )
+    [ swap (dataflow>quot) ] [ ] make ;
+
+: dataflow. ( quot ? -- )
+    #! Print dataflow IR for a quotation. Flag indicates if
+    #! annotations should be printed or not.
+    >r dataflow optimize r> dataflow>quot . ;
diff --git a/examples/print-dataflow/tests.factor b/examples/print-dataflow/tests.factor
new file mode 100644 (file)
index 0000000..56fe05b
--- /dev/null
@@ -0,0 +1,9 @@
+IN: print-dataflow
+
+[ ] [ [ 2 ] t dataflow. ] unit-test
+[ ] [ [ 3 + ] t dataflow. ] unit-test
+[ ] [ [ drop ] t dataflow. ] unit-test
+[ ] [ [ [ sq ] [ abs ] if ] t dataflow. ] unit-test
+[ ] [ [ { [ sq ] [ abs ] } dispatch ] t dataflow. ] unit-test
+[ ] [ \ unify-values word-def t dataflow. ] unit-test
+[ ] [ [ 0 0 / ] t dataflow. ] unit-test
index 3b42e21d50bfc08b9415e0760a3fedeb96a5b74c..04eaedd1c79dc004380c59d35a5ed85878685895 100644 (file)
@@ -161,6 +161,6 @@ DEFER: create ( level c r -- scene )
     "Generating " write dup write "..." print
     <file-writer> [ run write ] with-stream ;
 
-[ "raytracer.pnm" run>file ] time
-
 PROVIDE: examples/raytracer ;
+
+MAIN: examples/raytracer [ "raytracer.pnm" run>file ] time ;
index 0b3753959f616f1d88e81d325b044b0adb0edb04..f92e2b0b8d0282b53126e7621d0ad3aae9f5b978 100644 (file)
@@ -1,5 +1,5 @@
 IN: turing
-USING: arrays hashtables io kernel lists math namespaces
+USING: arrays hashtables io kernel math namespaces
 prettyprint sequences strings vectors words ;
 
 ! A turing machine simulator.
@@ -14,12 +14,12 @@ SYMBOL: halt
 
 ! This is a simple program that outputs 5 1's
 H{
-    { [[ 1 0 ]] T{ state f 1  1 2    } }
-    { [[ 2 0 ]] T{ state f 1  1 3    } }
-    { [[ 3 0 ]] T{ state f 1 -1 1    } }
-    { [[ 1 1 ]] T{ state f 1 -1 2    } }
-    { [[ 2 1 ]] T{ state f 1 -1 3    } }
-    { [[ 3 1 ]] T{ state f 1 -1 halt } }
+    { { 1 0 } T{ state f 1  1 2    } }
+    { { 2 0 } T{ state f 1  1 3    } }
+    { { 3 0 } T{ state f 1 -1 1    } }
+    { { 1 1 } T{ state f 1 -1 2    } }
+    { { 2 1 } T{ state f 1 -1 3    } }
+    { { 3 1 } T{ state f 1 -1 halt } }
 } states set
 
 ! Current state
@@ -50,7 +50,7 @@ SYMBOL: tape
 
 : next-state ( -- state )
     #! Look up the next state/symbol/direction triplet.
-    state get sym cons states get hash ;
+    state get sym 2array states get hash ;
 
 : turing-step ( -- )
     #! Do one step of the turing machine.
@@ -63,7 +63,7 @@ SYMBOL: tape
     #! Print current turing machine state.
     state get .
     tape get .
-    2 position get 2 * + CHAR: \s fill write "^" print ;
+    2 position get 2 * + CHAR: \s <string> write "^" print ;
 
 : n
     #! Do one step and print new state.
index c6956cb23338becaef401a582eb76be6171e39f1..adf4f5bbdefdd8533f31cb8f32d66b96ad65b794 100644 (file)
@@ -96,7 +96,7 @@ TUPLE: too-many-r> ;
     ] when ;
 
 : undo-infer ( -- )
-    recorded get [ "infer" word-prop not ] subset [
+    recorded get [ custom-infer? not ] subset [
         dup
         f "inferred-vars" set-word-prop
         f "inferred-effect" set-word-prop
index 76455689bcc6478c92c79ace448b106fc7da69e0..dc4d144829f3762375ef1fa7011ab2035b884a2a 100644 (file)
@@ -62,8 +62,8 @@ USING: kernel arrays sequences math namespaces strings io ;
         [ swap call dup rot fuzzy score ] keep swap 2array
     ] if ; inline
 
-: completions ( str candidates quot -- seq )
-    pick empty? pick length 100 >= and [
+: completions ( str quot candidates -- seq )
+    pick empty? over length 100 >= and [
         3drop f
     ] [
         [ >r 2dup r> completion ] map 2nip rank-completions
index 82c2b4cce63ce6748d3bf38b524988059b955fd5..4a6493b9d73d58e9212510a3b25e11f0e2e8e1d9 100644 (file)
@@ -79,10 +79,13 @@ SYMBOL: crossref
 
 : reset-props ( word seq -- ) [ remove-word-prop ] each-with ;
 
+: custom-infer? ( word -- ? )
+    dup "infer" word-prop swap "infer-vars" word-prop or ;
+
 : unxref-word* ( word -- )
     {
         { [ dup compound? not ] [ drop ] }
-        { [ dup "infer" word-prop ] [ drop ] }
+        { [ dup custom-infer? ] [ drop ] }
         { [ t ] [
             dup changed-word
             {