]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 19 Mar 2009 12:06:50 +0000 (05:06 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 19 Mar 2009 12:06:50 +0000 (05:06 -0700)
136 files changed:
basis/compiler/tests/stack-trace.factor
basis/generalizations/generalizations-docs.factor
basis/html/streams/streams-tests.factor
basis/http/http.factor
basis/io/encodings/iana/iana-docs.factor
basis/io/encodings/iana/iana-tests.factor
basis/io/encodings/iana/iana.factor
basis/io/sockets/secure/unix/debug/debug.factor
basis/regexp/ast/ast.factor
basis/regexp/classes/classes.factor
basis/regexp/combinators/combinators.factor
basis/regexp/nfa/nfa.factor
basis/regexp/parser/parser.factor
basis/regexp/prettyprint/authors.txt [new file with mode: 0644]
basis/regexp/prettyprint/prettyprint.factor [new file with mode: 0644]
basis/regexp/regexp.factor
basis/simple-flat-file/simple-flat-file.factor
basis/stack-checker/errors/errors.factor
basis/tools/deploy/deploy-tests.factor
basis/tools/deploy/shaker/shaker.factor
basis/tools/deploy/shaker/strip-call.factor
basis/unicode/breaks/breaks.factor
basis/unicode/case/case-tests.factor
basis/unicode/case/case.factor
basis/unicode/categories/categories-tests.factor
basis/unicode/collation/collation.factor
basis/unicode/data/data-docs.factor
basis/unicode/data/data.factor
basis/unicode/normalize/normalize-tests.factor
basis/unicode/script/script-docs.factor
basis/unicode/script/script.factor
basis/unicode/syntax/syntax.factor
basis/urls/urls-docs.factor
basis/xml/autoencoding/autoencoding.factor
basis/xml/errors/errors-tests.factor
basis/xml/errors/errors.factor
core/vocabs/loader/loader-tests.factor
extra/advice/advice.factor
extra/benchmark/regex-dna/deploy.factor [new file with mode: 0644]
extra/benchmark/regex-dna/regex-dna.factor
extra/project-euler/001/001.factor
extra/project-euler/002/002.factor
extra/project-euler/003/003.factor
extra/project-euler/004/004.factor
extra/project-euler/005/005.factor
extra/project-euler/006/006.factor
extra/project-euler/007/007.factor
extra/project-euler/008/008.factor
extra/project-euler/009/009.factor
extra/project-euler/010/010.factor
extra/project-euler/011/011.factor
extra/project-euler/012/012.factor
extra/project-euler/013/013.factor
extra/project-euler/014/014.factor
extra/project-euler/015/015.factor
extra/project-euler/016/016.factor
extra/project-euler/017/017.factor
extra/project-euler/018/018.factor
extra/project-euler/019/019.factor
extra/project-euler/020/020.factor
extra/project-euler/021/021.factor
extra/project-euler/022/022.factor
extra/project-euler/023/023.factor
extra/project-euler/024/024.factor
extra/project-euler/025/025.factor
extra/project-euler/026/026.factor
extra/project-euler/027/027.factor
extra/project-euler/028/028.factor
extra/project-euler/029/029.factor
extra/project-euler/030/030.factor
extra/project-euler/031/031.factor
extra/project-euler/032/032.factor
extra/project-euler/033/033.factor
extra/project-euler/034/034.factor
extra/project-euler/035/035.factor
extra/project-euler/036/036.factor
extra/project-euler/037/037.factor
extra/project-euler/038/038.factor
extra/project-euler/039/039.factor
extra/project-euler/040/040.factor
extra/project-euler/041/041.factor
extra/project-euler/042/042.factor
extra/project-euler/043/043.factor
extra/project-euler/044/044.factor
extra/project-euler/045/045.factor
extra/project-euler/046/046.factor
extra/project-euler/047/047.factor
extra/project-euler/048/048.factor
extra/project-euler/050/050.factor
extra/project-euler/052/052.factor
extra/project-euler/053/053.factor
extra/project-euler/055/055.factor
extra/project-euler/056/056.factor
extra/project-euler/057/057.factor
extra/project-euler/059/059.factor
extra/project-euler/067/067.factor
extra/project-euler/071/071.factor
extra/project-euler/073/073.factor
extra/project-euler/075/075.factor
extra/project-euler/076/076.factor
extra/project-euler/079/079.factor
extra/project-euler/092/092.factor
extra/project-euler/097/097.factor
extra/project-euler/099/099.factor
extra/project-euler/100/100.factor
extra/project-euler/116/116.factor
extra/project-euler/117/117.factor
extra/project-euler/134/134.factor
extra/project-euler/148/148.factor
extra/project-euler/150/150.factor
extra/project-euler/151/151.factor
extra/project-euler/164/164.factor
extra/project-euler/169/169.factor
extra/project-euler/173/173.factor
extra/project-euler/175/175.factor
extra/project-euler/186/186.factor
extra/project-euler/190/190.factor
extra/project-euler/203/203.factor
extra/project-euler/215/215.factor
extra/project-euler/common/common.factor
extra/project-euler/project-euler.factor
extra/site-watcher/authors.txt
extra/site-watcher/db/authors.txt [new file with mode: 0644]
extra/site-watcher/db/db.factor [new file with mode: 0644]
extra/site-watcher/site-watcher-docs.factor [deleted file]
extra/site-watcher/site-watcher-tests.factor [new file with mode: 0644]
extra/site-watcher/site-watcher.factor
extra/webapps/site-watcher/main.xml [new file with mode: 0644]
extra/webapps/site-watcher/site-list.xml
extra/webapps/site-watcher/site-watcher.factor
extra/webapps/site-watcher/site-watcher.xml [new file with mode: 0644]
extra/webapps/site-watcher/update-notify.xml [new file with mode: 0644]
extra/webkit-demo/webkit-demo.factor
extra/wordtimer/wordtimer.factor
misc/fuel/fuel-font-lock.el
misc/fuel/fuel-syntax.el

index cfbea3bcb92c9e060e932876a86cdf1faa47f2cb..b317ed3eb5e5ef6a606625919540b1a9cecf020b 100755 (executable)
@@ -14,7 +14,7 @@ words splitting grouping sorting accessors ;
 [ t ] [
     symbolic-stack-trace
     [ word? ] filter
-    { baz bar foo throw } tail?
+    { baz bar foo } tail?
 ] unit-test
 
 : bleh ( seq -- seq' ) [ 3 + ] map [ 0 > ] filter ;
index 376ae5bed20aa0c212d8e825bd7270e19a03bd86..2088e468c64593800b8d869e335f6b618ceb6bfa 100644 (file)
@@ -58,7 +58,7 @@ HELP: npick
 "placed on the top of the stack."\r
 }\r
 { $examples\r
-  { $example "USING: kernel prettyprint generalizations ;" "1 2 3 4 4 npick .s clear" "1\n2\n3\n4\n1" }\r
+  { $example "USING: kernel prettyprint generalizations ;" "1 2 3 4 4 npick 5 narray ." "{ 1 2 3 4 1 }" }\r
   "Some core words expressed in terms of " { $link npick } ":"\r
     { $table\r
         { { $link dup } { $snippet "1 npick" } }\r
@@ -75,7 +75,7 @@ HELP: ndup
 "placed on the top of the stack."\r
 }\r
 { $examples\r
-  { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 4 ndup .s clear" "1\n2\n3\n4\n1\n2\n3\n4" }\r
+  { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 4 ndup 8 narray ." "{ 1 2 3 4 1 2 3 4 }" }\r
   "Some core words expressed in terms of " { $link ndup } ":"\r
     { $table\r
         { { $link dup } { $snippet "1 ndup" } }\r
@@ -91,7 +91,7 @@ HELP: nnip
 "for any number of items."\r
 }\r
 { $examples\r
-  { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 3 nnip .s clear" "4" }\r
+  { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 3 nnip ." "4" }\r
   "Some core words expressed in terms of " { $link nnip } ":"\r
     { $table\r
         { { $link nip } { $snippet "1 nnip" } }\r
@@ -106,7 +106,7 @@ HELP: ndrop
 "for any number of items."\r
 }\r
 { $examples\r
-  { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 3 ndrop .s clear" "1" }\r
+  { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 3 ndrop ." "1" }\r
   "Some core words expressed in terms of " { $link ndrop } ":"\r
     { $table\r
         { { $link drop } { $snippet "1 ndrop" } }\r
@@ -121,7 +121,7 @@ HELP: nrot
 "number of items on the stack. "\r
 }\r
 { $examples\r
-  { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 4 nrot .s clear" "2\n3\n4\n1" }\r
+  { $example "USING: arrays generalizations kernel prettyprint ;" "1 2 3 4 4 nrot 4array ." "{ 2 3 4 1 }" }\r
   "Some core words expressed in terms of " { $link nrot } ":"\r
     { $table\r
         { { $link swap } { $snippet "1 nrot" } }\r
@@ -135,7 +135,7 @@ HELP: -nrot
 "number of items on the stack. "\r
 }\r
 { $examples\r
-  { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 4 -nrot .s clear" "4\n1\n2\n3" }\r
+  { $example "USING: arrays generalizations kernel prettyprint ;" "1 2 3 4 4 -nrot 4array ." "{ 4 1 2 3 }" }\r
   "Some core words expressed in terms of " { $link -nrot } ":"\r
     { $table\r
         { { $link swap } { $snippet "1 -nrot" } }\r
@@ -151,8 +151,8 @@ HELP: ndip
 "stack. The quotation can consume and produce any number of items."\r
 } \r
 { $examples\r
-  { $example "USING: generalizations kernel prettyprint kernel ;" "1 2 [ dup ] 1 ndip .s clear" "1\n1\n2" }\r
-  { $example "USING: generalizations kernel prettyprint kernel ;" "1 2 3 [ drop ] 2 ndip .s clear" "2\n3" }\r
+  { $example "USING: arrays generalizations kernel prettyprint ;" "1 2 [ dup ] 1 ndip 3array ." "{ 1 1 2 }" }\r
+  { $example "USING: arrays generalizations kernel prettyprint ;" "1 2 3 [ drop ] 2 ndip 2array ." "{ 2 3 }" }\r
   "Some core words expressed in terms of " { $link ndip } ":"\r
     { $table\r
         { { $link dip } { $snippet "1 ndip" } }\r
@@ -168,7 +168,7 @@ HELP: nslip
 "removed from the stack, the quotation called, and the items restored."\r
 } \r
 { $examples\r
-  { $example "USING: generalizations kernel prettyprint ;" "[ 99 ] 1 2 3 4 5 5 nslip .s clear" "99\n1\n2\n3\n4\n5" }\r
+  { $example "USING: generalizations kernel prettyprint ;" "[ 99 ] 1 2 3 4 5 5 nslip 6 narray ." "{ 99 1 2 3 4 5 }" }\r
   "Some core words expressed in terms of " { $link nslip } ":"\r
     { $table\r
         { { $link slip } { $snippet "1 nslip" } }\r
@@ -184,7 +184,7 @@ HELP: nkeep
 "saved, the quotation called, and the items restored."\r
 } \r
 { $examples\r
-  { $example "USING: generalizations kernel prettyprint ;" "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep .s clear" "99\n1\n2\n3\n4\n5" }\r
+  { $example "USING: generalizations kernel prettyprint ;" "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep 6 narray ." "{ 99 1 2 3 4 5 }" }\r
   "Some core words expressed in terms of " { $link nkeep } ":"\r
     { $table\r
         { { $link keep } { $snippet "1 nkeep" } }\r
index 249861b12a8b93e7c6125ec827705219b4a5eb81..835874cbb751030659993b8c186b8f4d4b64e36c 100644 (file)
@@ -61,6 +61,4 @@ M: funky url-of "http://www.funky-town.com/" swap town>> append ;
     [ H{ } [ ] with-nesting nl ] make-html-string
 ] unit-test
 
-[ ] [ [ { 1 2 3 } describe ] with-html-writer drop ] unit-test
-
-[ ] [ [ \ predicate-instance? def>> . ] with-html-writer drop ] unit-test
+[ ] [ [ { 1 2 3 } describe ] with-html-writer drop ] unit-test
\ No newline at end of file
index bf58f5c238dd2c36c6d175c8a13f6d3de9e349e3..2b68edfb8e3f0f6e50873e21d5bd6426c9fc0884 100755 (executable)
@@ -5,8 +5,7 @@ sequences splitting sorting sets strings vectors hashtables
 quotations arrays byte-arrays math.parser calendar
 calendar.format present urls fry
 io io.encodings io.encodings.iana io.encodings.binary
-io.encodings.8-bit io.crlf
-unicode.case unicode.categories
+io.encodings.8-bit io.crlf ascii
 http.parsers
 base64 ;
 IN: http
@@ -215,11 +214,10 @@ TUPLE: post-data data params content-type content-encoding ;
 : parse-content-type-attributes ( string -- attributes )
     " " split harvest [
         "=" split1
-        [ >lower ] [ "\"" ?head drop "\"" ?tail drop ] bi*
+        "\"" ?head drop "\"" ?tail drop
     ] { } map>assoc ;
 
 : parse-content-type ( content-type -- type encoding )
     ";" split1
-    parse-content-type-attributes "charset" swap at
-    [ name>encoding ]
-    [ dup "text/" head? latin1 binary ? ] if* ;
+    parse-content-type-attributes "charset" swap at name>encoding
+    [ dup "text/" head? latin1 binary ? ] unless* ;
index c565d79ef5d58294780b4a48c72ee8d3ccf66d2e..628bceac6290e445b840a0c42748e07d7c641f67 100644 (file)
@@ -9,24 +9,15 @@ ARTICLE: "io.encodings.iana" "IANA-registered encoding names"
 { $subsection name>encoding }
 { $subsection encoding>name }
 "To let a new encoding be used with the above words, use the following:"
-{ $subsection register-encoding }
-"Exceptions when encodings or names are not found:"
-{ $subsection missing-encoding }
-{ $subsection missing-name } ;
-
-HELP: missing-encoding
-{ $error-description "The error called from " { $link name>encoding } " when there is no encoding descriptor registered corresponding to the given name." } ;
-
-HELP: missing-name
-{ $error-description "The error called from " { $link encoding>name } " when there is no name registered corresponding to the given encoding." } ;
+{ $subsection register-encoding } ;
 
 HELP: name>encoding
 { $values { "name" "an encoding name" } { "encoding" "an encoding descriptor" } }
-{ $description "Given an IANA-registered encoding name, find the encoding descriptor that represents it, or " { $code f } " if it is not found (either not implemented in Factor or not registered)." } ;
+{ $description "Given an IANA-registered encoding name, find the encoding descriptor that represents it, or " { $snippet "f" } " if it is not found (either not implemented in Factor or not registered)." } ;
 
 HELP: encoding>name
 { $values { "encoding" "an encoding descriptor" } { "name" "an encoding name" } }
-{ $description "Given an encoding descriptor, return the preferred IANA name." } ;
+{ $description "Given an encoding descriptor, return the preferred IANA name. If no name is found, returns " { $snippet "f" } "." } ;
 
 { name>encoding encoding>name } related-words
 
index 3175e624cea2f95d7e5686a0d7191f0d1dae1ea9..67b849b2b24a3b4f9dadc67a23b9b3f86f10db2d 100644 (file)
@@ -19,10 +19,10 @@ ebcdic-fisea "EBCDIC-FI-SE-A" register-encoding
     "csEBCDICFISEA" n>e-table get delete-at
     ebcdic-fisea e>n-table get delete-at
 ] unit-test
-[ "EBCDIC-FI-SE-A" name>encoding ] must-fail
-[ "csEBCDICFISEA" name>encoding ] must-fail
-[ ebcdic-fisea encoding>name ] must-fail
+[ f ] [ "EBCDIC-FI-SE-A" name>encoding ] unit-test
+[ f ] [ "csEBCDICFISEA" name>encoding ] unit-test
+[ f ] [ ebcdic-fisea encoding>name ] unit-test
 
 [ ebcdic-fisea "foobar" register-encoding ] must-fail
-[ "foobar" name>encoding ] must-fail
-[ ebcdic-fisea encoding>name ] must-fail
+[ f ] [ "foobar" name>encoding ] unit-test
+[ f ] [ ebcdic-fisea encoding>name ] unit-test
index a8555ac3393bc74d70d633eed2765e04d69e263a..b504bf854a29a224f0ceaaf107b42fb9cd965a29 100644 (file)
@@ -10,15 +10,11 @@ SYMBOL: e>n-table
 SYMBOL: aliases
 PRIVATE>
 
-ERROR: missing-encoding name ;
+: name>encoding ( name -- encoding/f )
+    n>e-table get-global at ;
 
-: name>encoding ( name -- encoding )
-    dup n>e-table get-global at [ ] [ missing-encoding ] ?if ;
-
-ERROR: missing-name encoding ;
-
-: encoding>name ( encoding -- name )
-    dup e>n-table get-global at [ ] [ missing-name ] ?if ;
+: encoding>name ( encoding -- name/f )
+    e>n-table get-global at ;
 
 <PRIVATE
 : parse-iana ( file -- synonym-set )
index 10df82ae7bf28ee8b4ad186219fae9a56eb61d98..9481a7c1a8924d87d13c9c4ae5749578dc131537 100644 (file)
@@ -1,11 +1,14 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors io.sockets.secure kernel ;
 IN: io.sockets.secure.unix.debug
 
-: with-test-context ( quot -- )
+: <test-secure-config> ( -- config )
     <secure-config>
         "vocab:openssl/test/server.pem" >>key-file
         "vocab:openssl/test/dh1024.pem" >>dh-file
-        "password" >>password
+        "password" >>password ;
+
+: with-test-context ( quot -- )
+    <test-secure-config>
     swap with-secure-context ; inline
index 1c11ed5c7d58070ba5e51d29d48d2fb605963714..be657227e521a2c522a0adc20ff34bb4e6d6fdc7 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel arrays accessors fry sequences regexp.classes ;
-FROM: math.ranges => [a,b] ;
+USING: kernel arrays accessors fry sequences regexp.classes
+math.ranges math ;
 IN: regexp.ast
 
 TUPLE: negation term ;
@@ -49,10 +49,20 @@ SINGLETONS: unix-lines dotall multiline case-insensitive reversed-regexp ;
     <array> <concatenation> ;
 
 GENERIC: <times> ( term times -- term' )
+
 M: at-least <times>
     n>> swap [ repetition ] [ <star> ] bi 2array <concatenation> ;
+
+: to-times ( term n -- ast )
+    dup zero?
+    [ 2drop epsilon ]
+    [ dupd 1- to-times 2array <concatenation> <maybe> ]
+    if ;
+
 M: from-to <times>
-    [ n>> ] [ m>> ] bi [a,b] swap '[ _ repetition ] map <alternation> ;
+    [ n>> swap repetition ]
+    [ [ m>> ] [ n>> ] bi - to-times ] 2bi
+    2array <concatenation> ;
 
 : char-class ( ranges ? -- term )
     [ <or-class> ] dip [ <not-class> ] when ;
index e3a177458591bff0d0b99d4ce6f2ebd75e31afef..28b0ed1563441aa7a410fa04fc50e434c6f685cd 100644 (file)
@@ -2,20 +2,33 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel math math.order words combinators locals
 ascii unicode.categories combinators.short-circuit sequences
-fry macros arrays assocs sets classes mirrors ;
+fry macros arrays assocs sets classes mirrors unicode.script
+unicode.data ;
 IN: regexp.classes
 
-SINGLETONS: any-char any-char-no-nl
-letter-class LETTER-class Letter-class digit-class
+SINGLETONS: dot letter-class LETTER-class Letter-class digit-class
 alpha-class non-newline-blank-class
 ascii-class punctuation-class java-printable-class blank-class
 control-character-class hex-digit-class java-blank-class c-identifier-class
 unmatchable-class terminator-class word-boundary-class ;
 
-SINGLETONS: beginning-of-input ^ end-of-input $ end-of-file ^unix $unix word-break ;
+SINGLETONS: beginning-of-input ^ end-of-input $ end-of-file
+^unix $unix word-break ;
 
-TUPLE: range from to ;
-C: <range> range
+TUPLE: range-class from to ;
+C: <range-class> range-class
+
+TUPLE: primitive-class class ;
+C: <primitive-class> primitive-class
+
+TUPLE: category-class category ;
+C: <category-class> category-class
+
+TUPLE: category-range-class category ;
+C: <category-range-class> category-range-class
+
+TUPLE: script-class script ;
+C: <script-class> script-class
 
 GENERIC: class-member? ( obj class -- ? )
 
@@ -23,15 +36,9 @@ M: t class-member? ( obj class -- ? ) 2drop t ;
 
 M: integer class-member? ( obj class -- ? ) = ;
 
-M: range class-member? ( obj class -- ? )
+M: range-class class-member? ( obj class -- ? )
     [ from>> ] [ to>> ] bi between? ;
 
-M: any-char class-member? ( obj class -- ? )
-    2drop t ;
-
-M: any-char-no-nl class-member? ( obj class -- ? )
-    drop CHAR: \n = not ;
-
 M: letter-class class-member? ( obj class -- ? )
     drop letter? ;
             
@@ -99,21 +106,24 @@ M: unmatchable-class class-member? ( obj class -- ? )
 M: terminator-class class-member? ( obj class -- ? )
     drop "\r\n\u000085\u002029\u002028" member? ;
 
-M: ^ class-member? ( obj class -- ? )
-    2drop f ;
+M: f class-member? 2drop f ;
 
-M: $ class-member? ( obj class -- ? )
-    2drop f ;
+M: script-class class-member?
+    [ script-of ] [ script>> ] bi* = ;
 
-M: f class-member? 2drop f ;
+M: category-class class-member?
+    [ category# ] [ category>> ] bi* = ;
 
-TUPLE: primitive-class class ;
-C: <primitive-class> primitive-class
+M: category-range-class class-member?
+    [ category first ] [ category>> ] bi* = ;
 
 TUPLE: not-class class ;
 
 PREDICATE: not-integer < not-class class>> integer? ;
-PREDICATE: not-primitive < not-class class>> primitive-class? ;
+
+UNION: simple-class
+    primitive-class range-class category-class category-range-class dot ;
+PREDICATE: not-simple < not-class class>> simple-class? ;
 
 M: not-class class-member?
     class>> class-member? not ;
@@ -140,14 +150,14 @@ DEFER: substitute
         [ drop class new seq { } like >>seq ]
     } case ; inline
 
-TUPLE: class-partition integers not-integers primitives not-primitives and or other ;
+TUPLE: class-partition integers not-integers simples not-simples and or other ;
 
 : partition-classes ( seq -- class-partition )
     prune
     [ integer? ] partition
     [ not-integer? ] partition
-    [ primitive-class? ] partition ! extend primitive-class to epsilon tags
-    [ not-primitive? ] partition
+    [ simple-class? ] partition
+    [ not-simple? ] partition
     [ and-class? ] partition
     [ or-class? ] partition
     class-partition boa ;
@@ -161,17 +171,17 @@ TUPLE: class-partition integers not-integers primitives not-primitives and or ot
 
 : filter-not-integers ( partition -- partition' )
     dup
-    [ primitives>> ] [ not-primitives>> ] [ or>> ] tri
+    [ simples>> ] [ not-simples>> ] [ or>> ] tri
     3append and-class boa
     '[ [ class>> _ class-member? ] filter ] change-not-integers ;
 
 : answer-ors ( partition -- partition' )
-    dup [ not-integers>> ] [ not-primitives>> ] [ primitives>> ] tri 3append
+    dup [ not-integers>> ] [ not-simples>> ] [ simples>> ] tri 3append
     '[ [ _ [ t substitute ] each ] map ] change-or ;
 
 : contradiction? ( partition -- ? )
     {
-        [ [ primitives>> ] [ not-primitives>> ] bi intersects? ]
+        [ [ simples>> ] [ not-simples>> ] bi intersects? ]
         [ other>> f swap member? ]
     } 1|| ;
 
@@ -192,17 +202,17 @@ TUPLE: class-partition integers not-integers primitives not-primitives and or ot
 
 : filter-integers ( partition -- partition' )
     dup
-    [ primitives>> ] [ not-primitives>> ] [ and>> ] tri
+    [ simples>> ] [ not-simples>> ] [ and>> ] tri
     3append or-class boa
     '[ [ _ class-member? not ] filter ] change-integers ;
 
 : answer-ands ( partition -- partition' )
-    dup [ integers>> ] [ not-primitives>> ] [ primitives>> ] tri 3append
+    dup [ integers>> ] [ not-simples>> ] [ simples>> ] tri 3append
     '[ [ _ [ f substitute ] each ] map ] change-and ;
 
 : tautology? ( partition -- ? )
     {
-        [ [ primitives>> ] [ not-primitives>> ] bi intersects? ]
+        [ [ simples>> ] [ not-simples>> ] bi intersects? ]
         [ other>> t swap member? ]
     } 1|| ;
 
@@ -241,8 +251,6 @@ M: f <not-class> drop t ;
 M: primitive-class class-member?
     class>> class-member? ;
 
-UNION: class primitive-class not-class or-class and-class range ;
-
 TUPLE: condition question yes no ;
 C: <condition> condition
 
index 2941afd99e59c9aa96f6bd423ef823c179fbd315..3bb5fcef6d96ca8f692b8b859f52ef8fdf9f61dc 100644 (file)
@@ -13,14 +13,14 @@ IN: regexp.combinators
 
 PRIVATE>
 
-CONSTANT: <nothing> R/ (?~.*)/
+CONSTANT: <nothing> R/ (?~.*)/s
 
 : <literal> ( string -- regexp )
     [ "\\Q" "\\E" surround ] [ <concatenation> ] bi make-regexp ; foldable
 
 : <char-range> ( char1 char2 -- regexp )
     [ [ "[" "-" surround ] [ "]" append ] bi* append ]
-    [ <range> ]
+    [ <range-class> ]
     2bi make-regexp ;
 
 : <or> ( regexps -- disjunction )
index d59d4818ec7ef5926a8dbd13ca4f9c5c61bdf347..a692f707780f239754fe7570ce116f580f304542 100644 (file)
@@ -3,11 +3,11 @@
 USING: accessors arrays assocs grouping kernel locals math namespaces
 sequences fry quotations math.order math.ranges vectors
 unicode.categories regexp.transition-tables words sets hashtables
-combinators.short-circuit unicode.case unicode.case.private regexp.ast
-regexp.classes ;
+combinators.short-circuit unicode.data regexp.ast
+regexp.classes memoize ;
 IN: regexp.nfa
 
-! This uses unicode.case.private for ch>upper and ch>lower
+! This uses unicode.data for ch>upper and ch>lower
 ! but case-insensitive matching should be done by case-folding everything
 ! before processing starts
 
@@ -117,8 +117,17 @@ M: or-class modify-class
 M: not-class modify-class
     class>> modify-class <not-class> ;
 
-M: any-char modify-class
-    drop dotall option? t any-char-no-nl ? ;
+MEMO: unix-dot ( -- class )
+    CHAR: \n <not-class> ;
+
+MEMO: nonl-dot ( -- class )
+    { CHAR: \n CHAR: \r } <or-class> <not-class> ;
+
+M: dot modify-class
+    drop dotall option? [ t ] [
+        unix-lines option?
+        unix-dot nonl-dot ?
+    ] if ;
 
 : modify-letter-class ( class -- newclass )
     case-insensitive option? [ drop Letter-class ] when ;
@@ -131,17 +140,17 @@ M: LETTER-class modify-class modify-letter-class ;
         [ [ LETTER? ] bi@ and ]
     } 2|| ;
 
-M: range modify-class
+M: range-class modify-class
     case-insensitive option? [
         dup cased-range? [
             [ from>> ] [ to>> ] bi
-            [ [ ch>lower ] bi@ <range> ]
-            [ [ ch>upper ] bi@ <range> ] 2bi 
+            [ [ ch>lower ] bi@ <range-class> ]
+            [ [ ch>upper ] bi@ <range-class> ] 2bi 
             2array <or-class>
         ] when
     ] when ;
 
-M: class nfa-node
+M: object nfa-node
     modify-class add-simple-entry ;
 
 M: with-options nfa-node ( node -- start end )
index 7b2d6af2c1d17afb1fc8cd0de6d73ce5f22330e5..bf5465e0e2607f0e8142360dfa9f84dde122c81a 100644 (file)
@@ -18,6 +18,13 @@ ERROR: bad-number ;
 
 ERROR: bad-class name ;
 
+: parse-unicode-class ( name -- class )
+    ! Implement this!
+    drop f ;
+
+: unicode-class ( name -- class )
+    dup parse-unicode-class [ ] [ bad-class ] ?if ;
+
 : name>class ( name -- class )
     >string >case-fold {
         { "lower" letter-class }
@@ -32,8 +39,7 @@ ERROR: bad-class name ;
         { "cntrl" control-character-class }
         { "xdigit" hex-digit-class }
         { "space" java-blank-class }
-        ! TODO: unicode-character-class
-    } [ bad-class ] at-error ;
+    } [ unicode-class ] at-error ;
 
 : lookup-escape ( char -- ast )
     {
@@ -119,10 +125,10 @@ AnyRangeCharacter = EscapeSequence | .
 
 RangeCharacter = !("]") AnyRangeCharacter
 
-Range = RangeCharacter:a "-" RangeCharacter:b => [[ a b <range> ]]
+Range = RangeCharacter:a "-" RangeCharacter:b => [[ a b <range-class> ]]
       | RangeCharacter
 
-StartRange = AnyRangeCharacter:a "-" RangeCharacter:b => [[ a b <range> ]]
+StartRange = AnyRangeCharacter:a "-" RangeCharacter:b => [[ a b <range-class> ]]
            | AnyRangeCharacter
 
 Ranges = StartRange:s Range*:r => [[ r s prefix ]]
@@ -144,7 +150,7 @@ Parenthized = "?:" Alternation:a => [[ a ]]
 
 Element = "(" Parenthized:p ")" => [[ p ]]
         | "[" CharClass:r "]" => [[ r ]]
-        | ".":d => [[ any-char <primitive-class> ]]
+        | ".":d => [[ dot ]]
         | Character
 
 Number = (!(","|"}").)* => [[ string>number ensure-number ]]
diff --git a/basis/regexp/prettyprint/authors.txt b/basis/regexp/prettyprint/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/regexp/prettyprint/prettyprint.factor b/basis/regexp/prettyprint/prettyprint.factor
new file mode 100644 (file)
index 0000000..7af762a
--- /dev/null
@@ -0,0 +1,13 @@
+! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors kernel make prettyprint.backend
+prettyprint.custom regexp regexp.parser regexp.private ;
+IN: regexp.prettyprint
+
+M: regexp pprint*
+    [
+        [
+            [ raw>> dup find-regexp-syntax swap % swap % % ]
+            [ options>> options>string % ] bi
+        ] "" make
+    ] keep present-text ;
\ No newline at end of file
index 5889b19e476d122b2212a87bbf1b5270e81c4667..33499b14372bc5e7a143cfda03d0afc6248f35fe 100644 (file)
@@ -1,10 +1,9 @@
 ! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors combinators kernel kernel.private math sequences
-sequences.private strings sets assocs prettyprint.backend
-prettyprint.custom make lexer namespaces parser arrays fry locals
-regexp.parser splitting sorting regexp.ast regexp.negation
-regexp.compiler compiler.units words math.ranges ;
+sequences.private strings sets assocs make lexer namespaces parser
+arrays fry locals regexp.parser splitting sorting regexp.ast
+regexp.negation regexp.compiler compiler.units words math.ranges ;
 IN: regexp
 
 TUPLE: regexp
@@ -217,11 +216,8 @@ PRIVATE>
 : R{ CHAR: } parsing-regexp ; parsing
 : R| CHAR: | parsing-regexp ; parsing
 
-M: regexp pprint*
-    [
-        [
-            [ raw>> dup find-regexp-syntax swap % swap % % ]
-            [ options>> options>string % ] bi
-        ] "" make
-    ] keep present-text ;
+USING: vocabs vocabs.loader ;
 
+"prettyprint" vocab [
+    "regexp.prettyprint" require
+] when
\ No newline at end of file
index 403fc4d14b82e0a4b8056d0d5120184e867c3dbf..6e53c97738d476a4c99098b0745ceb95239715b8 100644 (file)
@@ -1,10 +1,11 @@
 ! Copyright (C) 2009 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
-USING: sequences splitting kernel math.parser io.files io.encodings.ascii biassocs ;
+USING: sequences splitting kernel math.parser io.files io.encodings.utf8
+biassocs ascii ;
 IN: simple-flat-file
 
 : drop-comments ( seq -- newseq )
-    [ "#" split1 drop ] map harvest ;
+    [ "#@" split first ] map harvest ;
 
 : split-column ( line -- columns )
     " \t" split harvest 2 short head 2 f pad-tail ;
@@ -22,5 +23,10 @@ IN: simple-flat-file
     drop-comments [ parse-line ] map ; 
 
 : flat-file>biassoc ( filename -- biassoc )
-    ascii file-lines process-codetable-lines >biassoc ;
+    utf8 file-lines process-codetable-lines >biassoc ;
 
+: split-; ( line -- array )
+    ";" split [ [ blank? ] trim ] map ;
+
+: data ( filename -- data )
+    utf8 file-lines drop-comments [ split-; ] map ;
index 7f35ece71473fe7fee5ce7c5ee0f819089587da0..07c26ad100f4490a19290245ab6eaadfba248570 100644 (file)
@@ -1,8 +1,8 @@
-! Copyright (C) 2006, 2008 Slava Pestov.
+! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel generic sequences io words arrays summary effects
-assocs accessors namespaces compiler.errors stack-checker.values
-stack-checker.recursive-state ;
+continuations assocs accessors namespaces compiler.errors
+stack-checker.values stack-checker.recursive-state ;
 IN: stack-checker.errors
 
 : pretty-word ( word -- word' )
@@ -15,7 +15,7 @@ M: inference-error compiler-error-type type>> ;
 : (inference-error) ( ... class type -- * )
     [ boa ] dip
     recursive-state get word>>
-    \ inference-error boa throw ; inline
+    \ inference-error boa rethrow ; inline
 
 : inference-error ( ... class -- * )
     +error+ (inference-error) ; inline
index 3a2f960fc93713b346f70eeadd3f601406eeabc7..3bebf7236d6074c1db7ecbc62fb4af785febfebf 100644 (file)
@@ -26,6 +26,8 @@ os macosx? [
     [ t ] [ "webkit-demo" shake-and-bake 500000 small-enough? ] unit-test\r
 ] when\r
 \r
+[ t ] [ "benchmark.regex-dna" shake-and-bake 900000 small-enough? ] unit-test\r
+\r
 {\r
     "tools.deploy.test.1"\r
     "tools.deploy.test.2"\r
index 239d34b86460b2c733c9cf29aa8a4b9b8e5a533d..a729e40e2a670f6798a8d5aca202d766cdd229e5 100755 (executable)
@@ -54,11 +54,8 @@ IN: tools.deploy.shaker
     ] when ;
 
 : strip-call ( -- )
-    "call" vocab [
-        "Stripping stack effect checking from call( and execute(" show
-        "vocab:tools/deploy/shaker/strip-call.factor"
-        run-file
-    ] when ;
+    "Stripping stack effect checking from call( and execute(" show
+    "vocab:tools/deploy/shaker/strip-call.factor" run-file ;
 
 : strip-cocoa ( -- )
     "cocoa" vocab [
index 860a0f38492fa2e80400f8a77fd7ea8bce0be905..d0593b6c150165c37208483cc5e81580249fe32f 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 IN: tools.deploy.shaker.call
 
-IN: call
-USE: call.private
+IN: combinators
+USE: combinators.private
 
 : call-effect ( word effect -- ) call-effect-unsafe ; inline
 
index f2e94545455972ba712c954d1d714b01db6d6ff3..91f6a45911cce51ada86bbd44f4c6896ec1e6edd 100644 (file)
@@ -2,8 +2,9 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: combinators.short-circuit unicode.categories kernel math
 combinators splitting sequences math.parser io.files io assocs
-arrays namespaces make math.ranges unicode.normalize.private values
-io.encodings.ascii unicode.syntax unicode.data compiler.units fry
+arrays namespaces make math.ranges unicode.normalize
+unicode.normalize.private values io.encodings.ascii
+unicode.syntax unicode.data compiler.units fry
 alien.syntax sets accessors interval-maps memoize locals words ;
 IN: unicode.breaks
 
@@ -126,7 +127,7 @@ to: grapheme-table
 
 VALUE: word-break-table
 
-"vocab:unicode/data/WordBreakProperty.txt" load-script
+"vocab:unicode/data/WordBreakProperty.txt" load-key-value
 to: word-break-table
 
 C-ENUM: wOther wCR wLF wNewline wExtend wFormat wKatakana wALetter wMidLetter
index 52a8d9755eb2ef7a99afbe90b0816e2f1c8a07be..a76f5e78c408c3a1cd8c7955db87d9828d75dc7b 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2008, 2009 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: unicode.case unicode.case.private tools.test namespaces strings unicode.normalize ;
+USING: unicode.case tools.test namespaces strings unicode.normalize
+unicode.case.private ;
 IN: unicode.case.tests
 
 \ >upper must-infer
index c75582dacd82a5497ca91c43fdaf391adaf91983..fa842b8b818a1bed743ea5e46c647877f4c7469d 100644 (file)
@@ -7,12 +7,6 @@ strings splitting kernel accessors unicode.breaks fry locals ;
 QUALIFIED: ascii
 IN: unicode.case
 
-<PRIVATE
-: ch>lower ( ch -- lower ) simple-lower at-default ; inline
-: ch>upper ( ch -- upper ) simple-upper at-default ; inline
-: ch>title ( ch -- title ) simple-title at-default ; inline
-PRIVATE>
-
 SYMBOL: locale ! Just casing locale, or overall?
 
 <PRIVATE
@@ -86,7 +80,7 @@ SYMBOL: locale ! Just casing locale, or overall?
 :: map-case ( string string-quot char-quot -- case )
     string length <sbuf> :> out
     string [
-        dup special-casing at
+        dup special-case
         [ string-quot call out push-all ]
         [ char-quot call out push ] ?if
     ] each out "" like ; inline
index e16125b6423349fe0d924aa21020476410658924..1e718cf9b7c76dbac78e681771eda8e575ba24b3 100644 (file)
@@ -1,4 +1,7 @@
-USING: tools.test kernel unicode.categories words sequences unicode.syntax ;
+! Copyright (C) 2008 Daniel Ehrenberg.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test kernel unicode.categories words sequences unicode.data ;
+IN: unicode.categories.tests
 
 [ { f f t t f t t f f t } ] [ CHAR: A { 
     blank? letter? LETTER? Letter? digit? 
index 2a94d501bdce30de81e10bc4db287f554760ce80..0c51ea4352efda97386b7528886f4bc2639a288c 100755 (executable)
@@ -5,7 +5,7 @@ io.encodings.ascii kernel values splitting accessors math.parser
 ascii io assocs strings math namespaces make sorting combinators\r
 math.order arrays unicode.normalize unicode.data locals\r
 unicode.syntax macros sequences.deep words unicode.breaks\r
-quotations combinators.short-circuit ;\r
+quotations combinators.short-circuit simple-flat-file ;\r
 IN: unicode.collation\r
 \r
 <PRIVATE\r
@@ -20,13 +20,11 @@ TUPLE: weight primary secondary tertiary ignorable? ;
         [ >>primary ] [ >>secondary ] [ >>tertiary ] tri*\r
     ] map ;\r
 \r
-: parse-line ( line -- code-poing weight )\r
-    ";" split1 [ [ blank? ] trim ] bi@\r
-    [ " " split [ hex> ] "" map-as ] [ parse-weight ] bi* ;\r
+: parse-keys ( string -- chars )\r
+    " " split [ hex> ] "" map-as ;\r
 \r
 : parse-ducet ( file -- ducet )\r
-    ascii file-lines filter-comments\r
-    [ parse-line ] H{ } map>assoc ;\r
+    data [ [ parse-keys ] [ parse-weight ] bi* ] H{ } assoc-map-as ;\r
 \r
 "vocab:unicode/collation/allkeys.txt" parse-ducet to: ducet\r
 \r
index 55fed313866d753fc60ea61dbd261d4c6b3d7b8a..d1a458eb480066de5fe5bb8fd913f30375268156 100644 (file)
@@ -1,3 +1,5 @@
+! Copyright (C) 2009 Daniel Ehrenberg
+! See http://factorcode.org/license.txt for BSD license.
 USING: help.syntax help.markup strings ;
 IN: unicode.data
 
@@ -5,18 +7,14 @@ 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
-{ $values { "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." } ;
+{ $subsection property? }
+{ $subsection load-key-value } ;
 
 HELP: canonical-entry
 { $values { "char" "a code point" } { "seq" string } }
@@ -49,3 +47,7 @@ HELP: name>char
 HELP: property?
 { $values { "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." } ;
+
+HELP: load-key-value
+{ $values { "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." } ;
index 74914e8537cd37b6a31935281b0322f7483fe943..e94036a85e6cf4bb6944526ee2b6b97b41e58547 100644 (file)
@@ -1,13 +1,15 @@
-! Copyright (C) 2008 Daniel Ehrenberg.
+! Copyright (C) 2008, 2009 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: combinators.short-circuit assocs math kernel sequences
 io.files hashtables quotations splitting grouping arrays io
 math.parser hash2 math.order byte-arrays words namespaces words
 compiler.units parser io.encodings.ascii values interval-maps
 ascii sets combinators locals math.ranges sorting make
-strings.parser io.encodings.utf8 memoize ;
+strings.parser io.encodings.utf8 memoize simple-flat-file ;
 IN: unicode.data
 
+<PRIVATE
+
 VALUE: simple-lower
 VALUE: simple-upper
 VALUE: simple-title
@@ -16,35 +18,69 @@ VALUE: combine-map
 VALUE: class-map
 VALUE: compatibility-map
 VALUE: category-map
-VALUE: name-map
 VALUE: special-casing
 VALUE: properties
 
-: canonical-entry ( char -- seq ) canonical-map at ;
-: combine-chars ( a b -- char/f ) combine-map hash2 ;
-: compatibility-entry ( char -- seq ) compatibility-map at  ;
-: combining-class ( char -- n ) class-map at ;
-: non-starter? ( char -- ? ) combining-class { 0 f } member? not ;
-: name>char ( name -- char ) name-map at ;
-: char>name ( char -- name ) name-map value-at ;
-: property? ( char property -- ? ) properties at interval-key? ;
+PRIVATE>
 
-! Loading data from UnicodeData.txt
+VALUE: name-map
+
+: canonical-entry ( char -- seq ) canonical-map at ; inline
+: combine-chars ( a b -- char/f ) combine-map hash2 ; inline
+: compatibility-entry ( char -- seq ) compatibility-map at ; inline
+: combining-class ( char -- n ) class-map at ; inline
+: non-starter? ( char -- ? ) combining-class { 0 f } member? not ; inline
+: name>char ( name -- char ) name-map at ; inline
+: char>name ( char -- name ) name-map value-at ; inline
+: property? ( char property -- ? ) properties at interval-key? ; inline
+: ch>lower ( ch -- lower ) simple-lower at-default ; inline
+: ch>upper ( ch -- upper ) simple-upper at-default ; inline
+: ch>title ( ch -- title ) simple-title at-default ; inline
+: special-case ( ch -- casing-tuple ) special-casing at ; inline
+
+! For non-existent characters, use Cn
+CONSTANT: categories
+    { "Cn"
+      "Lu" "Ll" "Lt" "Lm" "Lo"
+      "Mn" "Mc" "Me"
+      "Nd" "Nl" "No"
+      "Pc" "Pd" "Ps" "Pe" "Pi" "Pf" "Po"
+      "Sm" "Sc" "Sk" "So"
+      "Zs" "Zl" "Zp"
+      "Cc" "Cf" "Cs" "Co" }
 
-: split-; ( line -- array )
-    ";" split [ [ blank? ] trim ] map ;
+<PRIVATE
 
-: data ( filename -- data )
-    ascii file-lines [ split-; ] map ;
+MEMO: categories-map ( -- hashtable )
+    categories <enum> [ swap ] H{ } assoc-map-as ;
+
+CONSTANT: num-chars HEX: 2FA1E
+
+PRIVATE>
+
+: category# ( char -- category )
+    ! There are a few characters that should be Cn
+    ! that this gives Cf or Mn
+    ! Cf = 26; Mn = 5; Cn = 29
+    ! Use a compressed array instead?
+    dup category-map ?nth [ ] [
+        dup HEX: E0001 HEX: E007F between?
+        [ drop 26 ] [
+            HEX: E0100 HEX: E01EF between?  5 29 ?
+        ] if
+    ] ?if ;
+
+: category ( char -- category )
+    category# categories nth ;
+
+<PRIVATE
+
+! Loading data from UnicodeData.txt
 
 : load-data ( -- data )
     "vocab:unicode/data/UnicodeData.txt" data ;
 
-: filter-comments ( lines -- lines )
-    [ "#@" split first ] map harvest ;
-
 : (process-data) ( index data -- newdata )
-    filter-comments
     [ [ nth ] keep first swap ] with { } map>assoc
     [ [ hex> ] dip ] assoc-map ;
 
@@ -97,22 +133,6 @@ VALUE: properties
     [ nip zero? not ] assoc-filter
     >hashtable ;
 
-! For non-existent characters, use Cn
-CONSTANT: categories
-    { "Cn"
-      "Lu" "Ll" "Lt" "Lm" "Lo"
-      "Mn" "Mc" "Me"
-      "Nd" "Nl" "No"
-      "Pc" "Pd" "Ps" "Pe" "Pi" "Pf" "Po"
-      "Sm" "Sc" "Sk" "So"
-      "Zs" "Zl" "Zp"
-      "Cc" "Cf" "Cs" "Co" }
-
-MEMO: categories-map ( -- hashtable )
-    categories <enum> [ swap ] H{ } assoc-map-as ;
-
-CONSTANT: num-chars HEX: 2FA1E
-
 ! the maximum unicode char in the first 3 planes
 
 : ?set-nth ( val index seq -- )
@@ -140,24 +160,26 @@ CONSTANT: num-chars HEX: 2FA1E
 : multihex ( hexstring -- string )
     " " split [ hex> ] map sift ;
 
+PRIVATE>
+
 TUPLE: code-point lower title upper ;
 
 C: <code-point> code-point
 
+<PRIVATE
+
 : set-code-point ( seq -- )
     4 head [ multihex ] map first4
     <code-point> swap first set ;
 
 ! Extra properties
-: properties-lines ( -- lines )
-    "vocab:unicode/data/PropList.txt"
-    ascii file-lines ;
-
 : parse-properties ( -- {{[a,b],prop}} )
-    properties-lines filter-comments [
-        split-; first2
-        [ ".." split1 [ dup ] unless* [ hex> ] bi@ 2array ] dip
-    ] { } map>assoc ;
+    "vocab:unicode/data/PropList.txt" data [
+        [
+            ".." split1 [ dup ] unless*
+            [ hex> ] bi@ 2array
+        ] dip
+    ] assoc-map ;
 
 : properties>intervals ( properties -- assoc[str,interval] )
     dup values prune [ f ] H{ } map>assoc
@@ -195,14 +217,11 @@ load-special-casing to: special-casing
 
 load-properties to: properties
 
-! Utility to load resource files that look like Scripts.txt
+[ name>char [ "Invalid character" throw ] unless* ]
+name>char-hook set-global
 
 SYMBOL: interned
 
-: parse-script ( filename -- assoc )
-    ! assoc is code point/range => name
-    ascii file-lines filter-comments [ split-; ] map ;
-
 : range, ( value key -- )
     swap interned get
     [ = ] with find nip 2array , ;
@@ -216,12 +235,11 @@ SYMBOL: interned
         ] assoc-each
     ] { } make <interval-map> ;
 
-: process-script ( ranges -- table )
+: process-key-value ( ranges -- table )
     dup values prune interned
     [ expand-ranges ] with-variable ;
 
-: load-script ( filename -- table )
-    parse-script process-script ;
+PRIVATE>
 
-[ name>char [ "Invalid character" throw ] unless* ]
-name>char-hook set-global
+: load-key-value ( filename -- table )
+    data process-key-value ;
index f3ecb96af97dc72c1d17fd4f96b9dd22d3531a38..f774016272168f8771670543a5ec4cf822877137 100644 (file)
@@ -1,5 +1,5 @@
 USING: unicode.normalize kernel tools.test sequences
-unicode.data io.encodings.utf8 io.files splitting math.parser
+simple-flat-file io.encodings.utf8 io.files splitting math.parser
 locals math quotations assocs combinators unicode.normalize.private ;
 IN: unicode.normalize.tests
 
@@ -23,9 +23,8 @@ IN: unicode.normalize.tests
 [ "\u00d55c" ] [ "\u001112\u001161\u0011ab" nfc ] unit-test
 
 : parse-test ( -- tests )
-    "vocab:unicode/normalize/NormalizationTest.txt"
-    utf8 file-lines filter-comments
-    [ ";" split 5 head [ " " split [ hex> ] "" map-as ] map ] map ;
+    "vocab:unicode/normalize/NormalizationTest.txt" data
+    [ 5 head [ " " split [ hex> ] "" map-as ] map ] map ;
 
 :: assert= ( test spec quot -- )
     spec [
index 6612825c21eb971f833ee9783df862e62041f8ec..2860f83befd02f51143800755f324501859e9165 100644 (file)
@@ -1,6 +1,14 @@
-USING: help.syntax help.markup ;\r
+! Copyright (C) 2009 Daniel Ehrenberg\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: help.syntax help.markup strings ;\r
 IN: unicode.script\r
 \r
+ABOUT: "unicode.script"\r
+\r
+ARTICLE: "unicode.script" "Unicode script properties"\r
+"The unicode standard gives every character a script. Note that this is different from a language, and that it is non-trivial to detect language from a string. To get the script of a character, use"\r
+{ $subsection script-of } ;\r
+\r
 HELP: script-of\r
-{ $values { "char" "a code point" } { "script" "a symbol" } }\r
-{ $description "Gets a symbol representing the code point of a given character. The word name of the symbol is the same as the one " } ;\r
+{ $values { "char" "a code point" } { "script" string } }\r
+{ $description "Finds the script of the given Unicode code point, represented as a string." } ;\r
index 383f9e3de3ca4c225325af461283327d29e1f888..ed804760848a07c8c275b4e6dbce4c3d719678e4 100644 (file)
@@ -7,10 +7,14 @@ words words.symbol compiler.units arrays interval-maps
 unicode.data ;
 IN: unicode.script
 
+<PRIVATE
+
 VALUE: script-table
 
-"vocab:unicode/script/Scripts.txt" load-script
+"vocab:unicode/script/Scripts.txt" load-key-value
 to: script-table
 
+PRIVATE>
+
 : script-of ( char -- script )
     script-table interval-at ;
index b7ac022d0e1cc7cc49261d3a7340ff5a3ec40caf..5bd8c05e153103658a6df5b25afdb10c49f503fa 100644 (file)
@@ -5,22 +5,7 @@ bit-arrays namespaces make sequences.private arrays quotations
 assocs classes.predicate math.order strings.parser ;
 IN: unicode.syntax
 
-! Character classes (categories)
-
-: category# ( char -- category )
-    ! There are a few characters that should be Cn
-    ! that this gives Cf or Mn
-    ! Cf = 26; Mn = 5; Cn = 29
-    ! Use a compressed array instead?
-    dup category-map ?nth [ ] [
-        dup HEX: E0001 HEX: E007F between?
-        [ drop 26 ] [
-            HEX: E0100 HEX: E01EF between?  5 29 ?
-        ] if
-    ] ?if ;
-
-: category ( char -- category )
-    category# categories nth ;
+<PRIVATE
 
 : >category-array ( categories -- bitarray )
     categories [ swap member? ] with map >bit-array ;
@@ -40,6 +25,8 @@ IN: unicode.syntax
 : define-category ( word categories -- )
     [category] integer swap define-predicate-class ;
 
+PRIVATE>
+
 : CATEGORY:
     CREATE ";" parse-tokens define-category ; parsing
 
index 437a9419e39131a2b67d6c33974b97b243cc0312..707caf31880bb6275ea71c3d8f6c7a783ef0b690 100644 (file)
@@ -82,9 +82,9 @@ HELP: parse-host
 { $notes "This word is used by " { $link >url } ". It can also be used directly to parse " { $snippet "host:port" } " strings which are not full URLs." }
 { $examples
     { $example
-        "USING: prettyprint urls kernel ;"
-        "\"sbcl.org:80\" parse-host .s 2drop"
-        "\"sbcl.org\"\n80"
+        "USING: arrays kernel prettyprint urls ;"
+        "\"sbcl.org:80\" parse-host 2array ."
+        "{ \"sbcl.org\" 80 }"
     }
 } ;
 
index fe4762acbe686d1edb84135b7ca58fb224c627eb..63482ff706f12097aa6972c82d5ccd1f57476fb4 100644 (file)
@@ -3,7 +3,7 @@
 USING: kernel namespaces xml.name io.encodings.utf8 xml.elements
 io.encodings.utf16 xml.tokenize xml.state math ascii sequences
 io.encodings.string io.encodings combinators accessors
-xml.data io.encodings.iana ;
+xml.data io.encodings.iana xml.errors ;
 IN: xml.autoencoding
 
 : decode-stream ( encoding -- )
@@ -35,7 +35,10 @@ IN: xml.autoencoding
 
 : prolog-encoding ( prolog -- )
     encoding>> dup "UTF-16" =
-    [ drop ] [ name>encoding [ decode-stream ] when* ] if ;
+    [ drop ] [
+        dup name>encoding
+        [ decode-stream ] [ bad-encoding ] ?if
+    ] if ;
 
 : instruct-encoding ( instruct/prolog -- )
     dup prolog?
index 8a469bc08fbe0d3f598b822e4b983d37d6ef6271..10d7bb63ca5b6e0628008941cee884da1f79c83b 100644 (file)
@@ -1,5 +1,5 @@
 USING: continuations xml xml.errors tools.test kernel arrays
-xml.data quotations fry ;
+xml.data quotations fry byte-arrays ;
 IN: xml.errors.tests
 
 : xml-error-test ( expected-error xml-string -- )
@@ -40,3 +40,4 @@ T{ bad-doctype f 1 22 T{ opener { name T{ name f "" "foo" "" } } { attrs T{ attr
 T{ disallowed-char f 1 4 1 } "<x>\u000001</x>" xml-error-test
 T{ missing-close f 1 8 } "<!-- foo" xml-error-test
 T{ misplaced-directive f 1 9 "ENTITY" } "<!ENTITY foo 'bar'><x/>" xml-error-test
+[ "<?xml version='1.0' encoding='foobar'?>" >byte-array bytes>xml ] [ T{ bad-encoding f 1 39 "foobar" } = ] must-fail-with
index 35111f5a54473cfb2ae9bcb43b9aa670e38db86a..7be7e074c3a26fa07202e5c983ba4a6cb06b9720 100644 (file)
@@ -338,5 +338,14 @@ TUPLE: bad-doctype < xml-error-at contents ;
 M: bad-doctype summary
     call-next-method "\nDTD contains invalid object" append ;
 
+TUPLE: bad-encoding < xml-error-at encoding ;
+: bad-encoding ( encoding -- * )
+    \ bad-encoding xml-error-at
+        swap >>encoding
+    throw ;
+M: bad-encoding summary
+    call-next-method
+    "\nEncoding in XML document does not exist" append ;
+
 UNION: xml-error
     multitags notags pre/post-content xml-error-at ;
index cb4a0b50aa9c78f176f162ce25705ced54d78911..4241999bcd221c89f1faf620823575d85d187aa9 100644 (file)
@@ -27,20 +27,18 @@ combinators vocabs.parser grouping ;
 
 IN: vocabs.loader.test.2
 
-: hello 3 ;
+: hello ( -- ) ;
 
 MAIN: hello
 
 IN: vocabs.loader.tests
 
-[ { 3 3 3 } ] [
+[ ] [
     "vocabs.loader.test.2" run
     "vocabs.loader.test.2" vocab run
     "vocabs.loader.test.2" <vocab-link> run
-    3array
 ] unit-test
 
-
 [
     "resource:core/vocabs/loader/test/a/a.factor" forget-source
     "vocabs.loader.test.a" forget-vocab
index fbdfa9c66bb41397f312da904873c51c41efbf1b..be9835c5b9bec8d819800750356089defc51dcae 100644 (file)
@@ -49,7 +49,7 @@ PRIVATE>
     in-advice? get [ "ad-do-it should only be called inside 'around' advice" throw ] unless coyield ;
     
 : make-advised ( word -- )
-    [ dup [ over dup '[ _ call-before _ _ call-around _ call-after ] ] annotate ]
+    [ dup '[ [ _ ] dip over dup '[ _ call-before _ _ call-around _ call-after ] ] annotate ]
     [ { before after around } [ <linked-hash> swap set-word-prop ] with each ] 
     [ t advised set-word-prop ] tri ;
 
diff --git a/extra/benchmark/regex-dna/deploy.factor b/extra/benchmark/regex-dna/deploy.factor
new file mode 100644 (file)
index 0000000..91edab4
--- /dev/null
@@ -0,0 +1,15 @@
+USING: tools.deploy.config ;
+H{
+    { deploy-word-defs? f }
+    { deploy-word-props? f }
+    { deploy-math? f }
+    { deploy-compiler? t }
+    { deploy-ui? f }
+    { deploy-c-types? f }
+    { "stop-after-last-window?" t }
+    { deploy-reflection 1 }
+    { deploy-name "benchmark.regex-dna" }
+    { deploy-io 2 }
+    { deploy-threads? f }
+    { deploy-unicode? f }
+}
index 5c11be357f790e8386b02cc50c9482a92ad9d2fa..24e77597831e5f180a64ef74eacaf5199d8156a3 100644 (file)
@@ -1,7 +1,7 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors prettyprint io io.encodings.ascii
-io.files kernel sequences assocs namespaces regexp ;
+USING: accessors io io.encodings.ascii io.files kernel sequences
+assocs math.parser namespaces regexp ;
 IN: benchmark.regex-dna
 
 ! Based on http://shootout.alioth.debian.org/gp4/benchmark.php?test=regexdna&lang=ruby&id=1
@@ -22,7 +22,7 @@ IN: benchmark.regex-dna
         R/ agggtaa[cgt]|[acg]ttaccct/i
     } [
         [ raw>> write bl ]
-        [ count-matches . ]
+        [ count-matches number>string print ]
         bi
     ] with each ;
 
@@ -50,9 +50,9 @@ SYMBOL: clen
     dup count-patterns
     do-replacements
     nl
-    ilen get .
-    clen get .
-    length . ;
+    ilen get number>string print
+    clen get number>string print
+    length number>string print ;
 
 : regex-dna-main ( -- )
     "resource:extra/benchmark/regex-dna/regex-dna-test-in.txt" regex-dna ;
index 1e49be9a608d38038a1a8c57a7641dda8e8b73a4..de4345db689e8f3dfc5b5b395c007a46c20f5042 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.ranges sequences ;
+USING: kernel math math.ranges sequences project-euler.common ;
 IN: project-euler.001
 
 ! http://projecteuler.net/index.php?section=problems&id=1
@@ -51,4 +51,4 @@ PRIVATE>
 ! [ euler001b ] 100 ave-time
 ! 0 ms run / 0 ms GC ave time - 100 trials
 
-MAIN: euler001
+SOLUTION: euler001
index 136ebbb6da79a76d64d08d6517072b890aaae7c8..9995e434e7cec04337409aa2c633f36f757e71b3 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer, Alexander Solovyov, Vishal Talwar.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math sequences ;
+USING: kernel math sequences project-euler.common ;
 IN: project-euler.002
 
 ! http://projecteuler.net/index.php?section=problems&id=2
@@ -77,4 +77,4 @@ PRIVATE>
 ! [ euler002b ] 100 ave-time
 ! 0 ms ave run time - 0.0 SD (100 trials)
 
-MAIN: euler002b
+SOLUTION: euler002b
index 09374bcee302d26c26b4e01bc00e5a5460e25a40..36dc862de68eb66e0645d36e7d80ddc4ca8dec90 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: math.primes.factors sequences ;
+USING: math.primes.factors sequences project-euler.common ;
 IN: project-euler.003
 
 ! http://projecteuler.net/index.php?section=problems&id=3
@@ -22,4 +22,4 @@ IN: project-euler.003
 ! [ euler003 ] 100 ave-time
 ! 1 ms ave run time - 0.49 SD (100 trials)
 
-MAIN: euler003
+SOLUTION: euler003
index e1918f5fa6b5fb92b1a6f36e01b5852ac5a2584b..ff62b4e18151485d8d263f498063dfb35de497f3 100644 (file)
@@ -34,4 +34,4 @@ PRIVATE>
 ! [ euler004 ] 100 ave-time
 ! 1164 ms ave run time - 39.35 SD (100 trials)
 
-MAIN: euler004
+SOLUTION: euler004
index 8b446f237628f8545c1e1454ea0b1c5f7b071c8c..7fef29a6b9d73be55a9c70923485db6c50df537e 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: math math.functions sequences ;
+USING: math math.functions sequences project-euler.common ;
 IN: project-euler.005
 
 ! http://projecteuler.net/index.php?section=problems&id=5
@@ -23,4 +23,4 @@ IN: project-euler.005
 ! [ euler005 ] 100 ave-time
 ! 0 ms ave run time - 0.14 SD (100 trials)
 
-MAIN: euler005
+SOLUTION: euler005
index 21493536583ae4a4287c602adde37f9e645e78df..00a5c447713e87b36b3d46c8828ba8209e481777 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.ranges sequences ;
+USING: kernel math math.ranges sequences project-euler.common ;
 IN: project-euler.006
 
 ! http://projecteuler.net/index.php?section=problems&id=6
@@ -40,4 +40,4 @@ PRIVATE>
 ! [ euler006 ] 100 ave-time
 ! 0 ms ave run time - 0.24 SD (100 trials)
 
-MAIN: euler006
+SOLUTION: euler006
index f40108e4d7105ff2b98453d4a07c2ba7da61f978..f9208e11b3a7fb3a613ceca976a9efe018cb3901 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.lists ;
+USING: lists math math.primes.lists project-euler.common ;
 IN: project-euler.007
 
 ! http://projecteuler.net/index.php?section=problems&id=7
@@ -26,4 +26,4 @@ IN: project-euler.007
 ! [ euler007 ] 100 ave-time
 ! 5 ms ave run time - 1.13 SD (100 trials)
 
-MAIN: euler007
+SOLUTION: euler007
index 1e8dade646d603ff2460d6c879ba7572f8b2889c..dcc669b125be518c03482baa1e3edb53f4faf2c4 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: grouping math.order math.parser sequences ;
+USING: grouping math.order math.parser sequences project-euler.common ;
 IN: project-euler.008
 
 ! http://projecteuler.net/index.php?section=problems&id=8
@@ -69,4 +69,4 @@ PRIVATE>
 ! [ euler008 ] 100 ave-time
 ! 2 ms ave run time - 0.79 SD (100 trials)
 
-MAIN: euler008
+SOLUTION: euler008
index a1040d2bf2687a6a5f4c33008fada47acd97619e..f75950520d810b60efc29aa80a73eff96f266cbe 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel make math sequences sorting ;
+USING: kernel make math sequences sorting project-euler.common ;
 IN: project-euler.009
 
 ! http://projecteuler.net/index.php?section=problems&id=9
@@ -50,4 +50,4 @@ PRIVATE>
 ! [ euler009 ] 100 ave-time
 ! 1 ms ave run time - 0.73 SD (100 trials)
 
-MAIN: euler009
+SOLUTION: euler009
index 593f9cc0e898fc6dd19e09c907a8708bd49253ab..648699e1dbd0a9c9405709769fdae5501515f816 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007 Aaron Schaefer, Samuel Tardieu.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: math.primes sequences ;
+USING: math.primes sequences project-euler.common ;
 IN: project-euler.010
 
 ! http://projecteuler.net/index.php?section=problems&id=10
@@ -22,4 +22,4 @@ IN: project-euler.010
 ! [ euler010 ] 100 ave-time
 ! 15 ms ave run time - 0.41 SD (100 trials)
 
-MAIN: euler010
+SOLUTION: euler010
index 122eec2c2e6904c1dfc6a9cf7fb38b98e0d6aea0..9d98ac67668817bbf2cdc514fdcabaaa2dfd602f 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: grouping kernel make math.order sequences ;
+USING: grouping kernel make math.order sequences project-euler.common ;
 IN: project-euler.011
 
 ! http://projecteuler.net/index.php?section=problems&id=11
@@ -101,4 +101,4 @@ PRIVATE>
 ! [ euler011 ] 100 ave-time
 ! 3 ms ave run time - 0.77 SD (100 trials)
 
-MAIN: euler011
+SOLUTION: euler011
index ff482c6812ca3a7cd154a9afeeac06c6d29d79d8..d2679f6309eade32c9880dc7bbb410cf5f388a07 100644 (file)
@@ -39,4 +39,4 @@ IN: project-euler.012
 ! [ euler012 ] 10 ave-time
 ! 6573 ms ave run time - 346.27 SD (10 trials)
 
-MAIN: euler012
+SOLUTION: euler012
index 857bd62cc40c7bce093c8796396a8c3b73aa282b..25aad2d749223f1d86d06f72f8b90a3e34d4e7f6 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: math.parser sequences ;
+USING: math.parser sequences project-euler.common ;
 IN: project-euler.013
 
 ! http://projecteuler.net/index.php?section=problems&id=13
@@ -230,4 +230,4 @@ PRIVATE>
 ! [ euler013 ] 100 ave-time
 ! 0 ms ave run time - 0.31 SD (100 trials)
 
-MAIN: euler013
+SOLUTION: euler013
index e93e3d11bc803019d601fc4844cc3cd8a3c05ced..a9a8dbce3f16fd7682dc46718dc6ace7b19e0a30 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: combinators.short-circuit kernel make math math.ranges sequences ;
+USING: combinators.short-circuit kernel make math math.ranges
+sequences project-euler.common ;
 IN: project-euler.014
 
 ! http://projecteuler.net/index.php?section=problems&id=14
@@ -72,4 +73,4 @@ PRIVATE>
 
 ! TODO: try using memoization
 
-MAIN: euler014a
+SOLUTION: euler014a
index fb720c7e7c76545484921e6d267ee9f4e0ad6b72..03823deab41d378e5ffa0a79dcd96bcb7db3c775 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.combinatorics ;
+USING: kernel math math.combinatorics project-euler.common ;
 IN: project-euler.015
 
 ! http://projecteuler.net/index.php?section=problems&id=15
@@ -30,4 +30,4 @@ PRIVATE>
 ! [ euler015 ] 100 ave-time
 ! 0 ms ave run time - 0.2 SD (100 trials)
 
-MAIN: euler015
+SOLUTION: euler015
index 216fcb3523382cd33d62ffd72f7ad1911aafbaa2..b81619b980df6bcd3b75038c31e00b9dc2b9bfb0 100644 (file)
@@ -22,4 +22,4 @@ IN: project-euler.016
 ! [ euler016 ] 100 ave-time
 ! 0 ms ave run time - 0.67 SD (100 trials)
 
-MAIN: euler016
+SOLUTION: euler016
index 21e277da00455db69539965a2a0b1d6969288d45..53513691ff795147030153c9568818e9042a7d0e 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (c) 2007, 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: ascii kernel math.ranges math.text.english sequences ;
+USING: ascii kernel math.ranges math.text.english sequences
+project-euler.common ;
 IN: project-euler.017
 
 ! http://projecteuler.net/index.php?section=problems&id=17
@@ -28,4 +29,4 @@ IN: project-euler.017
 ! [ euler017 ] 100 ave-time
 ! 15 ms ave run time - 1.71 SD (100 trials)
 
-MAIN: euler017
+SOLUTION: euler017
index 21831b90d49b1217735a9f183dc2dd726757e231..a4aded7096c28bac286382f637e15a3f9065b5a2 100644 (file)
@@ -86,4 +86,4 @@ PRIVATE>
 ! [ euler018a ] 100 ave-time
 ! 0 ms ave run time - 0.39 SD (100 trials)
 
-MAIN: euler018a
+SOLUTION: euler018a
index 4b750ac1805bb11aa9e7b3323e802be8276cd03e..fc9cdacad794ee00615395fef42884e1dff3c297 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2007 Samuel Tardieu, Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: calendar combinators kernel math math.ranges namespaces sequences
-    math.order ;
+    math.order project-euler.common ;
 IN: project-euler.019
 
 ! http://projecteuler.net/index.php?section=problems&id=19
@@ -63,4 +63,4 @@ PRIVATE>
 ! [ euler019a ] 100 ave-time
 ! 17 ms ave run time - 2.13 SD (100 trials)
 
-MAIN: euler019
+SOLUTION: euler019
index e75747b57c80dd3d70a5e68015c615e76ff31c31..85aeebb5adc1c5d95282c13b79c4999b0a5eaef0 100644 (file)
@@ -22,4 +22,4 @@ IN: project-euler.020
 ! [ euler020 ] 100 ave-time
 ! 0 ms ave run time - 0.55 (100 trials)
 
-MAIN: euler020
+SOLUTION: euler020
index 55060a7c71aeb442004aede598864f58921fb047..0401aad9be97579003073d1cf2887543989869ef 100644 (file)
@@ -35,4 +35,4 @@ IN: project-euler.021
 ! [ euler021 ] 100 ave-time
 ! 335 ms ave run time - 18.63 SD (100 trials)
 
-MAIN: euler021
+SOLUTION: euler021
index a12838406ab6d8f9fe973d3ab6b4fa03eaff7c12..1b675d41c47333ff9171c85a652ae12ca873b70a 100644 (file)
@@ -42,4 +42,4 @@ PRIVATE>
 ! [ euler022 ] 100 ave-time
 ! 74 ms ave run time - 5.13 SD (100 trials)
 
-MAIN: euler022
+SOLUTION: euler022
index 80aa40f449bbe9f8d61bd66a12dda1a6722ef887..7c28ebfa6cd9aacac09ac74c6e9c6e47bf91e85d 100644 (file)
@@ -58,4 +58,4 @@ PRIVATE>
 ! [ euler023 ] time
 ! 52780 ms run / 3839 ms GC
 
-MAIN: euler023
+SOLUTION: euler023
index c10ce418c4e471cefe8b7730c7a7ae18ce82a1ea..f6b4d497c070ae45150178a0166e5b42e1c09717 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math.combinatorics math.parser ;
+USING: kernel math.combinatorics math.parser project-euler.common ;
 IN: project-euler.024
 
 ! http://projecteuler.net/index.php?section=problems&id=24
@@ -28,4 +28,4 @@ IN: project-euler.024
 ! [ euler024 ] 100 ave-time
 ! 0 ms ave run time - 0.27 SD (100 trials)
 
-MAIN: euler024
+SOLUTION: euler024
index a2934c23c71f8c5771e07c7e3c41e3b8369d3863..80a933dc63a74a106aca65fbd1dcdf2b7a4e4188 100644 (file)
@@ -78,4 +78,4 @@ PRIVATE>
 ! [ euler025a ] 100 ave-time
 ! 0 ms ave run time - 0.17 SD (100 trials)
 
-MAIN: euler025a
+SOLUTION: euler025a
index cf30d0ee4288a8793a9663bc96a1b4ac87c59ffd..8e0cf37fa2724b6ad466989052747d93c0d6812e 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions math.primes math.ranges sequences ;
+USING: kernel math math.functions math.primes math.ranges sequences project-euler.common ;
 IN: project-euler.026
 
 ! http://projecteuler.net/index.php?section=problems&id=26
@@ -68,4 +68,4 @@ PRIVATE>
 ! [ euler026 ] 100 ave-time
 ! 290 ms ave run time - 19.2 SD (100 trials)
 
-MAIN: euler026
+SOLUTION: euler026
index 5bf753074e4c05295e39f9ad4dd5d7d7d85d98ca..4bcfb66a9405d73726179abfbca50f8d673c20ee 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.primes project-euler.common sequences ;
+USING: kernel math math.primes project-euler.common sequences
+project-euler.common ;
 IN: project-euler.027
 
 ! http://projecteuler.net/index.php?section=problems&id=27
@@ -72,4 +73,4 @@ PRIVATE>
 
 ! TODO: generalize max-consecutive/max-product (from #26) into a new word
 
-MAIN: euler027
+SOLUTION: euler027
index cd359c70a9bbadde9b0c124d2d5724cbc7bfd7ea..6dc284f802150b8dac480874ef51592b4fc1bb23 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.ranges sequences ;
+USING: kernel math math.ranges sequences project-euler.common ;
 IN: project-euler.028
 
 ! http://projecteuler.net/index.php?section=problems&id=28
@@ -43,4 +43,4 @@ PRIVATE>
 ! [ euler028 ] 100 ave-time
 ! 0 ms ave run time - 0.39 SD (100 trials)
 
-MAIN: euler028
+SOLUTION: euler028
index 2586e6182ae4c9eaaf18eab6a4a0c0ee336b2e4c..73773e1887d146ab5e83b77e0883b64e03d0cb75 100644 (file)
@@ -34,4 +34,4 @@ IN: project-euler.029
 ! [ euler029 ] 100 ave-time
 ! 704 ms ave run time - 28.07 SD (100 trials)
 
-MAIN: euler029
+SOLUTION: euler029
index 63693f96d8a38f2119e9cf475f2432a5701083d5..54d48660d5af251e7caf7124892f12c0bebd9122 100644 (file)
@@ -43,4 +43,4 @@ PRIVATE>
 ! [ euler030 ] 100 ave-time
 ! 1700 ms ave run time - 64.84 SD (100 trials)
 
-MAIN: euler030
+SOLUTION: euler030
index 1b6d1c83eb26a75eb1b2f61c283d6b619189951d..f5648721498d301199f572c877efe6988df542f3 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math ;
+USING: kernel math project-euler.common ;
 IN: project-euler.031
 
 ! http://projecteuler.net/index.php?section=problems&id=31
@@ -60,4 +60,4 @@ PRIVATE>
 
 ! TODO: generalize to eliminate duplication; use a sequence to specify denominations?
 
-MAIN: euler031
+SOLUTION: euler031
index 07c643659c723c911b74e0b17022869db43cdd14..5ff5234679c318fbaf47874f9e9e3e5424c05c3c 100755 (executable)
@@ -75,4 +75,4 @@ PRIVATE>
 ! [ euler032a ] 10 ave-time
 ! 2624 ms ave run time - 131.91 SD (10 trials)
 
-MAIN: euler032a
+SOLUTION: euler032a
index d0c79c220a151e2e2ae0bdb093bb65bc218a2084..c7c3fea5da7d52e6e100776d2f03e131e1202e98 100644 (file)
@@ -52,4 +52,4 @@ PRIVATE>
 ! [ euler033 ] 100 ave-time
 ! 7 ms ave run time - 1.31 SD (100 trials)
 
-MAIN: euler033
+SOLUTION: euler033
index 11b7efa8b55fedae275d5b4fd11ef4458510e07f..f7a4865da7aea861aa52fed58245a3b040498add 100644 (file)
@@ -44,4 +44,4 @@ PRIVATE>
 ! [ euler034 ] 10 ave-time
 ! 5506 ms ave run time - 144.0 SD (10 trials)
 
-MAIN: euler034
+SOLUTION: euler034
index 517e5211d20e4d1461b7c145406f5ed4c296159b..378461842312e15d9f4815690281e5abc03e6c8a 100755 (executable)
@@ -58,4 +58,4 @@ PRIVATE>
 ! TODO: try using bit arrays or other methods outlined here:
 !     http://home.comcast.net/~babdulbaki/Circular_Primes.html
 
-MAIN: euler035
+SOLUTION: euler035
index f5afeceb21fd3858af6b727fa875f5f5492a5a5a..e6c257969e60ac8624be1e7c8f52a103cb8c65eb 100644 (file)
@@ -36,4 +36,4 @@ PRIVATE>
 ! [ euler036 ] 100 ave-time
 ! 1703 ms ave run time - 96.6 SD (100 trials)
 
-MAIN: euler036
+SOLUTION: euler036
index 4562c4588f90c7f559455cf85dcb651a3dff62a7..e59f506962127c33e90511122312e0eb3dc81041 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.parser math.primes sequences ;
+USING: kernel math math.parser math.primes sequences project-euler.common ;
 IN: project-euler.037
 
 ! http://projecteuler.net/index.php?section=problems&id=37
@@ -49,4 +49,4 @@ PRIVATE>
 ! [ euler037 ] 100 ave-time
 ! 130 ms ave run time - 6.27 SD (100 trials)
 
-MAIN: euler037
+SOLUTION: euler037
index 2df993b341dda71ca60781fa780be60fe1d90d9c..3c6e2eac0275d365a452b4b816344c4f2b841984 100755 (executable)
@@ -53,4 +53,4 @@ PRIVATE>
 ! [ euler038 ] 100 ave-time
 ! 11 ms ave run time - 1.5 SD (100 trials)
 
-MAIN: euler038
+SOLUTION: euler038
index 6b5601566762f0e0be2721afef150948594abd44..dee3f9804c15dde9c4ebd4d579c82e513297b71d 100755 (executable)
@@ -62,4 +62,4 @@ PRIVATE>
 ! [ euler039 ] 100 ave-time
 ! 1 ms ave run time - 0.37 SD (100 trials)
 
-MAIN: euler039
+SOLUTION: euler039
index 6b8a3f267ac59321573886fdb00bc5e0e180ff5d..86fb34629e03ba974b1ff85eb7eb975638d86306 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.parser sequences strings ;
+USING: kernel math math.parser sequences strings project-euler.common ;
 IN: project-euler.040
 
 ! http://projecteuler.net/index.php?section=problems&id=40
@@ -48,4 +48,4 @@ PRIVATE>
 ! [ euler040 ] 100 ave-time
 ! 444 ms ave run time - 23.64 SD (100 trials)
 
-MAIN: euler040
+SOLUTION: euler040
index d6d428a11f5a191c1440d1e70ad90e51771bebca..751ddd345052beddbdbd871a29fef2e55bf1a7d1 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math.combinatorics math.parser math.primes sequences ;
+USING: kernel math.combinatorics math.parser math.primes sequences project-euler.common ;
 IN: project-euler.041
 
 ! http://projecteuler.net/index.php?section=problems&id=41
@@ -37,4 +37,4 @@ IN: project-euler.041
 ! [ euler041 ] 100 ave-time
 ! 64 ms ave run time - 4.22 SD (100 trials)
 
-MAIN: euler041
+SOLUTION: euler041
index c8236db1185c2de5332ebd26fcdc91d2005669f1..8c74cc9b312a0ee67e23d2714f0e59b7cb850a34 100644 (file)
@@ -71,4 +71,4 @@ PRIVATE>
 ! [ euler042a ] 100 ave-time
 ! 21 ms ave run time - 2.2 SD (100 trials)
 
-MAIN: euler042a
+SOLUTION: euler042a
index 21e9ec8e60c1024facd98e59c137fb831eb44e61..7edcd14364724815a3fbd478b717082819894f9d 100644 (file)
@@ -97,4 +97,4 @@ PRIVATE>
 ! [ euler043a ] 100 ave-time
 ! 10 ms ave run time - 1.37 SD (100 trials)
 
-MAIN: euler043a
+SOLUTION: euler043a
index 46b20253ee48392458b80a3c2f63e88dcbe6a9e5..8fc979e8bcf3257627b4d07723c69be91aa24afd 100644 (file)
@@ -45,4 +45,4 @@ PRIVATE>
 
 ! TODO: this solution is ugly and not very efficient...find a better algorithm
 
-MAIN: euler044
+SOLUTION: euler044
index ca5cd83f41aba82ca15d84e5c34a3e8fc713f7a5..939b8416bb3b9083f0c7e5509d82aba37c02fb0e 100644 (file)
@@ -46,4 +46,4 @@ PRIVATE>
 ! [ euler045 ] 100 ave-time
 ! 12 ms ave run time - 1.71 SD (100 trials)
 
-MAIN: euler045
+SOLUTION: euler045
index b5ff6a9b816c2a884137658acbb1690592d26b8e..e4b8dcc955518ad86bf8f71bfbed1b4457574b3c 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions math.primes math.ranges sequences ;
+USING: kernel math math.functions math.primes math.ranges sequences project-euler.common ;
 IN: project-euler.046
 
 ! http://projecteuler.net/index.php?section=problems&id=46
@@ -49,4 +49,4 @@ PRIVATE>
 ! [ euler046 ] 100 ave-time
 ! 37 ms ave run time - 3.39 SD (100 trials)
 
-MAIN: euler046
+SOLUTION: euler046
index 9caaa8776f79c28e445d2db4b099f14d934ebbc9..e251045cd4d324970f692564e36237ba4cd031e4 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays kernel math math.primes math.primes.factors
-    math.ranges namespaces sequences ;
+    math.ranges namespaces sequences project-euler.common ;
 IN: project-euler.047
 
 ! http://projecteuler.net/index.php?section=problems&id=47
@@ -93,4 +93,4 @@ PRIVATE>
 ! TODO: I don't like that you have to specify the upper bound, maybe try making
 ! this lazy so it could also short-circuit when it finds the answer?
 
-MAIN: euler047a
+SOLUTION: euler047a
index baa1a430e86ed9d8374e3fc535f0984867c9cfc1..e56b9e9548bd99a70e19e4262234e9b183b6b3ce 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions sequences ;
+USING: kernel math math.functions sequences project-euler.common ;
 IN: project-euler.048
 
 ! http://projecteuler.net/index.php?section=problems&id=48
@@ -22,4 +22,4 @@ IN: project-euler.048
 ! [ euler048 ] 100 ave-time
 ! 276 ms run / 1 ms GC ave time - 100 trials
 
-MAIN: euler048
+SOLUTION: euler048
index f8ce68d17396d6056a81afd52903c63cbfd660a2..a97e16d0fad1273f5857ff14e4a64559c811c388 100644 (file)
@@ -87,4 +87,4 @@ PRIVATE>
 ! [ euler050 ] 100 ave-time
 ! 291 ms run / 20.6 ms GC ave time - 100 trials
 
-MAIN: euler050
+SOLUTION: euler050
index 6245a794af257dfd4f3b46b3970b8076b192521e..1b3b9ba1f11abb108413db3b5f5705d91f8d153a 100644 (file)
@@ -49,4 +49,4 @@ PRIVATE>
 ! [ euler052 ] 100 ave-time
 ! 92 ms ave run time - 6.29 SD (100 trials)
 
-MAIN: euler052
+SOLUTION: euler052
index d264bca4bff1a8b80a174551976c15aa2de98f52..111b8147fb59807cb18c03ec2e8234b92891e0e8 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.combinatorics math.ranges sequences ;
+USING: kernel math math.combinatorics math.ranges sequences project-euler.common ;
 IN: project-euler.053
 
 ! http://projecteuler.net/index.php?section=problems&id=53
@@ -32,4 +32,4 @@ IN: project-euler.053
 ! [ euler053 ] 100 ave-time
 ! 52 ms ave run time - 4.44 SD (100 trials)
 
-MAIN: euler053
+SOLUTION: euler053
index d07d0c8e31dabbcff6cdf2075e4f2b7c7b16aa6a..43f380b3ba820de37a836288f8b00fbd213eceae 100644 (file)
@@ -66,4 +66,4 @@ PRIVATE>
 ! [ euler055 ] 100 ave-time
 ! 478 ms ave run time - 30.63 SD (100 trials)
 
-MAIN: euler055
+SOLUTION: euler055
index e2d95e27c11f6f7dcf56ff1e7419eb220c69c1a6..76c275e4dde21dbabc1d3cb43061f3b9685e8cae 100644 (file)
@@ -29,4 +29,4 @@ IN: project-euler.056
 ! [ euler056 ] 100 ave-time
 ! 22 ms ave run time - 2.13 SD (100 trials)
 
-MAIN: euler056
+SOLUTION: euler056
index 53240b0ec1dbea2176deb63bebdf3910447f466c..681a17dd9ec2fe17434d74e380e77e868be72996 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Samuel Tardieu
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions math.parser sequences ;
+USING: kernel math math.functions math.parser sequences project-euler.common ;
 IN: project-euler.057
 
 ! http://projecteuler.net/index.php?section=problems&id=57
@@ -40,4 +40,4 @@ IN: project-euler.057
 ! [ euler057 ] time
 ! 3.375118 seconds
 
-MAIN: euler057
+SOLUTION: euler057
index 0abd753c0989adca62db594e097c945a7c6ac2c3..9a2fb8c868a48f1c53a7ac6de43a6edcecbb85b7 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays ascii assocs hashtables io.encodings.ascii io.files kernel math
     math.parser namespaces make sequences sequences.private sorting
-    splitting grouping strings sets accessors ;
+    splitting grouping strings sets accessors project-euler.common ;
 IN: project-euler.059
 
 ! http://projecteuler.net/index.php?section=problems&id=59
@@ -89,4 +89,4 @@ PRIVATE>
 ! [ euler059 ] 100 ave-time
 ! 8 ms ave run time - 1.4 SD (100 trials)
 
-MAIN: euler059
+SOLUTION: euler059
index 3f9d67091dad9ceef9066042b5138047ee064f1b..7f3472f306a6ff5c7c299918170fafdf7c042fd3 100644 (file)
@@ -59,4 +59,4 @@ PRIVATE>
 ! [ euler067a ] 100 ave-time
 ! 21 ms ave run time - 2.65 SD (100 trials)
 
-MAIN: euler067a
+SOLUTION: euler067a
index 69d9eb1a03cb3b11f68de14cf0ec5ad49b42de19..cccf6bf708d75735c750d85e4b5d7d2014261a5f 100644 (file)
@@ -46,4 +46,4 @@ PRIVATE>
 ! [ euler071 ] 100 ave-time
 ! 155 ms ave run time - 6.95 SD (100 trials)
 
-MAIN: euler071
+SOLUTION: euler071
index 68dcd01e0d3d93ce1abf798e40af4eca06a970ed..c7e88057226c21b4a632361fb78a65be8dc8c93a 100644 (file)
@@ -49,4 +49,4 @@ PRIVATE>
 ! [ euler073 ] 10 ave-time
 ! 20506 ms ave run time - 937.07 SD (10 trials)
 
-MAIN: euler073
+SOLUTION: euler073
index 2b5b9311650b530fa22f274ffaf92c267823d0c3..5f54d8508e89683d64e352b1fdab0b8034877c8f 100755 (executable)
@@ -75,4 +75,4 @@ PRIVATE>
 ! [ euler075 ] 10 ave-time
 ! 3341 ms ave run timen - 157.77 SD (10 trials)
 
-MAIN: euler075
+SOLUTION: euler075
index e332d9ef3e53c40c4ba322fa793e4f800bb4e798..e6ed9035d2b72e1fd702003551d77b247ff7718d 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays assocs kernel locals math math.order math.ranges sequences ;
+USING: arrays assocs kernel locals math math.order math.ranges sequences project-euler.common ;
 IN: project-euler.076
 
 ! http://projecteuler.net/index.php?section=problems&id=76
@@ -56,4 +56,4 @@ PRIVATE>
 ! [ euler076 ] 100 ave-time
 ! 560 ms ave run time - 17.74 SD (100 trials)
 
-MAIN: euler076
+SOLUTION: euler076
index ad75c43c42772c2fe8f37bf9d3a40c84792d1b52..3ad740670312e4462f25d2bc0c3b7fe0cec156ec 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: assocs io.encodings.ascii io.files kernel make math math.parser
-    sequences sets ;
+    sequences sets project-euler.common ;
 IN: project-euler.079
 
 ! http://projecteuler.net/index.php?section=problems&id=79
@@ -63,4 +63,4 @@ PRIVATE>
 ! TODO: prune and diff are relatively slow; topological sort could be
 ! cleaned up and generalized much better, but it works for this problem
 
-MAIN: euler079
+SOLUTION: euler079
index c778fd952556f1406efd6dfb3f0482a5f7a92682..4901eae3428af4eb4f058a563b862d90a2d4a1b5 100644 (file)
@@ -50,4 +50,4 @@ PRIVATE>
 
 ! TODO: this solution is not very efficient, much better optimizations exist
 
-MAIN: euler092
+SOLUTION: euler092
index 6e6547a7e961e563d670ecff987fab769313e5de..a8895c215a0113e8c700825ba0ca7363fc6e5fcb 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: math math.functions ;
+USING: math math.functions project-euler.common ;
 IN: project-euler.097
 
 ! http://projecteuler.net/index.php?section=problems&id=97
@@ -28,4 +28,4 @@ IN: project-euler.097
 ! [ euler097 ] 100 ave-time
 ! 0 ms ave run timen - 0.22 SD (100 trials)
 
-MAIN: euler097
+SOLUTION: euler097
index ebc830cf0026f94d5c2fd687a7a77d824caa4d68..30bf52bebbf56867f719417d4965e4bdbbc99baf 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io.encodings.ascii io.files kernel math math.functions math.parser
-    math.vectors sequences splitting ;
+    math.vectors sequences splitting project-euler.common ;
 IN: project-euler.099
 
 ! http://projecteuler.net/index.php?section=problems&id=99
@@ -49,4 +49,4 @@ PRIVATE>
 ! [ euler099 ] 100 ave-time
 ! 16 ms ave run timen - 1.67 SD (100 trials)
 
-MAIN: euler099
+SOLUTION: euler099
index ec372add3bff00f4ded9e71be8bfc223c47aeb6b..6f05eb7120846adb2a05fdcb1ad2ab95aa018bf5 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions sequences ;
+USING: kernel math math.functions sequences project-euler.common ;
 IN: project-euler.100
 
 ! http://projecteuler.net/index.php?section=problems&id=100
@@ -33,4 +33,4 @@ IN: project-euler.100
 ! [ euler100 ] 100 ave-time
 ! 0 ms ave run time - 0.14 SD (100 trials)
 
-MAIN: euler100
+SOLUTION: euler100
index 742fe9d625b324b3c9f739026041a0ad9f392f0f..174618e1471723c5b76abea869240e7be17d1c59 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.ranges sequences ;
+USING: kernel math math.ranges sequences project-euler.common ;
 IN: project-euler.116
 
 ! http://projecteuler.net/index.php?section=problems&id=116
@@ -57,4 +57,4 @@ PRIVATE>
 ! [ euler116 ] 100 ave-time
 ! 0 ms ave run time - 0.34 SD (100 trials)
 
-MAIN: euler116
+SOLUTION: euler116
index b90a98173ee887f8286e56ac9c586734c19310c9..cb485d3ce237fbef8b8fff6d32c19a73cc2e5b9a 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.order sequences splitting ;
+USING: kernel math math.order sequences splitting project-euler.common ;
 IN: project-euler.117
 
 ! http://projecteuler.net/index.php?section=problems&id=117
@@ -41,4 +41,4 @@ PRIVATE>
 ! [ euler117 ] 100 ave-time
 ! 0 ms ave run time - 0.29 SD (100 trials)
 
-MAIN: euler117
+SOLUTION: euler117
index 0f009919d9ddde0c399627540d54839e4d3c2caf..ef1cf30dc0e22576d0c2fd3d643e6687a61b29d4 100644 (file)
@@ -45,4 +45,4 @@ PRIVATE>
 ! [ euler134 ] 10 ave-time
 ! 933 ms ave run timen - 19.58 SD (10 trials)
 
-MAIN: euler134
+SOLUTION: euler134
index 5aa0299dda1a7b8b904beb355376e6dbfcb0ea79..582e103e56538a67579b1e680b6cef9ea2b0ec28 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions sequences ;
+USING: kernel math math.functions sequences project-euler.common ;
 IN: project-euler.148
 
 ! http://projecteuler.net/index.php?section=problems&id=148
@@ -51,4 +51,4 @@ PRIVATE>
 ! [ euler148 ] 100 ave-time
 ! 0 ms ave run time - 0.17 SD (100 trials)
 
-MAIN: euler148
+SOLUTION: euler148
index 1b84b25d37a1b27dedaec1731dd396102b431a2e..e013e165751fc7128e4ee3b71b2833052bbef935 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: hints kernel locals math math.order sequences sequences.private ;
+USING: hints kernel locals math math.order sequences sequences.private project-euler.common ;
 IN: project-euler.150
 
 ! http://projecteuler.net/index.php?section=problems&id=150
@@ -75,4 +75,4 @@ PRIVATE>
 ! [ euler150 ] 10 ave-time
 ! 30208 ms ave run time - 593.45 SD (10 trials)
 
-MAIN: euler150
+SOLUTION: euler150
index 7913cf954012924ab3976a44c7286b5b9a1cd5bc..66c5a6301edad0832b9f3e56a77db20bbc73d1e1 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: assocs combinators kernel math math.order namespaces sequences ;
+USING: assocs combinators kernel math math.order namespaces sequences project-euler.common ;
 IN: project-euler.151
 
 ! http://projecteuler.net/index.php?section=problems&id=151
@@ -76,4 +76,4 @@ DEFER: (euler151)
 ! [ euler151 ] 100 ave-time
 ! ? ms run time - 100 trials
 
-MAIN: euler151
+SOLUTION: euler151
index 5bc4fdc74e3026162e52c9f45c9fc1fa9dd77475..cea1472c0bf67095ce32fb0b9803367361044df1 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays assocs kernel math math.ranges sequences ;
+USING: arrays assocs kernel math math.ranges sequences project-euler.common ;
 IN: project-euler.164
 
 ! http://projecteuler.net/index.php?section=problems&id=164
@@ -35,4 +35,4 @@ PRIVATE>
 ! [ euler164 ] 100 ave-time
 ! 7 ms ave run time - 1.23 SD (100 trials)
 
-MAIN: euler164
+SOLUTION: euler164
index ef43fc3c340cdc97b5883ac19828f1d4fa61757d..5f0b853f0db998207cbe1d9787bdd85fc4cc7bef 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2007 Samuel Tardieu.
 ! See http://factorcode.org/license.txt for BSD license.
 IN: project-euler.169
-USING: combinators kernel math math.functions memoize ;
+USING: combinators kernel math math.functions memoize project-euler.common ;
 
 ! http://projecteuler.net/index.php?section=problems&id=169
 
@@ -39,4 +39,4 @@ MEMO: fn ( n -- x )
 ! [ euler169 ] 100 ave-time
 ! 0 ms ave run time - 0.2 SD (100 trials)
 
-MAIN: euler169
+SOLUTION: euler169
index 757dfb017a223b339586fb3153a19e50f15ca9a8..3fbef562eba2c9652fc656151f1f5d85207dd0f1 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007 Samuel Tardieu.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions math.ranges sequences ;
+USING: kernel math math.functions math.ranges sequences project-euler.common ;
 IN: project-euler.173
 
 ! http://projecteuler.net/index.php?section=problems&id=173
@@ -35,4 +35,4 @@ PRIVATE>
 ! [ euler173 ] 100 ave-time
 ! 0 ms ave run time - 0.35 SD (100 trials)
 
-MAIN: euler173
+SOLUTION: euler173
index 9aebcf565cc44ab575187cf45726fb69b4bc0129..c99d670808a905f51d6b908a755dd440859b85fd 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2007 Samuel Tardieu.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: combinators kernel math math.parser math.ranges sequences vectors ;
+USING: combinators kernel math math.parser math.ranges sequences vectors project-euler.common ;
 IN: project-euler.175
 
 ! http://projecteuler.net/index.php?section=problems&id=175
@@ -55,4 +55,4 @@ PRIVATE>
 ! [ euler175 ] 100 ave-time
 ! 0 ms ave run time - 0.31 SD (100 trials)
 
-MAIN: euler175
+SOLUTION: euler175
index 679748b3c2fb694e61c38ae9bec8b13680205a42..a9e62ec3a90033659b83aff90487b0b1afc466a0 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: circular disjoint-sets kernel math math.ranges sequences ;
+USING: circular disjoint-sets kernel math math.ranges sequences project-euler.common ;
 IN: project-euler.186
 
 ! http://projecteuler.net/index.php?section=problems&id=186
@@ -73,4 +73,4 @@ IN: project-euler.186
 ! [ euler186 ] 10 ave-time
 ! 18572 ms ave run time - 796.87 SD (10 trials)
 
-MAIN: euler186
+SOLUTION: euler186
index 84ab74bb031177a7c0dddd9c3006518cb40718ec..ec52af041524405c6a4c95eaff8b9a1b021d9185 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel sequences math math.functions math.ranges locals ;
+USING: kernel sequences math math.functions math.ranges locals project-euler.common ;
 IN: project-euler.190
 
 ! http://projecteuler.net/index.php?section=problems&id=190
@@ -51,4 +51,4 @@ PRIVATE>
 ! [ euler150 ] 100 ave-time
 ! 5 ms ave run time - 1.01 SD (100 trials)
 
-MAIN: euler190
+SOLUTION: euler190
index f2b5a2e212e10ba6791686ab74d4a4dda141b98b..2f165f654889b1106d473334feddb20098738a75 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: fry kernel math math.primes.factors sequences sets ;
+USING: fry kernel math math.primes.factors sequences sets project-euler.common ;
 IN: project-euler.203
 
 ! http://projecteuler.net/index.php?section=problems&id=203
@@ -61,4 +61,4 @@ PRIVATE>
 ! [ euler203 ] 100 ave-time
 ! 12 ms ave run time - 1.6 SD (100 trials)
 
-MAIN: euler203
+SOLUTION: euler203
index 297fb69de377aa61b9c7b306cad24778802567a6..30c42cc4be2b5855a56d90556b903f1497db8d58 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel locals math ;
+USING: accessors kernel locals math project-euler.common ;
 IN: project-euler.215
 
 ! http://projecteuler.net/index.php?section=problems&id=215
@@ -89,4 +89,4 @@ PRIVATE>
 ! [ euler215 ] 100 ave-time
 ! 208 ms ave run time - 9.06 SD (100 trials)
 
-MAIN: euler215
+SOLUTION: euler215
index ac8986b3ffbef338a200a0ba625f2f34dce20184..bd50f817b6dd8b5296aa081b38b45d3ab364ee2e 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays kernel make math math.functions math.matrices math.miller-rabin
     math.order math.parser math.primes.factors math.ranges math.ratios
-    sequences sorting strings unicode.case ;
+    sequences sorting strings unicode.case parser accessors vocabs.parser
+    namespaces vocabs words quotations prettyprint ;
 IN: project-euler.common
 
 ! A collection of words used by more than one Project Euler solution
@@ -127,3 +128,10 @@ PRIVATE>
 : d-transform ( triple -- new-triple )
     { { -1 -2 -2 } { 2 1 2 } { 2 2 3 } } transform ;
 
+: SOLUTION:
+    scan-word
+    [ name>> "-main" append create-in ] keep
+    [ drop in get vocab (>>main) ]
+    [ [ . ] swap prefix (( -- )) define-declared ]
+    2bi ; parsing
+
index f5bc95a8f713f41e36920a15be1a9503e094d3cd..3d10dbcfbdcc5966d7220b08a51d8d63b78a2596 100644 (file)
@@ -44,8 +44,8 @@ PRIVATE>
 
 : run-project-euler ( -- )
     problem-prompt dup problem-solved? [
+        "Answer: " write
         dup number>euler "project-euler." prepend run
-        "Answer: " write dup number? [ number>string ] when print
         "Source: " write solution-path .
     ] [
         drop "That problem has not been solved yet..." print
index 7c1b2f22790bfdca05f14a555a40b7eaa3ce2abd..b4bd0e7b35e6a8f0d41992b7e7faba52bb7d25da 100644 (file)
@@ -1 +1 @@
-Doug Coleman
+Doug Coleman
\ No newline at end of file
diff --git a/extra/site-watcher/db/authors.txt b/extra/site-watcher/db/authors.txt
new file mode 100644 (file)
index 0000000..b4bd0e7
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
\ No newline at end of file
diff --git a/extra/site-watcher/db/db.factor b/extra/site-watcher/db/db.factor
new file mode 100644 (file)
index 0000000..0c62c7f
--- /dev/null
@@ -0,0 +1,92 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors continuations db db.sqlite db.tuples db.types
+io.directories io.files.temp kernel io.streams.string calendar
+debugger combinators.smart sequences ;
+IN: site-watcher.db
+
+TUPLE: account account-id account-name email ;
+
+: <account> ( account-name -- account )
+    account new
+        swap >>account-name ;
+
+account "ACCOUNT" {
+    { "account-name" "ACCOUNT_NAME" VARCHAR +user-assigned-id+ }
+    { "email" "EMAIL" VARCHAR }
+} define-persistent
+
+TUPLE: site site-id url up? changed? last-up error last-error ;
+
+: <site> ( url -- site )
+    site new
+        swap >>url ;
+
+site "SITE" {
+    { "site-id" "SITE_ID" INTEGER +db-assigned-id+ }
+    { "url" "URL" VARCHAR }
+    { "up?" "UP" BOOLEAN }
+    { "changed?" "CHANGED" BOOLEAN }
+    { "last-up" "LAST_UP" TIMESTAMP }
+    { "error" "ERROR" VARCHAR }
+    { "last-error" "LAST_ERROR" TIMESTAMP }
+} define-persistent
+
+TUPLE: watching-site account-name site-id ;
+
+: <watching-site> ( account-name site-id -- watching-site )
+    watching-site new
+        swap >>site-id
+        swap >>account-name ;
+
+watching-site "WATCHING_SITE" {
+    { "account-name" "ACCOUNT_NAME" VARCHAR +user-assigned-id+ }
+    { "site-id" "SITE_ID" INTEGER +user-assigned-id+ }
+} define-persistent
+
+TUPLE: reporting-site email url up? changed? last-up? error last-error ;
+
+<PRIVATE
+
+: set-notify-site-watchers ( site new-up? -- site )
+    [ over up?>> = [ t >>changed? ] unless ] keep >>up? ;
+
+: site-good ( site -- )
+    t set-notify-site-watchers
+    now >>last-up
+    f >>error
+    f >>last-error
+    update-tuple ;
+
+: site-bad ( site error -- )
+    [ error. ] with-string-writer >>error
+    f set-notify-site-watchers
+    now >>last-error
+    update-tuple ;
+
+: sites-to-report ( -- seq )
+    "select account.email, site.url, site.up, site.changed, site.last_up, site.error, site.last_error from account, site, watching_site where account.account_name = watching_site.account_name and site.site_id = watching_site.site_id and site.changed = '1'" sql-query 
+    [ [ reporting-site boa ] input<sequence ] map
+    "update site set changed = 'f';" sql-command ;
+
+: insert-site ( url -- site )
+    <site> dup select-tuple [ ] [ dup t >>up? insert-tuple ] ?if ;
+
+: insert-account ( account-name -- ) <account> insert-tuple ;
+
+: find-sites ( -- seq ) f <site> select-tuples ;
+
+: select-account/site ( username url -- account site )
+    insert-site site-id>> ;
+
+PRIVATE>
+
+: watch-site ( username url -- )
+    select-account/site <watching-site> insert-tuple ;
+
+: unwatch-site ( username url -- )
+    select-account/site <watching-site> delete-tuples ;
+
+: watching-sites ( username -- sites )
+    f <watching-site> select-tuples
+    [ site-id>> site new swap >>site-id select-tuple ] map ;
diff --git a/extra/site-watcher/site-watcher-docs.factor b/extra/site-watcher/site-watcher-docs.factor
deleted file mode 100644 (file)
index 37a1cf1..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: assocs help.markup help.syntax kernel urls alarms calendar ;
-IN: site-watcher
-
-HELP: run-site-watcher
-{ $description "Starts the site-watcher on the assoc stored in " { $link sites } "." } ;
-
-HELP: running-site-watcher
-{ $var-description "A symbol storing the alarm of a running site-watcher if started with the " { $link run-site-watcher } " word. To prevent multiple site-watchers from running, this variable is checked before allowing another site-watcher to start." } ;
-
-HELP: site-watcher-from
-{ $var-description "The email address from which site-watcher sends emails." } ;
-
-HELP: sites
-{ $var-description "A symbol storing an assoc of URLs, data about a site, and who to notify if a site goes down." } ;
-
-HELP: watch-site
-{ $values
-    { "emails" "a string containing an email address, or an array of such" }
-    { "url" url }
-}
-{ $description "Adds a new site to the watch assoc stored in " { $link sites } ", or adds email addresses to an already watched site." } ;
-
-HELP: watch-sites
-{ $values
-    { "assoc" assoc }
-    { "alarm" alarm }
-}
-{ $description "Runs the site-watcher on the input assoc and returns the alarm that times the site check loop. This alarm may be turned off with " { $link cancel-alarm } ", thus stopping the site-watcher." } ;
-
-HELP: site-watcher-frequency
-{ $var-description "A " { $link duration } " specifying how long to wait between checking sites." } ;
-
-HELP: unwatch-site
-{ $values
-    { "emails" "a string containing an email, or an array of such" }
-    { "url" url }
-}
-{ $description "Removes an email address from being notified when a site's goes down. If this email was the last one watching the site, removes the site as well." } ;
-
-HELP: delete-site
-{ $values
-    { "url" url }
-}
-{ $description "Removes a watched site from the " { $link sites } " assoc." } ;
-
-ARTICLE: "site-watcher" "Site watcher"
-"The " { $vocab-link "site-watcher" } " vocabulary monitors websites and sends email when a site goes down or comes up." $nl
-"To monitor a site:"
-{ $subsection watch-site }
-"To stop email addresses from being notified if a site's status changes:"
-{ $subsection unwatch-site }
-"To stop monitoring a site for all email addresses:"
-{ $subsection delete-site }
-"To run site-watcher using the sites variable:"
-{ $subsection run-site-watcher }
-;
-
-ABOUT: "site-watcher"
diff --git a/extra/site-watcher/site-watcher-tests.factor b/extra/site-watcher/site-watcher-tests.factor
new file mode 100644 (file)
index 0000000..68a4a44
--- /dev/null
@@ -0,0 +1,28 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: db.tuples locals site-watcher site-watcher.db
+site-watcher.private kernel db io.directories io.files.temp
+continuations db.sqlite site-watcher.db.private ;
+IN: site-watcher.tests
+
+: site-watcher-path ( -- path ) "site-watcher.db" temp-file ; inline
+
+[ site-watcher-path delete-file ] ignore-errors
+
+: with-sqlite-db ( quot -- )
+    site-watcher-path <sqlite-db> swap with-db ; inline
+
+:: fake-sites ( -- seq )
+    [
+        account ensure-table
+        site ensure-table
+        watching-site ensure-table
+
+        "erg@factorcode.org" insert-account
+        "http://asdfasdfasdfasdfqwerqqq.com" insert-site drop
+        "http://fark.com" insert-site drop
+
+        "erg@factorcode.org" "http://asdfasdfasdfasdfqwerqqq.com" watch-site
+        f <site> select-tuples
+    ] with-sqlite-db ;
+
index c538b12ed164ae341e63b90510f50146a2241eab..29a66afb13465426b9e082cae88915accabe84ee 100644 (file)
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alarms assocs calendar combinators
-continuations fry http.client io.streams.string kernel init
-namespaces prettyprint smtp arrays sequences math math.parser
-strings sets ;
+USING: accessors alarms arrays calendar combinators
+combinators.smart continuations debugger http.client
+init io.streams.string kernel locals math math.parser
+namespaces sequences site-watcher.db site-watcher.db.private smtp ;
 IN: site-watcher
 
-SYMBOL: sites
-
 SYMBOL: site-watcher-from
+"factor-site-watcher@gmail.com" site-watcher-from set-global
 
-sites [ H{ } clone ] initialize
-
-TUPLE: watching emails url last-up up? send-email? error ;
+SYMBOL: site-watcher-frequency
+10 seconds site-watcher-frequency set-global
+SYMBOL: running-site-watcher
+[ f running-site-watcher set-global ] "site-watcher" add-init-hook
 
 <PRIVATE
 
-: ?1array ( array/object -- array )
-    dup array? [ 1array ] unless ; inline
-
-: <watching> ( emails url -- watching )
-    watching new
-        swap >>url
-        swap ?1array >>emails
-        now >>last-up
-        t >>up? ;
-
-ERROR: not-watching-site url status ;
-
-: set-site-flags ( watching new-up? -- watching )
-    [ over up?>> = [ t >>send-email? ] unless ] keep >>up? ;
-
-: site-bad ( watching error -- )
-    >>error f set-site-flags drop ;
-
-: site-good ( watching -- )
-    f >>error
-    t set-site-flags
-    now >>last-up drop ;
-
-: check-sites ( assoc -- )
+: check-sites ( seq -- )
     [
-        swap '[ _ http-get 2drop site-good ] [ site-bad ] recover
-    ] assoc-each ;
+        [ dup url>> http-get 2drop site-good ] [ site-bad ] recover
+    ] each ;
 
-: site-up-email ( email watching -- email )
+: site-up-email ( email site -- email )
     last-up>> now swap time- duration>minutes 60 /mod
     [ >integer number>string ] bi@
     [ " hours, " append ] [ " minutes" append ] bi* append
     "Site was down for (at least): " prepend >>body ;
 
-: ?unparse ( string/object -- string )
-    dup string? [ unparse ] unless ; inline
+: site-down-email ( email site -- email ) error>> >>body ;
 
-: site-down-email ( email watching -- email )
-    error>> ?unparse >>body ;
-
-: send-report ( watching -- )
+: send-report ( site -- )
     [ <email> ] dip
     {
-        [ emails>> >>to ]
+        [ email>> 1array >>to ]
         [ drop site-watcher-from get "factor.site.watcher@gmail.com" or >>from ]
         [ dup up?>> [ site-up-email ] [ site-down-email ] if ]
         [ [ url>> ] [ up?>> "up" "down" ? ] bi " is " glue >>subject ]
-        [ f >>send-email? drop ]
     } cleave send-email ;
 
-: report-sites ( assoc -- )
-    [ nip send-email?>> ] assoc-filter
-    [ nip send-report ] assoc-each ;
+: send-reports ( seq -- )
+    [ ] [ [ send-report ] each ] if-empty ;
 
 PRIVATE>
 
-SYMBOL: site-watcher-frequency
-site-watcher-frequency [ 5 minutes ] initialize
-
-: watch-sites ( assoc -- alarm )
-    '[
-        _ [ check-sites ] [ report-sites ] bi
-    ] site-watcher-frequency get every ;
-
-: watch-site ( emails url -- )
-    sites get ?at [
-        [ [ ?1array ] dip append prune ] change-emails drop
-    ] [
-        <watching> dup url>> sites get set-at
-    ] if ;
-
-: delete-site ( url -- )
-    sites get delete-at ;
-
-: unwatch-site ( emails url -- )
-    [ ?1array ] dip
-    sites get ?at [
-        [ diff ] change-emails dup emails>> empty? [
-            url>> delete-site
-        ] [
-            drop
-        ] if 
-    ] [
-        nip delete-site
-    ] if ;
-
-SYMBOL: running-site-watcher
+: watch-sites ( -- )
+    find-sites check-sites sites-to-report send-reports ;
 
 : run-site-watcher ( -- )
-    running-site-watcher get-global [
-        sites get-global watch-sites running-site-watcher set-global
+    running-site-watcher get [ 
+        [ watch-sites ] site-watcher-frequency get every
+        running-site-watcher set-global 
     ] unless ;
 
-[ f running-site-watcher set-global ] "site-watcher" add-init-hook
-
-MAIN: run-site-watcher
+: stop-site-watcher ( -- )
+    running-site-watcher get [ cancel-alarm ] when* ;
diff --git a/extra/webapps/site-watcher/main.xml b/extra/webapps/site-watcher/main.xml
new file mode 100644 (file)
index 0000000..938ff09
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version='1.0' ?>
+
+<t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
+
+<p>SiteWatcher is a free service for web masters. It periodically tries fetching your web site via HTTP, and sends you an e-mail, SMS or Tweet if this fails. <t:a t:href="$site-watcher-app/list">Sign up now!</t:a></p>
+
+</t:chloe>
index 9bd1467fc7f09678736a338d1118a40b2a1a3c1e..c96a25f443f85277cf15465cbb3ccd6135d69b78 100644 (file)
@@ -2,40 +2,31 @@
 
 <t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
 
-<html>
-  <head>
-    <title>SiteWatcher</title>
-  </head>
-  <body>
-    <h1>SiteWatcher</h1>
-    <h2>It tells you if your web site goes down.</h2>
-    <table>
-      <t:bind-each t:name="sites">
-       <tr>
-         <td> <t:label t:name="url" /> </td>
-         <td> <t:button t:action="$site-watcher-app/remove" t:for="url">Remove</t:button> </td>
-       </tr>
-      </t:bind-each>
-    </table>
-    <p>
-      <t:button t:action="$site-watcher-app/check">Check now</t:button>
-    </p>
-    <hr />
-    <h3>Add a new site</h3>
-    <t:form t:action="$site-watcher-app/add">
-      <table>
-       <tr>
-         <th>URL:</th>
-         <td> <t:field t:name="url" t:size="80" /> </td>
-       </tr>
-       <tr>
-         <th>E-mail:</th>
-         <td> <t:field t:name="email" t:size="80" /> </td>
-       </tr>
-      </table>
-      <p> <button type="submit">Done</button> </p>
-    </t:form>
-  </body>
-</html>
+<p> Don't you hate it when your web site goes down, and all your users go buy that <a href="http://en.wikipedia.org/wiki/Slanket">slanket</a> from your competitor instead. Now using SiteWatcher, you can ensure this will never happen again! </p>
+
+<t:a t:href="$site-watcher-app/update-notify">Contact info</t:a>
+
+<h3>Step 2: add some sites to watch</h3>
+
+<t:form t:action="$site-watcher-app/add">
+<table>
+  <tr><th>URL:</th><td> <t:field t:name="url" t:size="80" /> <button type="submit">Done</button> </td></tr>
+</table>
+</t:form>
+
+<h3>Step 3: keep track of your sites</h3>
+
+<table border="2">
+  <tr> <th>URL</th><th></th> </tr>
+  <t:bind-each t:name="sites">
+    <tr>
+      <td> <t:label t:name="url" /> </td>
+      <td> <t:button t:action="$site-watcher-app/remove" t:for="url">Remove</t:button> </td>
+    </tr>
+  </t:bind-each>
+</table>
+<p>
+  <t:button t:action="$site-watcher-app/check">Check now</t:button>
+</p>
 
 </t:chloe>
index a71a14a37ac558e0bd360d9598aa704ae2f1ef2a..af07ccebbb83eb430614fb403ba6e605b72c6da2 100644 (file)
@@ -1,31 +1,51 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors furnace.actions furnace.alloy furnace.redirection
-html.forms http.server http.server.dispatchers namespaces site-watcher
-site-watcher.private kernel urls validators db.sqlite assocs ;
+USING: accessors assocs db.sqlite furnace furnace.actions furnace.alloy
+furnace.auth furnace.auth.features.deactivate-user
+furnace.auth.features.edit-profile
+furnace.auth.features.recover-password
+furnace.auth.features.registration furnace.auth.login
+furnace.boilerplate furnace.redirection html.forms http.server
+http.server.dispatchers kernel namespaces site-watcher site-watcher.db
+site-watcher.private urls validators io.sockets.secure.unix.debug
+io.servers.connection db db.tuples sequences ;
+QUALIFIED: assocs
 IN: webapps.site-watcher
 
 TUPLE: site-watcher-app < dispatcher ;
 
 CONSTANT: site-list-url URL" $site-watcher-app/"
 
+: <main-action> ( -- action )
+    <page-action>
+        [
+            logged-in?
+            [ URL" $site-watcher-app/list" <redirect> ]
+            [ { site-watcher-app "main" } <chloe-content> ] if
+        ] >>display ;
+
 : <site-list-action> ( -- action )
     <page-action>
         { site-watcher-app "site-list" } >>template
         [
-            begin-form
-            sites get values "sites" set-value
-        ] >>init ;
+            ! Silly query
+            username watching-sites
+            "sites" set-value
+        ] >>init
+    <protected>
+        "list watched sites" >>description ;
 
 : <add-site-action> ( -- action )
     <action>
         [
-            { { "url" [ v-url ] } { "email" [ v-email ] } } validate-params
+            { { "url" [ v-url ] } } validate-params
         ] >>validate
         [
-            "email" value "url" value watch-site
+            username "url" value watch-site
             site-list-url <redirect>
-        ] >>submit ;
+        ] >>submit
+    <protected>
+        "add a watched site" >>description ;
 
 : <remove-site-action> ( -- action )
     <action>
@@ -33,22 +53,79 @@ CONSTANT: site-list-url URL" $site-watcher-app/"
             { { "url" [ v-url ] } } validate-params
         ] >>validate
         [
-            "url" value delete-site
+            username "url" value unwatch-site
             site-list-url <redirect>
-        ] >>submit ;
+        ] >>submit
+    <protected>
+        "remove a watched site" >>description ;
 
 : <check-sites-action> ( -- action )
     <action>
         [
-            sites get [ check-sites ] [ report-sites ] bi
+            watch-sites
+            site-list-url <redirect>
+        ] >>submit
+    <protected>
+        "check watched sites" >>description ;
+
+: <update-notify-action> ( -- action )
+    <page-action>
+        [
+            username <account> select-tuple from-object
+        ] >>init
+        { site-watcher-app "update-notify" } >>template
+        [
+            {
+                { "email" [ [ v-email ] v-optional ] }
+                { "twitter" [ [ v-one-word ] v-optional ] }
+                { "sms" [ [ v-one-line ] v-optional ] }
+            } validate-params
+        ] >>validate
+        [
+            username <account> select-tuple
+            "email" value >>email
+            update-tuple
             site-list-url <redirect>
-        ] >>submit ;
+        ] >>submit
+    <protected>
+        "update notification details" >>description ;
 
 : <site-watcher-app> ( -- dispatcher )
     site-watcher-app new-dispatcher
-        <site-list-action> "" add-responder
+        <main-action> "" add-responder
+        <site-list-action> "list" add-responder
         <add-site-action> "add" add-responder
         <remove-site-action> "remove" add-responder
-        <check-sites-action> "check" add-responder ;
+        <check-sites-action> "check" add-responder
+        <update-notify-action> "update-notify" add-responder ;
+
+: <login-config> ( responder -- responder' )
+    "SiteWatcher" <login-realm>
+        "SiteWatcher" >>name
+        allow-registration
+        allow-password-recovery
+        allow-edit-profile
+        allow-deactivation ;
+
+: <site-watcher-server> ( -- threaded-server )
+    <http-server>
+        <test-secure-config> >>secure-config
+        8081 >>insecure
+        8431 >>secure ;
+
+: site-watcher-db ( -- db )
+    "resource:test.db" <sqlite-db> ;
+
+<site-watcher-app>
+<login-config>
+<boilerplate> { site-watcher-app "site-watcher" } >>template
+site-watcher-db <alloy>
+main-responder set-global
+
+: start-site-watcher ( -- )
+    <site-watcher-server> start-server ;
 
-<site-watcher-app> "resource:test.db" <sqlite-db> <alloy> main-responder set-global
\ No newline at end of file
+: init-db ( -- )
+    site-watcher-db [
+        { site account watching-site } [ ensure-table ] each
+    ] with-db ;
\ No newline at end of file
diff --git a/extra/webapps/site-watcher/site-watcher.xml b/extra/webapps/site-watcher/site-watcher.xml
new file mode 100644 (file)
index 0000000..5b2b129
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version='1.0' ?>
+
+<t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
+
+<html>
+  <head>
+    <title>SiteWatcher</title>
+  </head>
+  <body>
+    <h1>SiteWatcher</h1>
+    <h2>It tells you if your web site goes down.</h2>
+    <t:call-next-template />
+  </body>
+</html>
+
+</t:chloe>
diff --git a/extra/webapps/site-watcher/update-notify.xml b/extra/webapps/site-watcher/update-notify.xml
new file mode 100644 (file)
index 0000000..02075de
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version='1.0' ?>
+
+<t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
+
+<h3>Enter your contact details</h3>
+
+<t:form t:action="$site-watcher-app/update-notify">
+<table>
+  <tr><th>E-mail:</th><td><t:field t:name="email" t:size="80" /></td></tr>
+  <tr><th>Twitter:</th><td><t:field t:name="twitter" t:size="80" /></td></tr>
+  <tr><th>SMS:</th><td><t:field t:name="sms" t:size="80" /></td></tr>
+</table>
+<p> <button type="submit">Done</button> </p>
+</t:form>
+
+</t:chloe>
index 83f06ec1370445843f3f894ddf79b6f4db9a7fae..728764226eb7954b30ee683416c1e378af67a10f 100644 (file)
@@ -1,17 +1,18 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel
 cocoa
 cocoa.application
 cocoa.types
 cocoa.classes
-cocoa.windows ;
+cocoa.windows
+core-graphics.types ;
 IN: webkit-demo
 
 FRAMEWORK: /System/Library/Frameworks/WebKit.framework
 IMPORT: WebView
 
-: rect ( -- rect ) 0 0 700 500 <NSRect> ;
+: rect ( -- rect ) 0 0 700 500 <CGRect> ;
 
 : <WebView> ( -- id )
     WebView -> alloc
index 7abdc149dd8ed71bf5077c4927739e7f457cb830..34cd19c34fc99344f8b86536dfd7a51f4cf2d703 100644 (file)
@@ -1,6 +1,6 @@
 USING: kernel sequences namespaces make math assocs words arrays
 tools.annotations vocabs sorting prettyprint io system
-math.statistics accessors tools.time ;
+math.statistics accessors tools.time fry ;
 IN: wordtimer
 
 SYMBOL: *wordtimes*
@@ -40,7 +40,7 @@ SYMBOL: *calling*
   [ swap time-unless-recursing ] 2curry ; 
 
 : add-timer ( word -- )
-  dup [ (add-timer) ] annotate ;
+  dup '[ [ _ ] dip (add-timer) ] annotate ;
 
 : add-timers ( vocab -- )
   words [ add-timer ] each ;
index f3b510fdd97003f313ae63b983758dbc80836b97..5961d9e86fbddacbc5d1080c2020ebc7e59d92df 100644 (file)
              (save-excursion
                (goto-char (nth 8 state))
                (beginning-of-line)
-               (cond ((looking-at "USING: ")
+               (cond ((looking-at-p "USING: ")
                       'factor-font-lock-vocabulary-name)
-                     ((looking-at "\\(TUPLE\\|SYMBOLS\\|VARS\\): ")
+                     ((looking-at-p "\\(TUPLE\\|SYMBOLS\\|VARS\\|SINGLETONS\\):")
                       'factor-font-lock-symbol)
-                     ((looking-at "C-ENUM:\\( \\|\n\\)")
+                     ((looking-at-p "C-ENUM:\\( \\|\n\\)")
                       'factor-font-lock-constant)
                      (t 'default))))
             ((or (char-equal c ?U) (char-equal c ?C))
index 31e79b7c4a106b6c59c3ac41b43c3c087989ab0d..4cff58ae3b33837a0252680fce0ca75af488ebdf 100644 (file)
   "\\_<\"[^>]\\([^\"\n]\\|\\\\\"\\)*\n")
 
 (defconst fuel-syntax--word-definition-regex
-  (fuel-syntax--second-word-regex
-   '(":" "::" "GENERIC:" "DEFER:" "HOOK:" "MAIN:" "MATH:" "POSTPONE:"
-     "SYMBOL:" "RENAME:")))
+  (format "\\_<\\(%s\\)?: +\\_<\\(\\w+\\)\\_>"
+          (regexp-opt
+           '(":" "GENERIC" "DEFER" "HOOK" "MAIN" "MATH" "POSTPONE"
+             "SYMBOL" "RENAME"))))
 
 (defconst fuel-syntax--alias-definition-regex
   "^ALIAS: +\\(\\_<.+?\\_>\\) +\\(\\_<.+?\\_>\\)")
 (defconst fuel-syntax--indent-def-start-regex
   (format "^\\(%s:\\)\\( \\|\n\\)" (regexp-opt fuel-syntax--indent-def-starts)))
 
-(defconst fuel-syntax--no-indent-def-start-regex
-  (format "^\\(%s:\\) " (regexp-opt fuel-syntax--no-indent-def-starts)))
-
 (defconst fuel-syntax--definition-start-regex
   (format "^\\(%s:\\) " (regexp-opt (append fuel-syntax--no-indent-def-starts
                                             fuel-syntax--indent-def-starts))))
     ("\\_<\\(C\\)-ENUM: \\(;\\)" (1 "<b") (2 ">b"))
     ("\\_<C-ENUM:\\( \\|\n\\)" (1 "<b"))
     ("\\_<TUPLE: +\\w+? +< +\\w+? *\\( \\|\n\\)\\([^;]\\|$\\)" (1 "<b"))
-    ("\\_<\\(TUPLE\\|SYMBOLS\\|VARS\\): +\\w+? *\\( \\|\n\\)\\([^;<\n]\\|\\_>\\)"
-     (2 "<b"))
+    ("\\_<TUPLE: +\\w+? *\\( \\|\n\\)\\([^;<\n]\\|\\_>\\)" (1 "<b"))
+    ("\\_<\\(SYMBOLS\\|VARS\\|SINGLETONS\\): *?\\( \\|\n\\)\\([^;\n]\\|\\_>\\)" (2 "<b"))
     ("\\(\n\\| \\);\\_>" (1 ">b"))
     ;; Let and lambda:
     ("\\_<\\(!(\\) .* \\()\\)" (1 "<") (2 ">"))
 (defsubst fuel-syntax--is-last-char (pos)
   (save-excursion
     (goto-char (1+ pos))
-    (fuel-syntax--looking-at-emptiness)))
+    (looking-at-p "[ ]*$")))
 
 (defsubst fuel-syntax--line-offset (pos)
   (- pos (save-excursion