]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorEduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Thu, 8 Jan 2009 05:17:39 +0000 (23:17 -0600)
committerEduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Thu, 8 Jan 2009 05:17:39 +0000 (23:17 -0600)
51 files changed:
basis/bit-arrays/bit-arrays-tests.factor
basis/bit-arrays/bit-arrays.factor
basis/math/primes/authors.txt [new file with mode: 0644]
basis/math/primes/erato/authors.txt [new file with mode: 0644]
basis/math/primes/erato/erato-docs.factor [new file with mode: 0644]
basis/math/primes/erato/erato-tests.factor [new file with mode: 0644]
basis/math/primes/erato/erato.factor [new file with mode: 0644]
basis/math/primes/erato/summary.txt [new file with mode: 0644]
basis/math/primes/factors/authors.txt [new file with mode: 0644]
basis/math/primes/factors/factors-docs.factor [new file with mode: 0644]
basis/math/primes/factors/factors-tests.factor [new file with mode: 0644]
basis/math/primes/factors/factors.factor [new file with mode: 0644]
basis/math/primes/factors/summary.txt [new file with mode: 0644]
basis/math/primes/primes-docs.factor [new file with mode: 0644]
basis/math/primes/primes-tests.factor [new file with mode: 0644]
basis/math/primes/primes.factor [new file with mode: 0644]
basis/math/primes/summary.txt [new file with mode: 0644]
basis/unicode/case/case-docs.factor
basis/unicode/case/case.factor
basis/unicode/data/data-docs.factor [new file with mode: 0644]
basis/unicode/data/data.factor
basis/unicode/normalize/normalize-docs.factor
basis/unicode/normalize/normalize-tests.factor
basis/unicode/normalize/normalize.factor
core/kernel/kernel-docs.factor
extra/fuel/fuel.factor
extra/math/primes/authors.txt [deleted file]
extra/math/primes/erato/authors.txt [deleted file]
extra/math/primes/erato/erato-docs.factor [deleted file]
extra/math/primes/erato/erato-tests.factor [deleted file]
extra/math/primes/erato/erato.factor [deleted file]
extra/math/primes/erato/summary.txt [deleted file]
extra/math/primes/factors/authors.txt [deleted file]
extra/math/primes/factors/factors-docs.factor [deleted file]
extra/math/primes/factors/factors-tests.factor [deleted file]
extra/math/primes/factors/factors.factor [deleted file]
extra/math/primes/factors/summary.txt [deleted file]
extra/math/primes/lists/authors.txt [new file with mode: 0644]
extra/math/primes/lists/lists-docs.factor [new file with mode: 0644]
extra/math/primes/lists/lists-tests.factor [new file with mode: 0644]
extra/math/primes/lists/lists.factor [new file with mode: 0644]
extra/math/primes/lists/summary.txt [new file with mode: 0644]
extra/math/primes/primes-docs.factor [deleted file]
extra/math/primes/primes-tests.factor [deleted file]
extra/math/primes/primes.factor [deleted file]
extra/math/primes/summary.txt [deleted file]
extra/project-euler/007/007.factor
extra/project-euler/134/134.factor
misc/fuel/README
misc/fuel/fuel-mode.el
misc/fuel/fuel-refactor.el [new file with mode: 0644]

index 24c27fa15bcfa45042c53ec674f3ea8e59ffae60..1de49d353d7684fb3a306b36ebaf1fc89c06cc3b 100644 (file)
@@ -78,3 +78,5 @@ IN: bit-arrays.tests
 } bit-array>integer ] unit-test
 
 [ 49 ] [ 49 <bit-array> dup set-bits [ ] count ] unit-test
+
+[ HEX: 100 ] [ ?{ f f f f f f f f t } bit-array>integer ] unit-test
index 18796fbfed44fb1bc84cffa150381db84ee1f0c5..f1ba71ce1e02861bd79af83aeaff13b9639636b0 100644 (file)
@@ -83,7 +83,7 @@ M: bit-array byte-length length 7 + -3 shift ;
     ] if ;
 
 : bit-array>integer ( bit-array -- n )
