]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 9 Dec 2008 14:50:07 +0000 (06:50 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 9 Dec 2008 14:50:07 +0000 (06:50 -0800)
basis/db/db-docs.factor
extra/crypto/barrett/barrett-tests.factor
extra/math/binpack/authors.txt [new file with mode: 0644]
extra/math/binpack/binpack-docs.factor [new file with mode: 0644]
extra/math/binpack/binpack-tests.factor [new file with mode: 0644]
extra/math/binpack/binpack.factor [new file with mode: 0644]
extra/math/binpack/summary.txt [new file with mode: 0644]
extra/time/authors.txt [new file with mode: 0644]
extra/time/time-docs.factor [new file with mode: 0644]
extra/time/time-tests.factor [new file with mode: 0644]
extra/time/time.factor [new file with mode: 0644]

index 52dc389fe64d592717419cc7198636596c66f3b5..8173ff6a5b137ac24122a582d4ad61cf3e815b99 100644 (file)
@@ -229,7 +229,7 @@ ARTICLE: "db-protocol" "Low-level database protocol"
 { $subsection db-open }
 "Closing a database:"
 { $subsection db-close }
-"Creating tatements:"
+"Creating statements:"
 { $subsection <simple-statement> }
 { $subsection <prepared-statement> }
 "Using statements with the database:"
index 01163f730f6347439b60213fbebdb036e0ed415c..13dae69dce0303b055feb4712c12756a92adc8ca 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 DoDoug Coleman.
+! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: crypto.barrett kernel math namespaces tools.test ;
 IN: crypto.barrett.tests
diff --git a/extra/math/binpack/authors.txt b/extra/math/binpack/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/math/binpack/binpack-docs.factor b/extra/math/binpack/binpack-docs.factor
new file mode 100644 (file)
index 0000000..36a29c7
--- /dev/null
@@ -0,0 +1,19 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: help.syntax help.markup kernel assocs sequences quotations ;
+
+IN: math.binpack 
+
+HELP: binpack
+{ $values { "assoc" assoc } { "n" "number of bins" } { "bins" "packed bins" } }
+{ $description "Packs the (key, value) pairs into the specified number of bins, using the value as a weight." } ;
+
+HELP: binpack*
+{ $values { "items" sequence } { "n" "number of bins" } { "bins" "packed bins" } } 
+{ $description "Packs a sequence of numbers into the specified number of bins." } ;
+
+HELP: binpack!
+{ $values { "items" sequence } { "quot" quotation } { "n" "number of bins" } { "bins" "packed bins" } } 
+{ $description "Packs a sequence of items into the specified number of bins, using the quotatino to determine the weight." } ;
+
diff --git a/extra/math/binpack/binpack-tests.factor b/extra/math/binpack/binpack-tests.factor
new file mode 100644 (file)
index 0000000..d0d4630
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: kernel tools.test math.binpack ;
+
+[ t ] [ { V{ } } { } 1 binpack = ] unit-test
+
+[ t ] [ { { 3 } { 2 1 } } { 1 2 3 } 2 binpack* = ] unit-test
+
+[ t ] [ { { 1000 } { 100 60 30 7 } { 70 60 40 23 3 } } 
+        { 100 23 40 60 1000 30 60 07 70 03 } 3 binpack* = ] unit-test
+
+
diff --git a/extra/math/binpack/binpack.factor b/extra/math/binpack/binpack.factor
new file mode 100644 (file)
index 0000000..e3a009f
--- /dev/null
@@ -0,0 +1,22 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: sequences kernel arrays vectors accessors assocs sorting math math.functions ;
+
+IN: math.binpack 
+
+: (binpack) ( bins item -- )
+    [ [ values sum ] map ] keep
+    zip sort-keys values first push ;
+
+: binpack ( assoc n -- bins )
+    [ sort-values <reversed> dup length ] dip
+    tuck / ceiling <array> [ <vector> ] map
+    tuck [ (binpack) ] curry each ;
+
+: binpack* ( items n -- bins )
+    [ dup zip ] dip binpack [ keys ] map ;
+
+: binpack! ( items quot n -- bins ) 
+    [ dupd map zip ] dip binpack [ keys ] map ;
+
diff --git a/extra/math/binpack/summary.txt b/extra/math/binpack/summary.txt
new file mode 100644 (file)
index 0000000..c8b9196
--- /dev/null
@@ -0,0 +1 @@
+Bin-packing algorithms.
diff --git a/extra/time/authors.txt b/extra/time/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/time/time-docs.factor b/extra/time/time-docs.factor
new file mode 100644 (file)
index 0000000..8fbc59e
--- /dev/null
@@ -0,0 +1,43 @@
+
+USING: help.syntax help.markup kernel prettyprint sequences strings ;
+
+IN: time
+
+HELP: strftime
+{ $values { "format-string" string } }
+{ $description "Writes the timestamp (specified on the stack) formatted according to the format string." } 
+;
+
+ARTICLE: "strftime" "Formatted timestamps"
+"The " { $vocab-link "time" } " vocabulary is used for formatted timestamps.\n"
+{ $subsection strftime }
+"\n"
+"Several format specifications exist for handling arguments of different types, and specifying attributes for the result string, including such things as maximum width, padding, and decimals.\n"
+{ $table
+    { "%a"     "Abbreviated weekday name." }
+    { "%A"     "Full weekday name." }
+    { "%b"     "Abbreviated month name." }
+    { "%B"     "Full month name." }
+    { "%c"     "Date and time representation." }
+    { "%d"     "Day of the month as a decimal number [01,31]." }
+    { "%H"     "Hour (24-hour clock) as a decimal number [00,23]." }
+    { "%I"     "Hour (12-hour clock) as a decimal number [01,12]." }
+    { "%j"     "Day of the year as a decimal number [001,366]." }
+    { "%m"     "Month as a decimal number [01,12]." }
+    { "%M"     "Minute as a decimal number [00,59]." }
+    { "%p"     "Either AM or PM." }
+    { "%S"     "Second as a decimal number [00,59]." }
+    { "%U"     "Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]." }
+    { "%w"     "Weekday as a decimal number [0(Sunday),6]." }
+    { "%W"     "Week number of the year (Monday as the first day of the week) as a decimal number [00,53]." }
+    { "%x"     "Date representation." }
+    { "%X"     "Time representation." }
+    { "%y"     "Year without century as a decimal number [00,99]." }
+    { "%Y"     "Year with century as a decimal number." }
+    { "%Z"     "Time zone name (no characters if no time zone exists)." }
+    { "%%"     "A literal '%' character." }
+} ;
+
+ABOUT: "strftime"
+
+
diff --git a/extra/time/time-tests.factor b/extra/time/time-tests.factor
new file mode 100644 (file)
index 0000000..0b0602b
--- /dev/null
@@ -0,0 +1,24 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: kernel time tools.test calendar ;
+
+IN: time.tests
+
+[ "%H:%M:%S" strftime ] must-infer 
+
+: testtime ( -- timestamp )
+    2008 10 9 12 3 15 instant <timestamp> ;
+
+[ t ] [ "12:03:15" testtime "%H:%M:%S" strftime = ] unit-test
+[ t ] [ "12:03:15" testtime "%X" strftime = ] unit-test
+
+[ t ] [ "10/09/2008" testtime "%m/%d/%Y" strftime = ] unit-test
+[ t ] [ "10/09/2008" testtime "%x" strftime = ] unit-test
+
+[ t ] [ "Thu" testtime "%a" strftime = ] unit-test
+[ t ] [ "Thursday" testtime "%A" strftime = ] unit-test
+
+[ t ] [ "Oct" testtime "%b" strftime = ] unit-test
+[ t ] [ "October" testtime "%B" strftime = ] unit-test
+
diff --git a/extra/time/time.factor b/extra/time/time.factor
new file mode 100644 (file)
index 0000000..be19fb0
--- /dev/null
@@ -0,0 +1,72 @@
+! Copyright (C) 2008 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: accessors arrays calendar io kernel fry macros math
+math.functions math.parser peg.ebnf sequences strings vectors ;
+
+IN: time
+
+: >timestring ( timestamp -- string ) 
+    [ hour>> ] keep [ minute>> ] keep second>> 3array
+    [ number>string 2 CHAR: 0 pad-left ] map ":" join ; inline
+
+: >datestring ( timestamp -- string )
+    [ month>> ] keep [ day>> ] keep year>> 3array
+    [ number>string 2 CHAR: 0 pad-left ] map "/" join ; inline
+
+: (week-of-year) ( timestamp day -- n )
+    [ dup clone 1 >>month 1 >>day day-of-week dup ] dip > [ 7 swap - ] when
+    [ day-of-year ] dip 2dup < [ 0 2nip ] [ - 7 / 1+ >fixnum ] if ;
+
+: week-of-year-sunday ( timestamp -- n ) 0 (week-of-year) ; inline
+
+: week-of-year-monday ( timestamp -- n ) 1 (week-of-year) ; inline
+
+
+<PRIVATE
+
+EBNF: parse-format-string
+
+fmt-%     = "%"                  => [[ [ "%" ] ]]
+fmt-a     = "a"                  => [[ [ dup day-of-week day-abbreviation3 ] ]]
+fmt-A     = "A"                  => [[ [ dup day-of-week day-name ] ]] 
+fmt-b     = "b"                  => [[ [ dup month>> month-abbreviation ] ]]
+fmt-B     = "B"                  => [[ [ dup month>> month-name ] ]] 
+fmt-c     = "c"                  => [[ [ "Not yet implemented" throw ] ]]
+fmt-d     = "d"                  => [[ [ dup day>> number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-H     = "H"                  => [[ [ dup hour>> number>string 2 CHAR: 0 pad-left ] ]]
+fmt-I     = "I"                  => [[ [ dup hour>> 12 > [ 12 - ] when number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-j     = "j"                  => [[ [ dup day-of-year number>string ] ]] 
+fmt-m     = "m"                  => [[ [ dup month>> number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-M     = "M"                  => [[ [ dup minute>> number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-p     = "p"                  => [[ [ dup hour>> 12 < [ "AM" ] [ "PM" ] ? ] ]] 
+fmt-S     = "S"                  => [[ [ dup second>> round number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-U     = "U"                  => [[ [ dup week-of-year-sunday ] ]] 
+fmt-w     = "w"                  => [[ [ dup day-of-week number>string ] ]] 
+fmt-W     = "W"                  => [[ [ dup week-of-year-monday ] ]] 
+fmt-x     = "x"                  => [[ [ dup >datestring ] ]] 
+fmt-X     = "X"                  => [[ [ dup >timestring ] ]] 
+fmt-y     = "y"                  => [[ [ dup year>> 100 mod number>string ] ]] 
+fmt-Y     = "Y"                  => [[ [ dup year>> number>string ] ]] 
+fmt-Z     = "Z"                  => [[ [ "Not yet implemented" throw ] ]] 
+unknown   = (.)*                 => [[ "Unknown directive" throw ]]
+
+formats_  = fmt-%|fmt-a|fmt-A|fmt-b|fmt-B|fmt-c|fmt-d|fmt-H|fmt-I|
+            fmt-j|fmt-m|fmt-M|fmt-p|fmt-S|fmt-U|fmt-w|fmt-W|fmt-x|
+            fmt-X|fmt-y|fmt-Y|fmt-Z|unknown
+
+formats   = "%" (formats_)       => [[ second '[ _ dip ] ]]
+
+plain-text = (!("%").)+          => [[ >string '[ _ swap ] ]]
+
+text      = (formats|plain-text)* => [[ reverse [ [ [ push ] keep ] append ] map ]]
+
+;EBNF
+
+PRIVATE>
+
+MACRO: strftime ( format-string -- )
+    parse-format-string [ length ] keep [ ] join 
+    '[ _ <vector> @ reverse concat nip ] ;
+
+