]> gitweb.factorcode.org Git - factor.git/commitdiff
Move a few things around
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 29 Jul 2008 03:09:35 +0000 (22:09 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 29 Jul 2008 03:09:35 +0000 (22:09 -0500)
24 files changed:
basis/io/files/unique/backend/backend.factor [deleted file]
basis/io/files/unique/unique-docs.factor [deleted file]
basis/io/files/unique/unique.factor [deleted file]
basis/io/paths/authors.txt [deleted file]
basis/io/paths/paths.factor [deleted file]
basis/promises/authors.txt [deleted file]
basis/promises/promises-docs.factor [deleted file]
basis/promises/promises.factor [deleted file]
basis/promises/summary.txt [deleted file]
basis/promises/tags.txt [deleted file]
basis/random/blum-blum-shub/blum-blum-shub-tests.factor [deleted file]
basis/random/blum-blum-shub/blum-blum-shub.factor [deleted file]
extra/io/files/unique/backend/backend.factor [new file with mode: 0644]
extra/io/files/unique/unique-docs.factor [new file with mode: 0644]
extra/io/files/unique/unique.factor [new file with mode: 0644]
extra/io/paths/authors.txt [new file with mode: 0755]
extra/io/paths/paths.factor [new file with mode: 0755]
extra/promises/authors.txt [new file with mode: 0644]
extra/promises/promises-docs.factor [new file with mode: 0755]
extra/promises/promises.factor [new file with mode: 0755]
extra/promises/summary.txt [new file with mode: 0644]
extra/promises/tags.txt [new file with mode: 0644]
extra/random/blum-blum-shub/blum-blum-shub-tests.factor [new file with mode: 0644]
extra/random/blum-blum-shub/blum-blum-shub.factor [new file with mode: 0755]

diff --git a/basis/io/files/unique/backend/backend.factor b/basis/io/files/unique/backend/backend.factor
deleted file mode 100644 (file)
index 7b9809f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-USING: io.backend ;
-IN: io.files.unique.backend
-
-HOOK: (make-unique-file) io-backend ( path -- )
-HOOK: temporary-path io-backend ( -- path )
diff --git a/basis/io/files/unique/unique-docs.factor b/basis/io/files/unique/unique-docs.factor
deleted file mode 100644 (file)
index bb4e9ef..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-USING: help.markup help.syntax io io.ports kernel math
-io.files.unique.private math.parser io.files ;
-IN: io.files.unique
-
-ARTICLE: "unique" "Making and using unique files"
-"Files:"
-{ $subsection make-unique-file }
-{ $subsection with-unique-file }
-"Directories:"
-{ $subsection make-unique-directory }
-{ $subsection with-unique-directory } ;
-
-ABOUT: "unique"
-
-HELP: make-unique-file ( prefix suffix -- path )
-{ $values { "prefix" "a string" } { "suffix" "a string" }
-{ "path" "a pathname string" } }
-{ $description "Creates a file that is guaranteed not to exist in a platform-specific temporary directory.  The file name is composed of a prefix, a number of random digits and letters, and the suffix.  Returns the full pathname." }
-{ $errors "Throws an error if a new unique file cannot be created after a number of tries.  Since each try generates a new random name, the most likely error is incorrect directory permissions on the temporary directory." }
-{ $see-also with-unique-file } ;
-
-HELP: make-unique-directory ( -- path )
-{ $values { "path" "a pathname string" } }
-{ $description "Creates a directory that is guaranteed not to exist in a platform-specific temporary directory and returns the full pathname." }
-{ $errors "Throws an error if the directory cannot be created after a number of tries.  Since each try generates a new random name, the most likely error is incorrect directory permissions on the temporary directory." }
-{ $see-also with-unique-directory } ;
-
-HELP: with-unique-file ( prefix suffix quot -- )
-{ $values { "prefix" "a string" } { "suffix" "a string" }
-{ "quot" "a quotation" } }
-{ $description "Creates a file with " { $link make-unique-file } " and calls the quotation with the path name on the stack." }
-{ $notes "The unique file will be deleted after calling this word." } ;
-
-HELP: with-unique-directory ( quot -- )
-{ $values { "quot" "a quotation" } }
-{ $description "Creates a directory with " { $link make-unique-directory } " and calls the quotation with the pathname on the stack." }
-{ $notes "The directory will be deleted after calling this word." } ;
diff --git a/basis/io/files/unique/unique.factor b/basis/io/files/unique/unique.factor
deleted file mode 100644 (file)
index 3efef66..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-! Copyright (C) 2008 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.bitfields combinators.lib math.parser
-random sequences sequences.lib continuations namespaces
-io.files io arrays io.files.unique.backend system
-combinators vocabs.loader ;
-IN: io.files.unique
-
-<PRIVATE
-: random-letter ( -- ch )
-    26 random { CHAR: a CHAR: A } random + ;
-
-: random-ch ( -- ch )
-    { t f } random
-    [ 10 random CHAR: 0 + ] [ random-letter ] if ;
-
-: random-name ( n -- string )
-    [ random-ch ] "" replicate-as ;
-
-: unique-length ( -- n ) 10 ; inline
-: unique-retries ( -- n ) 10 ; inline
-PRIVATE>
-
-: make-unique-file ( prefix suffix -- path )
-    temporary-path -rot
-    [
-        unique-length random-name swap 3append append-path
-        dup (make-unique-file)
-    ] 3curry unique-retries retry ;
-
-: with-unique-file ( prefix suffix quot -- )
-    >r make-unique-file r> keep delete-file ; inline
-
-: make-unique-directory ( -- path )
-    [
-        temporary-path unique-length random-name append-path
-        dup make-directory
-    ] unique-retries retry ;
-
-: with-unique-directory ( quot -- )
-    >r make-unique-directory r>
-    [ with-directory ] curry keep delete-tree ; inline
-
-{
-    { [ os unix? ] [ "io.unix.files.unique" ] }
-    { [ os windows? ] [ "io.windows.files.unique" ] }
-} cond require
diff --git a/basis/io/paths/authors.txt b/basis/io/paths/authors.txt
deleted file mode 100755 (executable)
index 7c1b2f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Doug Coleman
diff --git a/basis/io/paths/paths.factor b/basis/io/paths/paths.factor
deleted file mode 100755 (executable)
index 98cf3e5..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-USING: io.files kernel sequences accessors
-dlists dequeues arrays sequences.lib ;
-IN: io.paths
-
-TUPLE: directory-iterator path bfs queue ;
-
-: qualified-directory ( path -- seq )
-    dup directory [ first2 >r append-path r> 2array ] with map ;
-
-: push-directory ( path iter -- )
-    >r qualified-directory r> [
-        dup queue>> swap bfs>>
-        [ push-front ] [ push-back ] if
-    ] curry each ;
-
-: <directory-iterator> ( path bfs? -- iterator )
-    <dlist> directory-iterator boa
-    dup path>> over push-directory ;
-
-: next-file ( iter -- file/f )
-    dup queue>> dequeue-empty? [ drop f ] [
-        dup queue>> pop-back first2
-        [ over push-directory next-file ] [ nip ] if
-    ] if ;
-
-: iterate-directory ( iter quot -- obj )
-    2dup >r >r >r next-file dup [
-        r> call dup [
-            r> r> 2drop
-        ] [
-            drop r> r> iterate-directory
-        ] if
-    ] [
-        drop r> r> r> 3drop f
-    ] if ; inline
-
-: find-file ( path bfs? quot -- path/f )
-    >r <directory-iterator> r>
-    [ keep and ] curry iterate-directory ; inline
-
-: each-file ( path bfs? quot -- )
-    >r <directory-iterator> r>
-    [ f ] compose iterate-directory drop ; inline
-
-: find-all-files ( path bfs? quot -- paths )
-    >r <directory-iterator> r>
-    pusher >r [ f ] compose iterate-directory drop r> ; inline
-
-: recursive-directory ( path bfs? -- paths )
-    [ ] accumulator >r each-file r> ;
diff --git a/basis/promises/authors.txt b/basis/promises/authors.txt
deleted file mode 100644 (file)
index 44b06f9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Chris Double
diff --git a/basis/promises/promises-docs.factor b/basis/promises/promises-docs.factor
deleted file mode 100755 (executable)
index c482df0..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-! Copyright (C) 2006 Chris Double.
-! See http://factorcode.org/license.txt for BSD license.
-
-USING: help.markup help.syntax ;
-IN: promises
-
-HELP: promise 
-{ $values { "quot" "a quotation with stack effect ( -- X )" } { "promise" "a promise object" } }
-{ $description "Creates a promise to return a value. When forced this quotation is called and the value returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." } 
-{ $see-also force promise-with promise-with2 } ;
-
-HELP: promise-with
-{ $values { "value" "an object" } { "quot" "a quotation with stack effect ( value -- X )" } { "promise" "a promise object" } }
-{ $description "Creates a promise to return a value. When forced this quotation is called with the given value on the stack and the result returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." } 
-{ $see-also force promise promise-with2 } ;
-
-HELP: promise-with2
-{ $values { "value1" "an object" } { "value2" "an object" } { "quot" "a quotation with stack effect ( value1 value2 -- X )" } { "promise" "a promise object" } }
-{ $description "Creates a promise to return a value. When forced this quotation is called with the given values on the stack and the result returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." } 
-{ $see-also force promise promise-with2 } ;
-
-HELP: force
-{ $values { "promise" "a promise object" } { "value" "a factor object" } }
-{ $description "Calls the quotation associated with the promise if it has not been called before, and returns the value. If the promise has been forced previously, returns the value from the previous call." } 
-{ $see-also promise promise-with promise-with2 } ;
-
-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 "USING: arrays sequences prettyprint promises ;" "IN: scratchpad" "LAZY: zeroes ( -- pair ) 0 zeroes 2array ;" "zeroes force second force first ." "0" }
-}
-{ $see-also force promise-with promise-with2 } ;
diff --git a/basis/promises/promises.factor b/basis/promises/promises.factor
deleted file mode 100755 (executable)
index 2126f0c..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-! Copyright (C) 2004 Chris Double.
-! See http://factorcode.org/license.txt for BSD license.
-!
-! Updated by Matthew Willis, July 2006
-! Updated by Chris Double, September 2006
-
-USING: arrays kernel sequences math vectors arrays namespaces
-quotations parser effects inference words ;
-IN: promises
-
-TUPLE: promise quot forced? value ;
-
-: promise ( quot -- promise )
-  f f \ promise boa ;
-
-: promise-with ( value quot -- promise )
-  curry promise ;
-
-: promise-with2 ( value1 value2 quot -- promise )
-  2curry promise ;
-
-: force ( promise -- value )
-    #! Force the given promise leaving the value of calling the
-    #! promises quotation on the stack. Re-forcing the promise
-    #! will return the same value and not recall the quotation.
-    dup promise-forced? [
-        dup promise-quot call over set-promise-value
-        t over set-promise-forced?
-    ] unless
-    promise-value ;
-
-: stack-effect-in ( quot word -- n )
-  stack-effect [ ] [ infer ] ?if effect-in length ;
-
-: make-lazy-quot ( word quot -- quot )
-  [
-    dup ,
-    swap stack-effect-in \ curry <repetition> % 
-    \ promise ,
-  ] [ ] make ;
-
-: LAZY:
-  CREATE-WORD
-  dup parse-definition
-  make-lazy-quot define ; parsing
diff --git a/basis/promises/summary.txt b/basis/promises/summary.txt
deleted file mode 100644 (file)
index d64fe20..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Lazy thunks
diff --git a/basis/promises/tags.txt b/basis/promises/tags.txt
deleted file mode 100644 (file)
index f427429..0000000
+++ /dev/null
@@ -1 +0,0 @@
-extensions
diff --git a/basis/random/blum-blum-shub/blum-blum-shub-tests.factor b/basis/random/blum-blum-shub/blum-blum-shub-tests.factor
deleted file mode 100644 (file)
index 2a1af53..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-USING: kernel math tools.test namespaces random
-random.blum-blum-shub alien.c-types sequences splitting
-grouping ;
-IN: blum-blum-shub.tests
-
-[ 887708070 ] [
-    T{ blum-blum-shub f 590695557939 811977232793 } clone random-32*
-] unit-test
-
-
-[ 887708070 ] [
-    T{ blum-blum-shub f 590695557939 811977232793 } clone [
-        32 random-bits
-        little-endian? [ <uint> reverse *uint ] unless
-    ] with-random
-] unit-test
-
-[ 5726770047455156646 ] [
-    T{ blum-blum-shub f 590695557939 811977232793 } clone [
-        64 random-bits
-        little-endian? [ <ulonglong> 4 group [ reverse ] map concat *ulonglong ] unless
-    ] with-random
-] unit-test
-
-[ 3716213681 ]
-[
-    100 T{ blum-blum-shub f 200352954495 846054538649 } clone tuck [
-        random-32* drop
-    ] curry times
-    random-32*
-] unit-test
diff --git a/basis/random/blum-blum-shub/blum-blum-shub.factor b/basis/random/blum-blum-shub/blum-blum-shub.factor
deleted file mode 100755 (executable)
index e609900..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-USING: kernel math sequences namespaces
-math.miller-rabin combinators.lib
-math.functions accessors random ;
-IN: random.blum-blum-shub
-
-! Blum Blum Shub, n = pq, x_i+1 = x_i ^ 2 mod n
-! return low bit of x+1
-TUPLE: blum-blum-shub x n ;
-
-<PRIVATE
-
-: generate-bbs-primes ( numbits -- p q )
-    [ [ random-prime ] curry [ 4 mod 3 = ] generate ] dup bi ;
-
-: next-bbs-bit ( bbs -- bit )
-    [ [ x>> 2 ] [ n>> ] bi ^mod dup ] keep (>>x) 1 bitand ;
-
-PRIVATE>
-
-: <blum-blum-shub> ( numbits -- blum-blum-shub )
-    generate-bbs-primes *
-    [ find-relative-prime ] keep
-    blum-blum-shub boa ;
-
-M: blum-blum-shub random-32* ( bbs -- r )
-    0 32 rot
-    [ next-bbs-bit swap 1 shift bitor ] curry times ;
diff --git a/extra/io/files/unique/backend/backend.factor b/extra/io/files/unique/backend/backend.factor
new file mode 100644 (file)
index 0000000..7b9809f
--- /dev/null
@@ -0,0 +1,5 @@
+USING: io.backend ;
+IN: io.files.unique.backend
+
+HOOK: (make-unique-file) io-backend ( path -- )
+HOOK: temporary-path io-backend ( -- path )
diff --git a/extra/io/files/unique/unique-docs.factor b/extra/io/files/unique/unique-docs.factor
new file mode 100644 (file)
index 0000000..bb4e9ef
--- /dev/null
@@ -0,0 +1,37 @@
+USING: help.markup help.syntax io io.ports kernel math
+io.files.unique.private math.parser io.files ;
+IN: io.files.unique
+
+ARTICLE: "unique" "Making and using unique files"
+"Files:"
+{ $subsection make-unique-file }
+{ $subsection with-unique-file }
+"Directories:"
+{ $subsection make-unique-directory }
+{ $subsection with-unique-directory } ;
+
+ABOUT: "unique"
+
+HELP: make-unique-file ( prefix suffix -- path )
+{ $values { "prefix" "a string" } { "suffix" "a string" }
+{ "path" "a pathname string" } }
+{ $description "Creates a file that is guaranteed not to exist in a platform-specific temporary directory.  The file name is composed of a prefix, a number of random digits and letters, and the suffix.  Returns the full pathname." }
+{ $errors "Throws an error if a new unique file cannot be created after a number of tries.  Since each try generates a new random name, the most likely error is incorrect directory permissions on the temporary directory." }
+{ $see-also with-unique-file } ;
+
+HELP: make-unique-directory ( -- path )
+{ $values { "path" "a pathname string" } }
+{ $description "Creates a directory that is guaranteed not to exist in a platform-specific temporary directory and returns the full pathname." }
+{ $errors "Throws an error if the directory cannot be created after a number of tries.  Since each try generates a new random name, the most likely error is incorrect directory permissions on the temporary directory." }
+{ $see-also with-unique-directory } ;
+
+HELP: with-unique-file ( prefix suffix quot -- )
+{ $values { "prefix" "a string" } { "suffix" "a string" }
+{ "quot" "a quotation" } }
+{ $description "Creates a file with " { $link make-unique-file } " and calls the quotation with the path name on the stack." }
+{ $notes "The unique file will be deleted after calling this word." } ;
+
+HELP: with-unique-directory ( quot -- )
+{ $values { "quot" "a quotation" } }
+{ $description "Creates a directory with " { $link make-unique-directory } " and calls the quotation with the pathname on the stack." }
+{ $notes "The directory will be deleted after calling this word." } ;
diff --git a/extra/io/files/unique/unique.factor b/extra/io/files/unique/unique.factor
new file mode 100644 (file)
index 0000000..3efef66
--- /dev/null
@@ -0,0 +1,47 @@
+! Copyright (C) 2008 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel math math.bitfields combinators.lib math.parser
+random sequences sequences.lib continuations namespaces
+io.files io arrays io.files.unique.backend system
+combinators vocabs.loader ;
+IN: io.files.unique
+
+<PRIVATE
+: random-letter ( -- ch )
+    26 random { CHAR: a CHAR: A } random + ;
+
+: random-ch ( -- ch )
+    { t f } random
+    [ 10 random CHAR: 0 + ] [ random-letter ] if ;
+
+: random-name ( n -- string )
+    [ random-ch ] "" replicate-as ;
+
+: unique-length ( -- n ) 10 ; inline
+: unique-retries ( -- n ) 10 ; inline
+PRIVATE>
+
+: make-unique-file ( prefix suffix -- path )
+    temporary-path -rot
+    [
+        unique-length random-name swap 3append append-path
+        dup (make-unique-file)
+    ] 3curry unique-retries retry ;
+
+: with-unique-file ( prefix suffix quot -- )
+    >r make-unique-file r> keep delete-file ; inline
+
+: make-unique-directory ( -- path )
+    [
+        temporary-path unique-length random-name append-path
+        dup make-directory
+    ] unique-retries retry ;
+
+: with-unique-directory ( quot -- )
+    >r make-unique-directory r>
+    [ with-directory ] curry keep delete-tree ; inline
+
+{
+    { [ os unix? ] [ "io.unix.files.unique" ] }
+    { [ os windows? ] [ "io.windows.files.unique" ] }
+} cond require
diff --git a/extra/io/paths/authors.txt b/extra/io/paths/authors.txt
new file mode 100755 (executable)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/io/paths/paths.factor b/extra/io/paths/paths.factor
new file mode 100755 (executable)
index 0000000..98cf3e5
--- /dev/null
@@ -0,0 +1,50 @@
+USING: io.files kernel sequences accessors
+dlists dequeues arrays sequences.lib ;
+IN: io.paths
+
+TUPLE: directory-iterator path bfs queue ;
+
+: qualified-directory ( path -- seq )
+    dup directory [ first2 >r append-path r> 2array ] with map ;
+
+: push-directory ( path iter -- )
+    >r qualified-directory r> [
+        dup queue>> swap bfs>>
+        [ push-front ] [ push-back ] if
+    ] curry each ;
+
+: <directory-iterator> ( path bfs? -- iterator )
+    <dlist> directory-iterator boa
+    dup path>> over push-directory ;
+
+: next-file ( iter -- file/f )
+    dup queue>> dequeue-empty? [ drop f ] [
+        dup queue>> pop-back first2
+        [ over push-directory next-file ] [ nip ] if
+    ] if ;
+
+: iterate-directory ( iter quot -- obj )
+    2dup >r >r >r next-file dup [
+        r> call dup [
+            r> r> 2drop
+        ] [
+            drop r> r> iterate-directory
+        ] if
+    ] [
+        drop r> r> r> 3drop f
+    ] if ; inline
+
+: find-file ( path bfs? quot -- path/f )
+    >r <directory-iterator> r>
+    [ keep and ] curry iterate-directory ; inline
+
+: each-file ( path bfs? quot -- )
+    >r <directory-iterator> r>
+    [ f ] compose iterate-directory drop ; inline
+
+: find-all-files ( path bfs? quot -- paths )
+    >r <directory-iterator> r>
+    pusher >r [ f ] compose iterate-directory drop r> ; inline
+
+: recursive-directory ( path bfs? -- paths )
+    [ ] accumulator >r each-file r> ;
diff --git a/extra/promises/authors.txt b/extra/promises/authors.txt
new file mode 100644 (file)
index 0000000..44b06f9
--- /dev/null
@@ -0,0 +1 @@
+Chris Double
diff --git a/extra/promises/promises-docs.factor b/extra/promises/promises-docs.factor
new file mode 100755 (executable)
index 0000000..c482df0
--- /dev/null
@@ -0,0 +1,34 @@
+! Copyright (C) 2006 Chris Double.
+! See http://factorcode.org/license.txt for BSD license.
+
+USING: help.markup help.syntax ;
+IN: promises
+
+HELP: promise 
+{ $values { "quot" "a quotation with stack effect ( -- X )" } { "promise" "a promise object" } }
+{ $description "Creates a promise to return a value. When forced this quotation is called and the value returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." } 
+{ $see-also force promise-with promise-with2 } ;
+
+HELP: promise-with
+{ $values { "value" "an object" } { "quot" "a quotation with stack effect ( value -- X )" } { "promise" "a promise object" } }
+{ $description "Creates a promise to return a value. When forced this quotation is called with the given value on the stack and the result returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." } 
+{ $see-also force promise promise-with2 } ;
+
+HELP: promise-with2
+{ $values { "value1" "an object" } { "value2" "an object" } { "quot" "a quotation with stack effect ( value1 value2 -- X )" } { "promise" "a promise object" } }
+{ $description "Creates a promise to return a value. When forced this quotation is called with the given values on the stack and the result returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." } 
+{ $see-also force promise promise-with2 } ;
+
+HELP: force
+{ $values { "promise" "a promise object" } { "value" "a factor object" } }
+{ $description "Calls the quotation associated with the promise if it has not been called before, and returns the value. If the promise has been forced previously, returns the value from the previous call." } 
+{ $see-also promise promise-with promise-with2 } ;
+
+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 "USING: arrays sequences prettyprint promises ;" "IN: scratchpad" "LAZY: zeroes ( -- pair ) 0 zeroes 2array ;" "zeroes force second force first ." "0" }
+}
+{ $see-also force promise-with promise-with2 } ;
diff --git a/extra/promises/promises.factor b/extra/promises/promises.factor
new file mode 100755 (executable)
index 0000000..2126f0c
--- /dev/null
@@ -0,0 +1,45 @@
+! Copyright (C) 2004 Chris Double.
+! See http://factorcode.org/license.txt for BSD license.
+!
+! Updated by Matthew Willis, July 2006
+! Updated by Chris Double, September 2006
+
+USING: arrays kernel sequences math vectors arrays namespaces
+quotations parser effects inference words ;
+IN: promises
+
+TUPLE: promise quot forced? value ;
+
+: promise ( quot -- promise )
+  f f \ promise boa ;
+
+: promise-with ( value quot -- promise )
+  curry promise ;
+
+: promise-with2 ( value1 value2 quot -- promise )
+  2curry promise ;
+
+: force ( promise -- value )
+    #! Force the given promise leaving the value of calling the
+    #! promises quotation on the stack. Re-forcing the promise
+    #! will return the same value and not recall the quotation.
+    dup promise-forced? [
+        dup promise-quot call over set-promise-value
+        t over set-promise-forced?
+    ] unless
+    promise-value ;
+
+: stack-effect-in ( quot word -- n )
+  stack-effect [ ] [ infer ] ?if effect-in length ;
+
+: make-lazy-quot ( word quot -- quot )
+  [
+    dup ,
+    swap stack-effect-in \ curry <repetition> % 
+    \ promise ,
+  ] [ ] make ;
+
+: LAZY:
+  CREATE-WORD
+  dup parse-definition
+  make-lazy-quot define ; parsing
diff --git a/extra/promises/summary.txt b/extra/promises/summary.txt
new file mode 100644 (file)
index 0000000..d64fe20
--- /dev/null
@@ -0,0 +1 @@
+Lazy thunks
diff --git a/extra/promises/tags.txt b/extra/promises/tags.txt
new file mode 100644 (file)
index 0000000..f427429
--- /dev/null
@@ -0,0 +1 @@
+extensions
diff --git a/extra/random/blum-blum-shub/blum-blum-shub-tests.factor b/extra/random/blum-blum-shub/blum-blum-shub-tests.factor
new file mode 100644 (file)
index 0000000..2a1af53
--- /dev/null
@@ -0,0 +1,31 @@
+USING: kernel math tools.test namespaces random
+random.blum-blum-shub alien.c-types sequences splitting
+grouping ;
+IN: blum-blum-shub.tests
+
+[ 887708070 ] [
+    T{ blum-blum-shub f 590695557939 811977232793 } clone random-32*
+] unit-test
+
+
+[ 887708070 ] [
+    T{ blum-blum-shub f 590695557939 811977232793 } clone [
+        32 random-bits
+        little-endian? [ <uint> reverse *uint ] unless
+    ] with-random
+] unit-test
+
+[ 5726770047455156646 ] [
+    T{ blum-blum-shub f 590695557939 811977232793 } clone [
+        64 random-bits
+        little-endian? [ <ulonglong> 4 group [ reverse ] map concat *ulonglong ] unless
+    ] with-random
+] unit-test
+
+[ 3716213681 ]
+[
+    100 T{ blum-blum-shub f 200352954495 846054538649 } clone tuck [
+        random-32* drop
+    ] curry times
+    random-32*
+] unit-test
diff --git a/extra/random/blum-blum-shub/blum-blum-shub.factor b/extra/random/blum-blum-shub/blum-blum-shub.factor
new file mode 100755 (executable)
index 0000000..e609900
--- /dev/null
@@ -0,0 +1,27 @@
+USING: kernel math sequences namespaces
+math.miller-rabin combinators.lib
+math.functions accessors random ;
+IN: random.blum-blum-shub
+
+! Blum Blum Shub, n = pq, x_i+1 = x_i ^ 2 mod n
+! return low bit of x+1
+TUPLE: blum-blum-shub x n ;
+
+<PRIVATE
+
+: generate-bbs-primes ( numbits -- p q )
+    [ [ random-prime ] curry [ 4 mod 3 = ] generate ] dup bi ;
+
+: next-bbs-bit ( bbs -- bit )
+    [ [ x>> 2 ] [ n>> ] bi ^mod dup ] keep (>>x) 1 bitand ;
+
+PRIVATE>
+
+: <blum-blum-shub> ( numbits -- blum-blum-shub )
+    generate-bbs-primes *
+    [ find-relative-prime ] keep
+    blum-blum-shub boa ;
+
+M: blum-blum-shub random-32* ( bbs -- r )
+    0 32 rot
+    [ next-bbs-bit swap 1 shift bitor ] curry times ;