-    0 swap underlying>> dup length [
+    0 swap underlying>> dup length <reversed> [
         alien-unsigned-1 swap 8 shift bitor
     ] with each ;
 
diff --git a/basis/math/primes/authors.txt b/basis/math/primes/authors.txt
new file mode 100644 (file)
index 0000000..f3b0233
--- /dev/null
@@ -0,0 +1 @@
+Samuel Tardieu
diff --git a/basis/math/primes/erato/authors.txt b/basis/math/primes/erato/authors.txt
new file mode 100644 (file)
index 0000000..f3b0233
--- /dev/null
@@ -0,0 +1 @@
+Samuel Tardieu
diff --git a/basis/math/primes/erato/erato-docs.factor b/basis/math/primes/erato/erato-docs.factor
new file mode 100644 (file)
index 0000000..b12ea45
--- /dev/null
@@ -0,0 +1,12 @@
+USING: help.markup help.syntax ;
+IN: math.primes.erato
+
+HELP: sieve
+{ $values { "n" "the greatest odd number to consider" } { "arr" "a bit array" } }
+{ $description "Return a bit array containing a primality bit for every odd number between 3 and " { $snippet "n" } " (inclusive). " { $snippet ">index" } " can be used to retrieve the index of an odd number to be tested." } ;
+
+HELP: >index
+{ $values { "n" "an odd number" } { "i" "the corresponding index" } }
+{ $description "Retrieve the index corresponding to the odd number on the stack." } ;
+
+{ sieve >index } related-words
diff --git a/basis/math/primes/erato/erato-tests.factor b/basis/math/primes/erato/erato-tests.factor
new file mode 100644 (file)
index 0000000..917824c
--- /dev/null
@@ -0,0 +1,3 @@
+USING: bit-arrays math.primes.erato tools.test ;
+
+[ ?{ t t t f t t f t t f t f f t } ] [ 29 sieve ] unit-test
diff --git a/basis/math/primes/erato/erato.factor b/basis/math/primes/erato/erato.factor
new file mode 100644 (file)
index 0000000..70a9c10
--- /dev/null
@@ -0,0 +1,25 @@
+! Copyright (C) 2009 Samuel Tardieu.
+! See http://factorcode.org/license.txt for BSD license.
+USING: bit-arrays kernel math math.functions math.ranges sequences ;
+IN: math.primes.erato
+
+: >index ( n -- i )
+    3 - 2 /i ; inline
+
+: index> ( i -- n )
+    2 * 3 + ; inline
+
+: mark-multiples ( i arr -- )
+    [ index> [ sq >index ] keep ] dip
+    [ length 1 - swap <range> f swap ] keep
+    [ set-nth ] curry with each ;
+
+: maybe-mark-multiples ( i arr -- )
+    2dup nth [ mark-multiples ] [ 2drop ] if ;
+
+: init-sieve ( n -- arr )
+    >index 1 + <bit-array> dup set-bits ;
+
+: sieve ( n -- arr )
+    [ init-sieve ] [ sqrt >index [0,b] ] bi
+    over [ maybe-mark-multiples ] curry each ; foldable
diff --git a/basis/math/primes/erato/summary.txt b/basis/math/primes/erato/summary.txt
new file mode 100644 (file)
index 0000000..6ecb893
--- /dev/null
@@ -0,0 +1 @@
+Eratosthene sieve
diff --git a/basis/math/primes/factors/authors.txt b/basis/math/primes/factors/authors.txt
new file mode 100644 (file)
index 0000000..f3b0233
--- /dev/null
@@ -0,0 +1 @@
+Samuel Tardieu
diff --git a/basis/math/primes/factors/factors-docs.factor b/basis/math/primes/factors/factors-docs.factor
new file mode 100644 (file)
index 0000000..f9fe4d5
--- /dev/null
@@ -0,0 +1,23 @@
+USING: help.markup help.syntax math sequences ;
+IN: math.primes.factors
+
+{ factors group-factors unique-factors } related-words
+
+HELP: factors
+{ $values { "n" "a positive integer" } { "seq" sequence } }
+{ $description { "Return an ordered list of a number's prime factors, possibly repeated." } }
+{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 factors ." "{ 2 2 3 5 5 }" } } ;
+
+HELP: group-factors
+{ $values { "n" "a positive integer" } { "seq" sequence } }
+{ $description { "Return a sequence of pairs representing each prime factor in the number and its corresponding power (multiplicity)." } }
+{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 group-factors ." "{ { 2 2 } { 3 1 } { 5 2 } }" } } ;
+
+HELP: unique-factors
+{ $values { "n" "a positive integer" } { "seq" sequence } }
+{ $description { "Return an ordered list of a number's unique prime factors." } }
+{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 unique-factors ." "{ 2 3 5 }" } } ;
+
+HELP: totient
+{ $values { "n" "a positive integer" } { "t" integer } }
+{ $description { "Return the number of integers between 1 and " { $snippet "n-1" } " that are relatively prime to " { $snippet "n" } "." } } ;
diff --git a/basis/math/primes/factors/factors-tests.factor b/basis/math/primes/factors/factors-tests.factor
new file mode 100644 (file)
index 0000000..f247683
--- /dev/null
@@ -0,0 +1,8 @@
+USING: math.primes.factors tools.test ;
+
+{ { 999983 999983 1000003 } } [ 999969000187000867 factors ] unit-test
+{ { } } [ -5 factors ] unit-test
+{ { { 999983 2 } { 1000003 1 } } } [ 999969000187000867 group-factors ] unit-test
+{ { 999983 1000003 } } [ 999969000187000867 unique-factors ] unit-test
+{ 999967000236000612 } [ 999969000187000867 totient ] unit-test
+{ 0 } [ 1 totient ] unit-test
diff --git a/basis/math/primes/factors/factors.factor b/basis/math/primes/factors/factors.factor
new file mode 100644 (file)
index 0000000..05d6b26
--- /dev/null
@@ -0,0 +1,29 @@
+! Copyright (C) 2007-2009 Samuel Tardieu.
+! See http://factorcode.org/license.txt for BSD license.
+USING: arrays combinators kernel make math math.primes sequences ;
+IN: math.primes.factors
+
+<PRIVATE
+
+: count-factor ( n d -- n' c )
+    [ 1 ] 2dip [ /i ] keep
+    [ dupd /mod zero? ] curry [ nip [ 1+ ] dip ] [ drop ] while
+    swap ;
+
+: write-factor ( n d -- n' d )
+    2dup mod zero? [ [ [ count-factor ] keep swap 2array , ] keep ] when ;
+
+PRIVATE>
+
+: group-factors ( n -- seq )
+    [ 2 [ over 1 > ] [ write-factor next-prime ] [ ] while 2drop ] { } make ;
+
+: unique-factors ( n -- seq ) group-factors [ first ] map ;
+
+: factors ( n -- seq ) group-factors [ first2 swap <array> ] map concat ;
+
+: totient ( n -- t )
+    {
+        { [ dup 2 < ] [ drop 0 ] }
+        [ dup unique-factors [ 1 [ 1- * ] reduce ] [ product ] bi / * ]
+    } cond ; foldable
diff --git a/basis/math/primes/factors/summary.txt b/basis/math/primes/factors/summary.txt
new file mode 100644 (file)
index 0000000..1440ddd
--- /dev/null
@@ -0,0 +1 @@
+Prime factors decomposition
diff --git a/basis/math/primes/primes-docs.factor b/basis/math/primes/primes-docs.factor
new file mode 100644 (file)
index 0000000..c7dbc95
--- /dev/null
@@ -0,0 +1,22 @@
+USING: help.markup help.syntax ;
+IN: math.primes
+
+{ next-prime prime? } related-words
+
+HELP: next-prime
+{ $values { "n" "an integer not smaller than 2" } { "p" "a prime number" } }
+{ $description "Return the next prime number greater than " { $snippet "n" } "." } ;
+
+HELP: prime?
+{ $values { "n" "an integer" } { "?" "a boolean" } }
+{ $description "Test if an integer is a prime number." } ;
+
+{ primes-upto primes-between } related-words
+
+HELP: primes-upto
+{ $values { "n" "an integer" } { "seq" "a sequence" } }
+{ $description "Return a sequence containing all the prime numbers smaller or equal to " { $snippet "n" } "." } ;
+
+HELP: primes-between
+{ $values { "low" "an integer" } { "high" "an integer" } { "seq" "a sequence" } }
+{ $description "Return a sequence containing all the prime numbers between " { $snippet "low" } " and " { $snippet "high" } "." } ;
diff --git a/basis/math/primes/primes-tests.factor b/basis/math/primes/primes-tests.factor
new file mode 100644 (file)
index 0000000..db73839
--- /dev/null
@@ -0,0 +1,9 @@
+USING: arrays math.primes tools.test ;
+
+{ 1237 } [ 1234 next-prime ] unit-test
+{ f t } [ 1234 prime? 1237 prime? ] unit-test
+{ { 2 3 5 7 } } [ 10 primes-upto >array ] unit-test
+{ { 999983 1000003 } } [ 999982 1000010 primes-between >array ] unit-test
+
+{ { 4999963 4999999 5000011 5000077 5000081 } }
+[ 4999962 5000082 primes-between >array ] unit-test
diff --git a/basis/math/primes/primes.factor b/basis/math/primes/primes.factor
new file mode 100644 (file)
index 0000000..807ebf0
--- /dev/null
@@ -0,0 +1,33 @@
+! Copyright (C) 2007-2009 Samuel Tardieu.
+! See http://factorcode.org/license.txt for BSD license.
+USING: combinators kernel math math.functions math.miller-rabin
+math.order math.primes.erato math.ranges sequences ;
+IN: math.primes
+
+<PRIVATE
+
+: look-in-bitmap ( n -- ? ) >index 4999999 sieve nth ;
+
+: really-prime? ( n -- ? )
+    dup 5000000 < [ look-in-bitmap ] [ miller-rabin ] if ; foldable
+
+PRIVATE>
+
+: prime? ( n -- ? )
+    {
+        { [ dup 2 < ] [ drop f ] }
+        { [ dup even? ] [ 2 = ] }
+        [ really-prime? ]
+    } cond ; foldable
+
+: next-prime ( n -- p )
+    next-odd [ dup really-prime? ] [ 2 + ] [ ] until ; foldable
+
+: primes-between ( low high -- seq )
+    [ dup 3 max dup even? [ 1 + ] when ] dip
+    2 <range> [ prime? ] filter
+    swap 3 < [ 2 prefix ] when ;
+
+: primes-upto ( n -- seq ) 2 swap primes-between ;
+
+: coprime? ( a b -- ? ) gcd nip 1 = ; foldable
diff --git a/basis/math/primes/summary.txt b/basis/math/primes/summary.txt
new file mode 100644 (file)
index 0000000..41b4197
--- /dev/null
@@ -0,0 +1,2 @@
+Prime numbers test and generation
+
index a5790f9a545f6f261ddd41434af2597748e7709b..86b791ed81bfa83de796ead0b8f30c73d2b23b0c 100644 (file)
@@ -1,4 +1,4 @@
-USING: help.syntax help.markup ;
+USING: help.syntax help.markup strings ;
 IN: unicode.case
 
 ABOUT: "unicode.case"
@@ -9,6 +9,10 @@ ARTICLE: "unicode.case" "Case mapping"
 { $subsection >lower }
 { $subsection >title }
 { $subsection >case-fold }
+"There are analogous routines which operate on individual code points, but these should " { $emphasis "not be used" } " in general as they have slightly different behavior. In some cases, for example, they do not perform the case operation, as a single code point must expand to more than one."
+{ $subsection ch>upper }
+{ $subsection ch>lower }
+{ $subsection ch>title }
 "To test if a string is in a given case:"
 { $subsection upper? }
 { $subsection lower? }
@@ -16,4 +20,51 @@ ARTICLE: "unicode.case" "Case mapping"
 { $subsection case-fold? }
 "For certain languages (Turkish, Azeri, Lithuanian), case mapping is dependent on locale; To change this, set the following variable to the ISO-639-1 code for your language:"
 { $subsection locale }
-"This is unnecessary for most languages." ;
+"This is unnecessary for most locales." ;
+
+HELP: >upper
+{ $values { "string" string } { "upper" string } }
+{ $description "Converts a string to upper case." } ;
+
+HELP: >lower
+{ $values { "string" string } { "lower" string } }
+{ $description "Converts a string to lower case." } ;
+
+HELP: >title
+{ $values { "string" string } { "title" string } }
+{ $description "Converts a string to title case." } ;
+
+HELP: >case-fold
+{ $values { "string" string } { "case-fold" string } }
+{ $description "Converts a string to case-folded form." } ;
+
+HELP: upper?
+{ $values { "string" string } { "?" "a boolean" } }
+{ $description "Tests if a string is in upper case." } ;
+
+HELP: lower?
+{ $values { "string" string } { "?" "a boolean" } }
+{ $description "Tests if a string is in lower case." } ;
+
+HELP: title?
+{ $values { "string" string } { "?" "a boolean" } }
+{ $description "Tests if a string is in title case." } ;
+
+HELP: case-fold?
+{ $values { "string" string } { "?" "a boolean" } }
+{ $description "Tests if a string is in case-folded form." } ;
+
+HELP: ch>lower
+{ $values { "ch" "a code point" } { "lower" "a code point" } }
+{ $description "Converts a code point to lower case." }
+{ $warning "Don't use this unless you know what you're doing! " { $code ">lower" } " is not the same as " { $code "[ ch>lower ] map" } "." } ;
+
+HELP: ch>upper
+{ $values { "ch" "a code point" } { "upper" "a code point" } }
+{ $description "Converts a code point to upper case." }
+{ $warning "Don't use this unless you know what you're doing! " { $code ">upper" } " is not the same as " { $code "[ ch>upper ] map" } "." } ;
+
+HELP: ch>title
+{ $values { "ch" "a code point" } { "title" "a code point" } }
+{ $description "Converts a code point to title case." }
+{ $warning "Don't use this unless you know what you're doing! " { $code ">title" } " is not the same as " { $code "[ ch>title ] map" } "." } ;
index 42fd13fc97e45535a713827f5a824a22784daf8d..7e61831f36d0ca536839e9ee7205f4affbf72c18 100644 (file)
@@ -7,12 +7,14 @@ IN: unicode.case
 
 <PRIVATE
 : at-default ( key assoc -- value/key ) [ at ] [ drop ] 2bi or ;
+PRIVATE>
 
 : ch>lower ( ch -- lower ) simple-lower at-default ;
 : ch>upper ( ch -- upper ) simple-upper at-default ;
 : ch>title ( ch -- title ) simple-title at-default ;
-PRIVATE>
+
 SYMBOL: locale ! Just casing locale, or overall?
+
 <PRIVATE
 : i-dot? ( -- ? )
     locale get { "tr" "az" } member? ;
diff --git a/basis/unicode/data/data-docs.factor b/basis/unicode/data/data-docs.factor
new file mode 100644 (file)
index 0000000..a918728
--- /dev/null
@@ -0,0 +1,51 @@
+USING: help.syntax help.markup strings ;
+IN: unicode.data
+
+ABOUT: "unicode.data"
+
+ARTICLE: "unicode.data" "Unicode data tables"
+"The " { $vocab-link "unicode.data" "unicode.data" } " vocabulary contains core Unicode data tables and code for parsing this from files."
+{ $subsection load-script }
+{ $subsection canonical-entry }
+{ $subsection combine-chars }
+{ $subsection combining-class }
+{ $subsection non-starter? }
+{ $subsection name>char }
+{ $subsection char>name }
+{ $subsection property? } ;
+
+HELP: load-script
+{ $value { "filename" string } { "table" "an interval map" } }
+{ $description "This loads a file that looks like Script.txt in the Unicode Character Database and converts it into an efficient interval map, where the keys are characters and the values are strings for the properties." } ;
+
+HELP: canonical-entry
+{ $value { "char" "a code point" } { "seq" string } }
+{ $description "Finds the canonical decomposition (NFD) for a code point" } ;
+
+HELP: combine-chars
+{ $value { "a" "a code point" } { "b" "a code point" } { "char/f" "a code point" } }
+{ $description "If a followed by b can be combined in NFC, this returns the code point of their combination." } ;
+
+HELP: compatibility-entry
+{ $value { "char" "a code point" } { "seq" string } }
+{ $description "This returns the compatibility decomposition (NFKD) for a code point" } ;
+
+HELP: combining-class
+{ $value { "char" "a code point" } { "n" "an integer" } }
+{ $description "Finds the combining class of a code point." } ;
+
+HELP: non-starter?
+{ $value { "char" "a code point" } { "?" "a boolean" } }
+{ $description "Returns true if the code point has a combining class." } ;
+
+HELP: char>name
+{ $value { "char" "a code point" } { "name" string } }
+{ $description "Looks up the name of a given code point. Warning: this is not optimized for speed, to save space." } ;
+
+HELP: name>char
+{ $value { "name" string } { "char" "a code point" } }
+{ $description "Looks up the code point corresponding to a given name." } ;
+
+HELP: property?
+{ $value { "char" "a code point" } { "property" string } { "?" "a boolean" } }
+{ $description "Tests whether the code point is listed under the given property in PropList.txt in the Unicode Character Database." } ;
index 3e19c5c30df93478499e78ff0421ccbf5310d407..8f99b6c160006500a949e41a8cc524c16b55887a 100644 (file)
@@ -28,10 +28,6 @@ VALUE: properties
 : char>name ( char -- string ) name-map value-at ;
 : property? ( char property -- ? ) properties at interval-key? ;
 
-! Convenience functions
-: ?between? ( n/f from to -- ? )
-    pick [ between? ] [ 3drop f ] if ;
-
 ! Loading data from UnicodeData.txt
 
 : split-; ( line -- array )
@@ -206,9 +202,9 @@ SYMBOL: interned
 : expand-ranges ( assoc -- interval-map )
     [
         [
-            CHAR: . pick member? [
-                swap ".." split1 [ hex> ] bi@ 2array
-            ] [ swap hex> ] if range,
+            swap CHAR: . over member? [
+                ".." split1 [ hex> ] bi@ 2array
+            ] [ hex> ] if range,
         ] assoc-each
     ] { } make <interval-map> ;
 
index 423332fb6e9d9ac22f5173fa7ecbfeb8b0b15308..65f50ab0aeb085ece84f507eeeceb58a7d16d3a0 100644 (file)
@@ -8,9 +8,7 @@ ARTICLE: "unicode.normalize" "Unicode normalization"
 { $subsection nfc }
 { $subsection nfd }
 { $subsection nfkc }
-{ $subsection nfkd }
-"If two strings in a normalization form are appended, the result may not be in that normalization form still. To append two strings in NFD and make sure the result is in NFD, the following procedure is supplied:"
-{ $subsection string-append } ;
+{ $subsection nfkd } ;
 
 HELP: nfc
 { $values { "string" string } { "nfc" "a string in NFC" } }
@@ -27,7 +25,3 @@ HELP: nfkc
 HELP: nfkd
 { $values { "string" string } { "nfc" "a string in NFKD" } }
 { $description "Converts a string to Normalization Form KD" } ;
-
-HELP: string-append
-{ $values { "s1" "a string in NFD" } { "s2" "a string in NFD" } { "string" "a string in NFD" } }
-{ $description "Appends two strings, putting the result in NFD." } ;
index 966238953148a9e1ae8425d580db00091a10a440..25d5ce365c4efcf6ea4f8cde1c2f8d5e6b212b96 100644 (file)
@@ -1,6 +1,6 @@
 USING: unicode.normalize kernel tools.test sequences
 unicode.data io.encodings.utf8 io.files splitting math.parser
-locals math quotations assocs combinators ;
+locals math quotations assocs combinators unicode.normalize.private ;
 IN: unicode.normalize.tests
 
 [ "ab\u000323\u000302cd" ] [ "ab\u000302" "\u000323cd" string-append ] unit-test
index eacdb2724abec5a43bf0782d17fdee440f268010..f13eb0759498ed110a5702a51bebeaba7d6f72e4 100644 (file)
@@ -1,21 +1,24 @@
 ! Copyright (C) 2008 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: sequences namespaces make unicode.data kernel math arrays
-locals sorting.insertion accessors assocs ;
+locals sorting.insertion accessors assocs math.order ;
 IN: unicode.normalize
 
 <PRIVATE
 ! Conjoining Jamo behavior
 
-: hangul-base HEX: ac00 ; inline
-: hangul-end HEX: D7AF ; inline
-: initial-base HEX: 1100 ; inline
-: medial-base HEX: 1161 ; inline
-: final-base HEX: 11a7 ; inline
+CONSTANT: hangul-base HEX: ac00
+CONSTANT: hangul-end HEX: D7AF
+CONSTANT: initial-base HEX: 1100
+CONSTANT: medial-base HEX: 1161
+CONSTANT: final-base HEX: 11a7
 
-: initial-count 19 ; inline
-: medial-count 21 ; inline
-: final-count 28 ; inline
+CONSTANT: initial-count 19
+CONSTANT: medial-count 21
+CONSTANT: final-count 28
+
+: ?between? ( n/f from to -- ? )
+    pick [ between? ] [ 3drop f ] if ;
 
 : hangul? ( ch -- ? ) hangul-base hangul-end ?between? ;
 : jamo? ( ch -- ? ) HEX: 1100 HEX: 11FF ?between? ;
@@ -84,8 +87,6 @@ PRIVATE>
     [ compatibility-entry ] decompose ;
 
 : string-append ( s1 s2 -- string )
-    ! This could be more optimized,
-    ! but in practice, it'll almost always just be append
     [ append ] keep
     0 over ?nth non-starter?
     [ length dupd reorder-back ] [ drop ] if ;
index bac40487061ae44339ecbe3eadb20dc4e018970c..7a53ff51722709fd0c083f1d344a1a11ce3e9697 100644 (file)
@@ -691,11 +691,10 @@ HELP: assert=
 { $values { "a" object } { "b" object } }
 { $description "Throws an " { $link assert } " error if " { $snippet "a" } " does not equal " { $snippet "b" } "." } ;
 
-
 ARTICLE: "shuffle-words" "Shuffle words"
 "Shuffle words rearrange items at the top of the data stack. They control the flow of data between words that perform actions."
 $nl
-"The " { $link "cleave-combinators" } " and " { $link "spread-combinators" } " are closely related to shuffle words and should be used instead where possible because they can result in clearer code; also, see the advice in " { $link "cookbook-philosophy" } "."
+"The " { $link "cleave-combinators" } ", " { $link "spread-combinators" } " and " { $link "apply-combinators" } " are closely related to shuffle words and should be used instead where possible because they can result in clearer code; also, see the advice in " { $link "cookbook-philosophy" } "."
 $nl
 "Removing stack elements:"
 { $subsection drop }
index 60420b3c39e0005582ca3e8662322c2361dc0290..becbf2161a22553c78a5155f32507e19b6a9947f 100644 (file)
@@ -269,7 +269,7 @@ MEMO: fuel-article-title ( name -- title/f )
     help-path [ dup article-title swap 2array ] map ; inline
 
 : (fuel-word-help) ( word -- element )
-    dup \ article swap article-title rot
+    \ article swap dup article-title swap
     [
         {
             [ fuel-parent-topics [ \ $doc-path prefix , ] unless-empty ]
diff --git a/extra/math/primes/authors.txt b/extra/math/primes/authors.txt
deleted file mode 100644 (file)
index f3b0233..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Samuel Tardieu
diff --git a/extra/math/primes/erato/authors.txt b/extra/math/primes/erato/authors.txt
deleted file mode 100644 (file)
index f3b0233..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Samuel Tardieu
diff --git a/extra/math/primes/erato/erato-docs.factor b/extra/math/primes/erato/erato-docs.factor
deleted file mode 100644 (file)
index b12ea45..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-USING: help.markup help.syntax ;
-IN: math.primes.erato
-
-HELP: sieve
-{ $values { "n" "the greatest odd number to consider" } { "arr" "a bit array" } }
-{ $description "Return a bit array containing a primality bit for every odd number between 3 and " { $snippet "n" } " (inclusive). " { $snippet ">index" } " can be used to retrieve the index of an odd number to be tested." } ;
-
-HELP: >index
-{ $values { "n" "an odd number" } { "i" "the corresponding index" } }
-{ $description "Retrieve the index corresponding to the odd number on the stack." } ;
-
-{ sieve >index } related-words
diff --git a/extra/math/primes/erato/erato-tests.factor b/extra/math/primes/erato/erato-tests.factor
deleted file mode 100644 (file)
index 917824c..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-USING: bit-arrays math.primes.erato tools.test ;
-
-[ ?{ t t t f t t f t t f t f f t } ] [ 29 sieve ] unit-test
diff --git a/extra/math/primes/erato/erato.factor b/extra/math/primes/erato/erato.factor
deleted file mode 100644 (file)
index 70a9c10..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-! Copyright (C) 2009 Samuel Tardieu.
-! See http://factorcode.org/license.txt for BSD license.
-USING: bit-arrays kernel math math.functions math.ranges sequences ;
-IN: math.primes.erato
-
-: >index ( n -- i )
-    3 - 2 /i ; inline
-
-: index> ( i -- n )
-    2 * 3 + ; inline
-
-: mark-multiples ( i arr -- )
-    [ index> [ sq >index ] keep ] dip
-    [ length 1 - swap <range> f swap ] keep
-    [ set-nth ] curry with each ;
-
-: maybe-mark-multiples ( i arr -- )
-    2dup nth [ mark-multiples ] [ 2drop ] if ;
-
-: init-sieve ( n -- arr )
-    >index 1 + <bit-array> dup set-bits ;
-
-: sieve ( n -- arr )
-    [ init-sieve ] [ sqrt >index [0,b] ] bi
-    over [ maybe-mark-multiples ] curry each ; foldable
diff --git a/extra/math/primes/erato/summary.txt b/extra/math/primes/erato/summary.txt
deleted file mode 100644 (file)
index 6ecb893..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Eratosthene sieve
diff --git a/extra/math/primes/factors/authors.txt b/extra/math/primes/factors/authors.txt
deleted file mode 100644 (file)
index f3b0233..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Samuel Tardieu
diff --git a/extra/math/primes/factors/factors-docs.factor b/extra/math/primes/factors/factors-docs.factor
deleted file mode 100644 (file)
index f9fe4d5..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-USING: help.markup help.syntax math sequences ;
-IN: math.primes.factors
-
-{ factors group-factors unique-factors } related-words
-
-HELP: factors
-{ $values { "n" "a positive integer" } { "seq" sequence } }
-{ $description { "Return an ordered list of a number's prime factors, possibly repeated." } }
-{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 factors ." "{ 2 2 3 5 5 }" } } ;
-
-HELP: group-factors
-{ $values { "n" "a positive integer" } { "seq" sequence } }
-{ $description { "Return a sequence of pairs representing each prime factor in the number and its corresponding power (multiplicity)." } }
-{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 group-factors ." "{ { 2 2 } { 3 1 } { 5 2 } }" } } ;
-
-HELP: unique-factors
-{ $values { "n" "a positive integer" } { "seq" sequence } }
-{ $description { "Return an ordered list of a number's unique prime factors." } }
-{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 unique-factors ." "{ 2 3 5 }" } } ;
-
-HELP: totient
-{ $values { "n" "a positive integer" } { "t" integer } }
-{ $description { "Return the number of integers between 1 and " { $snippet "n-1" } " that are relatively prime to " { $snippet "n" } "." } } ;
diff --git a/extra/math/primes/factors/factors-tests.factor b/extra/math/primes/factors/factors-tests.factor
deleted file mode 100644 (file)
index f247683..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-USING: math.primes.factors tools.test ;
-
-{ { 999983 999983 1000003 } } [ 999969000187000867 factors ] unit-test
-{ { } } [ -5 factors ] unit-test
-{ { { 999983 2 } { 1000003 1 } } } [ 999969000187000867 group-factors ] unit-test
-{ { 999983 1000003 } } [ 999969000187000867 unique-factors ] unit-test
-{ 999967000236000612 } [ 999969000187000867 totient ] unit-test
-{ 0 } [ 1 totient ] unit-test
diff --git a/extra/math/primes/factors/factors.factor b/extra/math/primes/factors/factors.factor
deleted file mode 100644 (file)
index 282c46c..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-! Copyright (C) 2007-2009 Samuel Tardieu.
-! See http://factorcode.org/license.txt for BSD license.
-USING: arrays kernel lists make math math.primes sequences ;
-IN: math.primes.factors
-
-<PRIVATE
-
-: count-factor ( n d -- n' c )
-    0 [ [ 2dup mod zero? ] dip swap ] [ [ [ / ] keep ] dip 1+ ] [ ] while nip ;
-
-: (factor) ( n d -- n' ) dup [ , ] curry [ count-factor ] dip times ;
-
-: (count) ( n d -- n' )
-    dup [ swap 2array , ] curry
-    [ count-factor dup zero? [ drop ] ] dip if ;
-
-: (unique) ( n d -- n' )
-    dup [ , ] curry [ count-factor zero? ] dip unless ;
-
-: (factors) ( quot list n -- )
-    dup 1 > [
-        swap uncons swap [ pick call ] dip swap (factors)
-    ] [ 3drop ] if ; inline recursive
-
-: decompose ( n quot -- seq ) [ lprimes rot (factors) ] { } make ; inline
-
-PRIVATE>
-
-: factors ( n -- seq ) [ (factor) ] decompose ; flushable
-
-: group-factors ( n -- seq ) [ (count) ] decompose ; flushable
-
-: unique-factors ( n -- seq ) [ (unique) ] decompose ; flushable
-
-: totient ( n -- t )
-    dup 2 < [
-        drop 0
-    ] [
-        dup unique-factors [ 1 [ 1- * ] reduce ] [ product ] bi / *
-    ] if ; foldable
diff --git a/extra/math/primes/factors/summary.txt b/extra/math/primes/factors/summary.txt
deleted file mode 100644 (file)
index 1440ddd..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Prime factors decomposition
diff --git a/extra/math/primes/lists/authors.txt b/extra/math/primes/lists/authors.txt
new file mode 100644 (file)
index 0000000..f3b0233
--- /dev/null
@@ -0,0 +1 @@
+Samuel Tardieu
diff --git a/extra/math/primes/lists/lists-docs.factor b/extra/math/primes/lists/lists-docs.factor
new file mode 100644 (file)
index 0000000..ecab12c
--- /dev/null
@@ -0,0 +1,10 @@
+USING: help.markup help.syntax ;
+IN: math.primes.lists
+
+HELP: lprimes
+{ $values { "list" "a lazy list" } }
+{ $description "Return a sorted list containing all the prime numbers." } ;
+
+HELP: lprimes-from
+{ $values { "n" "an integer" } { "list" "a lazy list" } }
+{ $description "Return a sorted list containing all the prime numbers greater or equal to " { $snippet "n" } "." } ;
diff --git a/extra/math/primes/lists/lists-tests.factor b/extra/math/primes/lists/lists-tests.factor
new file mode 100644 (file)
index 0000000..3bd7d70
--- /dev/null
@@ -0,0 +1,6 @@
+USING: lists.lazy math.primes.lists tools.test ;
+
+{ { 2 3 5 7 11 13 17 19 23 29 } } [ 10 lprimes ltake list>array ] unit-test
+{ { 101 103 107 109 113 } } [ 5 100 lprimes-from ltake list>array ] unit-test
+{ { 1000117 1000121 } } [ 2 1000100 lprimes-from ltake list>array ] unit-test
+{ { 999983 1000003 } } [ 2 999982 lprimes-from ltake list>array ] unit-test
diff --git a/extra/math/primes/lists/lists.factor b/extra/math/primes/lists/lists.factor
new file mode 100644 (file)
index 0000000..13f314f
--- /dev/null
@@ -0,0 +1,9 @@
+! Copyright (C) 2007-2009 Samuel Tardieu.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel lists.lazy math math.primes ;
+IN: math.primes.lists
+
+: lprimes ( -- list ) 2 [ next-prime ] lfrom-by ;
+
+: lprimes-from ( n -- list )
+    dup 3 < [ drop lprimes ] [ 1- next-prime [ next-prime ] lfrom-by ] if ;
diff --git a/extra/math/primes/lists/summary.txt b/extra/math/primes/lists/summary.txt
new file mode 100644 (file)
index 0000000..39a780a
--- /dev/null
@@ -0,0 +1 @@
+Infinite stream of prime numbers through lazy lists
diff --git a/extra/math/primes/primes-docs.factor b/extra/math/primes/primes-docs.factor
deleted file mode 100644 (file)
index 516b081..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-USING: help.markup help.syntax ;
-IN: math.primes
-
-{ next-prime prime? } related-words
-
-HELP: next-prime
-{ $values { "n" "an integer not smaller than 2" } { "p" "a prime number" } }
-{ $description "Return the next prime number greater than " { $snippet "n" } "." } ;
-
-HELP: prime?
-{ $values { "n" "an integer" } { "?" "a boolean" } }
-{ $description "Test if an integer is a prime number." } ;
-
-{ lprimes lprimes-from primes-upto primes-between } related-words
-
-HELP: lprimes
-{ $values { "list" "a lazy list" } }
-{ $description "Return a sorted list containing all the prime numbers." } ;
-
-HELP: lprimes-from
-{ $values { "n" "an integer" } { "list" "a lazy list" } }
-{ $description "Return a sorted list containing all the prime numbers greater or equal to " { $snippet "n" } "." } ;
-
-HELP: primes-upto
-{ $values { "n" "an integer" } { "seq" "a sequence" } }
-{ $description "Return a sequence containing all the prime numbers smaller or equal to " { $snippet "n" } "." } ;
-
-HELP: primes-between
-{ $values { "low" "an integer" } { "high" "an integer" } { "seq" "a sequence" } }
-{ $description "Return a sequence containing all the prime numbers between " { $snippet "low" } " and " { $snippet "high" } "." } ;
diff --git a/extra/math/primes/primes-tests.factor b/extra/math/primes/primes-tests.factor
deleted file mode 100644 (file)
index b0b2528..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-USING: arrays math.primes tools.test lists.lazy ;
-
-{ 1237 } [ 1234 next-prime ] unit-test
-{ f t } [ 1234 prime? 1237 prime? ] unit-test
-{ { 2 3 5 7 11 13 17 19 23 29 } } [ 10 lprimes ltake list>array ] unit-test
-{ { 101 103 107 109 113 } } [ 5 100 lprimes-from ltake list>array ] unit-test
-{ { 1000117 1000121 } } [ 2 1000100 lprimes-from ltake list>array ] unit-test
-{ { 999983 1000003 } } [ 2 999982 lprimes-from ltake list>array ] unit-test
-{ { 2 3 5 7 } } [ 10 primes-upto >array ] unit-test
-{ { 999983 1000003 } } [ 999982 1000010 primes-between >array ] unit-test
-
-{ { 4999963 4999999 5000011 5000077 5000081 } }
-[ 4999962 5000082 primes-between >array ]
-unit-test
diff --git a/extra/math/primes/primes.factor b/extra/math/primes/primes.factor
deleted file mode 100644 (file)
index fa42d73..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-! Copyright (C) 2007 Samuel Tardieu.
-! See http://factorcode.org/license.txt for BSD license.
-USING: combinators kernel lists.lazy math math.functions
-math.miller-rabin math.order math.primes.erato math.ranges sequences ;
-IN: math.primes
-
-<PRIVATE
-
-: look-in-bitmap ( n -- ? ) >index 4999999 sieve nth ;
-
-: really-prime? ( n -- ? )
-    dup 5000000 < [ look-in-bitmap ] [ miller-rabin ] if ; foldable
-
-PRIVATE>
-
-: prime? ( n -- ? )
-    {
-        { [ dup 2 < ] [ drop f ] }
-        { [ dup even? ] [ 2 = ] }
-        [ really-prime? ]
-    } cond ; foldable
-
-: next-prime ( n -- p )
-    next-odd [ dup really-prime? ] [ 2 + ] [ ] until ; foldable
-
-: lprimes ( -- list ) 2 [ next-prime ] lfrom-by ;
-
-: lprimes-from ( n -- list )
-    dup 3 < [ drop lprimes ] [ 1- next-prime [ next-prime ] lfrom-by ] if ;
-
-: primes-between ( low high -- seq )
-    [ dup 3 max dup even? [ 1 + ] when ] dip
-    2 <range> [ prime? ] filter
-    swap 3 < [ 2 prefix ] when ;
-
-: primes-upto ( n -- seq ) 2 swap primes-between ;
-
-: coprime? ( a b -- ? ) gcd nip 1 = ; foldable
diff --git a/extra/math/primes/summary.txt b/extra/math/primes/summary.txt
deleted file mode 100644 (file)
index 41b4197..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-Prime numbers test and generation
-
index f2b659fe94d32f9e21cc7a35526c519f03f9347e..f40108e4d7105ff2b98453d4a07c2ba7da61f978 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: lists math math.primes ;
+USING: lists math math.primes.lists ;
 IN: project-euler.007
 
 ! http://projecteuler.net/index.php?section=problems&id=7
index 7bdf17ef684260c36cc65e0d64f5feac11811aff..e00e86865d9a1a99d2b4a863a3615b7d9d6b57b3 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2007 Samuel Tardieu.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays kernel lists lists.lazy math.algebra math math.functions
-    math.order math.primes math.ranges project-euler.common sequences ;
+    math.order math.primes.lists math.ranges project-euler.common sequences ;
 IN: project-euler.134
 
 ! http://projecteuler.net/index.php?section=problems&id=134
index 14a9ca8b5d4656071d70b0625046efa443155176..f5d366a22e745d6a60316bd7b42fb31da84ef24c 100644 (file)
@@ -74,6 +74,8 @@ beast.
     - C-cM-<, C-cC-d< : show callers of word at point
     - C-cM->, C-cC-d> : show callees of word at point
 
+    - C-cC-xw : extract region as a separate word
+
 *** In the listener:
 
     - TAB : complete word at point
index 651cc323d0abb95daf5611ccc3c677679b7015a1..c1abcf414b6cdcb3aaa1d3ed46f0de57358edfae 100644 (file)
@@ -21,6 +21,7 @@
 (require 'fuel-eval)
 (require 'fuel-help)
 (require 'fuel-xref)
+(require 'fuel-refactor)
 (require 'fuel-stack)
 (require 'fuel-autodoc)
 (require 'fuel-font-lock)
@@ -224,6 +225,8 @@ interacting with a factor listener is at your disposal.
 (fuel-mode--key ?e ?w 'fuel-edit-word)
 (fuel-mode--key ?e ?x 'fuel-eval-definition)
 
+(fuel-mode--key ?x ?w 'fuel-refactor-extract-word)
+
 (fuel-mode--key ?d ?> 'fuel-show-callees)
 (fuel-mode--key ?d ?< 'fuel-show-callers)
 (fuel-mode--key ?d ?a 'fuel-autodoc-mode)
diff --git a/misc/fuel/fuel-refactor.el b/misc/fuel/fuel-refactor.el
new file mode 100644 (file)
index 0000000..547da19
--- /dev/null
@@ -0,0 +1,57 @@
+;;; fuel-refactor.el -- code refactoring support
+
+;; Copyright (C) 2009 Jose Antonio Ortega Ruiz
+;; See http://factorcode.org/license.txt for BSD license.
+
+;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
+;; Keywords: languages, fuel, factor
+;; Start date: Thu Jan 08, 2009 00:57
+
+;;; Comentary:
+
+;; Utilities performing refactoring on factor code.
+
+;;; Code:
+
+(require 'fuel-stack)
+(require 'fuel-syntax)
+(require 'fuel-base)
+
+\f
+;;; Extract word:
+
+(defun fuel-refactor-extract-word (begin end)
+  "Extracts current region as a separate word."
+  (interactive "r")
+  (let* ((word (read-string "New word name: "))
+         (begin (save-excursion
+                  (goto-char begin)
+                  (when (zerop (skip-syntax-backward "w"))
+                    (skip-syntax-forward "-"))
+                  (point)))
+         (end (save-excursion
+                (goto-char end)
+                (skip-syntax-forward "w")
+                (point)))
+         (code (buffer-substring begin end))
+         (code-str (fuel--region-to-string begin end))
+         (stack-effect (or (fuel-stack--infer-effect code-str)
+                           (read-string "Stack effect: "))))
+    (goto-char begin)
+    (delete-region begin end)
+    (insert word)
+    (indent-region begin (point))
+    (set-mark (point))
+    (fuel-syntax--beginning-of-defun)
+    (open-line 1)
+    (let ((start (point)))
+      (insert ": " word " " stack-effect "\n" code " ;\n")
+      (indent-region start (point))
+      (move-overlay fuel-stack--overlay start (point))
+      (goto-char (mark))
+      (sit-for fuel-stack-highlight-period)
+      (delete-overlay fuel-stack--overlay))))
+
+\f
+(provide 'fuel-refactor)
+;;; fuel-refactor.el ends here