From 1c038b611adaa7384d8cc2c8e91426c63bf0fc87 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 12 Sep 2008 12:08:01 -0500 Subject: [PATCH 01/11] add docs for mime-types --- basis/mime-types/mime-types-docs.factor | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 basis/mime-types/mime-types-docs.factor diff --git a/basis/mime-types/mime-types-docs.factor b/basis/mime-types/mime-types-docs.factor new file mode 100644 index 0000000000..cf44808725 --- /dev/null +++ b/basis/mime-types/mime-types-docs.factor @@ -0,0 +1,35 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: assocs help.markup help.syntax io.streams.string sequences ; +IN: mime-types + +HELP: mime-db +{ $values + + { "seq" sequence } } +{ $description "Outputs an array where the first element is a MIME type and the rest of the array is file extensions that have that MIME type." } ; + +HELP: mime-type +{ $values + { "path" "a pathname string" } + { "mime-type" "a MIME type string" } } +{ $description "Outputs the MIME type associtated with a path by parsing the path's file extension and looking it up in the table returned by " { $link mime-types } "." } ; + +HELP: mime-types +{ $values + + { "assoc" assoc } } +{ $description "Outputs an " { $snippet "assoc" } " made from the data in the " { $link mime-db } " word where the keys are file extensions and the values are the corresponding MIME types." } ; + +HELP: nonstandard-mime-types +{ $values + + { "assoc" assoc } } +{ $description "A list of Factor-specific MIME types that are added to the MIME database loaded from disk." } ; + +ARTICLE: "mime-types" "mime-types" +"The " { $vocab-link "mime-types" } " vocabulary loads a file of MIME types and provides a word to look up the MIME type based on a file extension." $nl +"Looking up a MIME type:" +{ $subsection mime-type } ; + +ABOUT: "mime-types" From 7f3b0de65996d87a9d338130ca6d83531943f267 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 12 Sep 2008 12:16:21 -0500 Subject: [PATCH 02/11] better docs --- basis/alias/alias-docs.factor | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/basis/alias/alias-docs.factor b/basis/alias/alias-docs.factor index f4d4ac0361..4dcf1a7738 100644 --- a/basis/alias/alias-docs.factor +++ b/basis/alias/alias-docs.factor @@ -1,3 +1,5 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. USING: kernel words help.markup help.syntax ; IN: alias @@ -14,4 +16,11 @@ HELP: ALIAS: } } ; +ARTICLE: "alias" "Alias" +"The " { $vocab-link "alias" } " vocabulary implements a way to make many different names for the same word. Although creating new names for words is generally frowned upon, aliases are useful for the Win32 API and other cases where words need to be renamed for symmetry." $nl +"Make a new word that aliases another word:" +{ $subsection define-alias } +"Make an alias at parse-time:" +{ $subsection POSTPONE: ALIAS: } ; +ABOUT: "alias" From 31939341e3a2ffe8f623347d58b80d654e8dd9d8 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 12 Sep 2008 12:16:27 -0500 Subject: [PATCH 03/11] better article name --- basis/mime-types/mime-types-docs.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/mime-types/mime-types-docs.factor b/basis/mime-types/mime-types-docs.factor index cf44808725..058a71d838 100644 --- a/basis/mime-types/mime-types-docs.factor +++ b/basis/mime-types/mime-types-docs.factor @@ -27,7 +27,7 @@ HELP: nonstandard-mime-types { "assoc" assoc } } { $description "A list of Factor-specific MIME types that are added to the MIME database loaded from disk." } ; -ARTICLE: "mime-types" "mime-types" +ARTICLE: "mime-types" "MIME types" "The " { $vocab-link "mime-types" } " vocabulary loads a file of MIME types and provides a word to look up the MIME type based on a file extension." $nl "Looking up a MIME type:" { $subsection mime-type } ; From 022a90c843a51b2098822b4852166a0bc360faee Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 12 Sep 2008 12:21:32 -0500 Subject: [PATCH 04/11] add vocab-link in docs --- basis/alarms/alarms-docs.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/alarms/alarms-docs.factor b/basis/alarms/alarms-docs.factor index 49480c0fe0..dac8b72dd5 100755 --- a/basis/alarms/alarms-docs.factor +++ b/basis/alarms/alarms-docs.factor @@ -23,7 +23,7 @@ HELP: every { $description "Creates and registers an alarm which calls the quotation repeatedly, using " { $snippet "dt" } " as the frequency." } ; ARTICLE: "alarms" "Alarms" -"Alarms provide a lightweight way to schedule one-time and recurring tasks without spawning a new thread." +"The " { $vocab-link "alarms" } " vocabulary provides a lightweight way to schedule one-time and recurring tasks without spawning a new thread." { $subsection alarm } { $subsection add-alarm } { $subsection later } From 1384514ad91501d0d5b9c7c8c1bee5c3add0a202 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 12 Sep 2008 12:30:42 -0500 Subject: [PATCH 05/11] better base64 docs --- basis/ascii/ascii-docs.factor | 2 +- basis/base64/base64-docs.factor | 18 +++++++++++++----- basis/base64/base64.factor | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/basis/ascii/ascii-docs.factor b/basis/ascii/ascii-docs.factor index 1f7a56bed9..75af8a7102 100755 --- a/basis/ascii/ascii-docs.factor +++ b/basis/ascii/ascii-docs.factor @@ -38,7 +38,7 @@ HELP: quotable? { $description "Tests for characters which may appear in a Factor string literal without escaping." } ; ARTICLE: "ascii" "ASCII character classes" -"Traditional ASCII character classes:" +"The " { $vocab-link "ascii" } " vocabulary implements traditional ASCII character classes:" { $subsection blank? } { $subsection letter? } { $subsection LETTER? } diff --git a/basis/base64/base64-docs.factor b/basis/base64/base64-docs.factor index fe948bf667..ed92a19577 100644 --- a/basis/base64/base64-docs.factor +++ b/basis/base64/base64-docs.factor @@ -1,20 +1,28 @@ -USING: help.markup help.syntax kernel math ; +USING: help.markup help.syntax kernel math sequences ; IN: base64 HELP: >base64 -{ $values { "seq" "a sequence" } { "base64" "a string of base64 characters" } } +{ $values { "seq" sequence } { "base64" "a string of base64 characters" } } { $description "Converts a sequence to its base64 representation by taking six bits at a time as an index into a lookup table containing alphanumerics, '+', and '/'. The result is padded with '=' if the input was not a multiple of six bits." } { $examples - { $unchecked-example "\"The monorail is a free service.\" >base64 ." "VGhlIG1vbm9yYWlsIGlzIGEgZnJlZSBzZXJ2aWNlLg==" } + { $example "USING: prettyprint base64 strings ;" "\"The monorail is a free service.\" >base64 >string ." "\"VGhlIG1vbm9yYWlsIGlzIGEgZnJlZSBzZXJ2aWNlLg==\"" } } { $see-also base64> } ; HELP: base64> -{ $values { "base64" "a string of base64 characters" } { "str" "a string" } } +{ $values { "base64" "a string of base64 characters" } { "seq" sequence } } { $description "Converts a string in base64 encoding back into its binary representation." } { $examples - { $unchecked-example "\"VGhlIG1vbm9yYWlsIGlzIGEgZnJlZSBzZXJ2aWNlLg==\" base64> ." "\"The monorail is a free service.\"" } + { $example "USING: prettyprint base64 strings ;" "\"VGhlIG1vbm9yYWlsIGlzIGEgZnJlZSBzZXJ2aWNlLg==\" base64> >string ." "\"The monorail is a free service.\"" } } { $notes "This word will throw if the input string contains characters other than those allowed in base64 encodings." } { $see-also >base64 } ; +ARTICLE: "base64" "Base 64 conversions" +"The " { $vocab-link "base64" } " vocabulary implements conversions of sequences to printable characters in base 64. These plain-text representations of binary data may be passed around and converted back to binary data later." $nl +"Converting to base 64:" +{ $subsection >base64 } +"Converting back to binary:" +{ $subsection base64> } ; + +ABOUT: "base64" diff --git a/basis/base64/base64.factor b/basis/base64/base64.factor index 7097de6c6e..e3033a2bde 100644 --- a/basis/base64/base64.factor +++ b/basis/base64/base64.factor @@ -43,7 +43,7 @@ PRIVATE> [ [ "" ] [ >base64-rem ] if-empty ] bi* append ; -: base64> ( base64 -- str ) +: base64> ( base64 -- seq ) #! input length must be a multiple of 4 [ 4 [ decode4 ] map concat ] [ [ CHAR: = = ] count-end ] From 624f0f552c24dfbb0dd2b7834706d28b368e5c79 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 12 Sep 2008 12:32:34 -0500 Subject: [PATCH 06/11] move about to end --- basis/binary-search/binary-search-docs.factor | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/basis/binary-search/binary-search-docs.factor b/basis/binary-search/binary-search-docs.factor index 8b85e078ce..caabbd7419 100644 --- a/basis/binary-search/binary-search-docs.factor +++ b/basis/binary-search/binary-search-docs.factor @@ -1,17 +1,6 @@ IN: binary-search USING: help.markup help.syntax sequences kernel math.order ; -ARTICLE: "binary-search" "Binary search" -"The " { $emphasis "binary search" } " algorithm allows elements to be located in sorted sequence in " { $snippet "O(log n)" } " time." -{ $subsection search } -"Variants of sequence words optimized for sorted sequences:" -{ $subsection sorted-index } -{ $subsection sorted-member? } -{ $subsection sorted-memq? } -{ $see-also "order-specifiers" "sequences-sorting" } ; - -ABOUT: "binary-search" - HELP: search { $values { "seq" "a sorted sequence" } { "quot" "a quotation with stack effect " { $snippet "( elt -- <=> )" } } { "i" "an index, or " { $link f } } { "elt" "an element, or " { $link f } } } { $description "Performs a binary search on a sequence, calling the quotation to decide whether to end the search (" { $link +eq+ } "), search lower (" { $link +lt+ } ") or search higher (" { $link +gt+ } ")." @@ -41,3 +30,14 @@ HELP: sorted-memq? { $description "Tests if the sorted sequence contains " { $snippet "elt" } ". Equality is tested with " { $link eq? } "." } ; { memq? sorted-memq? } related-words + +ARTICLE: "binary-search" "Binary search" +"The " { $emphasis "binary search" } " algorithm allows elements to be located in sorted sequence in " { $snippet "O(log n)" } " time." +{ $subsection search } +"Variants of sequence words optimized for sorted sequences:" +{ $subsection sorted-index } +{ $subsection sorted-member? } +{ $subsection sorted-memq? } +{ $see-also "order-specifiers" "sequences-sorting" } ; + +ABOUT: "binary-search" From 82a076df7923b5ddf1b89c840562e22906a964ab Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 12 Sep 2008 15:49:46 -0500 Subject: [PATCH 07/11] Clean up human sort, move it to basis --- basis/sorting/human/human-tests.factor | 6 ++++++ basis/sorting/human/human.factor | 10 ++++++++++ extra/sequences/lib/lib.factor | 25 ------------------------- 3 files changed, 16 insertions(+), 25 deletions(-) create mode 100644 basis/sorting/human/human-tests.factor create mode 100644 basis/sorting/human/human.factor diff --git a/basis/sorting/human/human-tests.factor b/basis/sorting/human/human-tests.factor new file mode 100644 index 0000000000..0e20b54c2f --- /dev/null +++ b/basis/sorting/human/human-tests.factor @@ -0,0 +1,6 @@ +USING: sorting.human tools.test ; +IN: sorting.human.tests + +\ human-sort must-infer + +[ { "x1y" "x2" "x10y" } ] [ { "x1y" "x10y" "x2" } human-sort ] unit-test diff --git a/basis/sorting/human/human.factor b/basis/sorting/human/human.factor new file mode 100644 index 0000000000..1c2ba419c7 --- /dev/null +++ b/basis/sorting/human/human.factor @@ -0,0 +1,10 @@ +! Copyright (C) 2008 Doug Coleman, Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: peg.ebnf math.parser kernel assocs sorting ; +IN: sorting.human + +: find-numbers ( string -- seq ) + [EBNF Result = ([0-9]+ => [[ string>number ]] | (!([0-9]) .)+)* EBNF] ; + +: human-sort ( seq -- seq' ) + [ dup find-numbers ] { } map>assoc sort-values keys ; diff --git a/extra/sequences/lib/lib.factor b/extra/sequences/lib/lib.factor index 0ce4f56f7a..690d7f4b76 100755 --- a/extra/sequences/lib/lib.factor +++ b/extra/sequences/lib/lib.factor @@ -131,23 +131,6 @@ PRIVATE> : power-set ( seq -- subsets ) 2 over length exact-number-strings swap [ switches ] curry map ; -: cut-find ( seq pred -- before after ) - dupd find drop dup [ cut ] when ; - -: cut3 ( seq pred -- first mid last ) - [ cut-find ] keep [ not ] compose cut-find ; - -: (cut-all) ( seq pred quot -- ) - [ >r cut3 r> dip >r >r , r> [ , ] when* r> ] 2keep - pick [ (cut-all) ] [ 3drop ] if ; - -: cut-all ( seq pred quot -- first mid last ) - [ (cut-all) ] { } make ; - -: human-sort ( seq -- newseq ) - [ dup [ digit? ] [ string>number ] cut-all ] { } map>assoc - sort-values keys ; - : ?first ( seq -- first/f ) 0 swap ?nth ; inline : ?second ( seq -- second/f ) 1 swap ?nth ; inline : ?third ( seq -- third/f ) 2 swap ?nth ; inline @@ -164,14 +147,6 @@ USE: continuations ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -! List the positions of obj in seq - -: indices ( seq obj -- seq ) - >r dup length swap r> - [ = [ ] [ drop f ] if ] curry - 2map - sift ; - Date: Fri, 12 Sep 2008 15:50:34 -0500 Subject: [PATCH 08/11] Add meta-data --- basis/sorting/human/authors.txt | 2 ++ basis/sorting/human/summary.txt | 1 + basis/sorting/human/tags.txt | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 basis/sorting/human/authors.txt create mode 100644 basis/sorting/human/summary.txt create mode 100644 basis/sorting/human/tags.txt diff --git a/basis/sorting/human/authors.txt b/basis/sorting/human/authors.txt new file mode 100644 index 0000000000..5674120196 --- /dev/null +++ b/basis/sorting/human/authors.txt @@ -0,0 +1,2 @@ +Doug Coleman +Slava Pestov diff --git a/basis/sorting/human/summary.txt b/basis/sorting/human/summary.txt new file mode 100644 index 0000000000..a72934f9e6 --- /dev/null +++ b/basis/sorting/human/summary.txt @@ -0,0 +1 @@ +Correct sorting of sequences of strings with embedded numbers diff --git a/basis/sorting/human/tags.txt b/basis/sorting/human/tags.txt new file mode 100644 index 0000000000..3ab2d731fe --- /dev/null +++ b/basis/sorting/human/tags.txt @@ -0,0 +1,2 @@ +collections +text From d5140cf248050b3ace5a111ef8ceeb14dab3e268 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 12 Sep 2008 15:52:43 -0500 Subject: [PATCH 09/11] Fix math.vectors unit tests --- basis/math/vectors/vectors-tests.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basis/math/vectors/vectors-tests.factor b/basis/math/vectors/vectors-tests.factor index 498bb81f62..aef4ade877 100644 --- a/basis/math/vectors/vectors-tests.factor +++ b/basis/math/vectors/vectors-tests.factor @@ -6,6 +6,6 @@ USING: math.vectors tools.test ; [ { 1 2 3 } ] [ { 2 4 6 } 2 v/n ] unit-test [ { 1/1 1/2 1/3 } ] [ 1 { 1 2 3 } n/v ] unit-test -[ 4 ] [ { 1 2 } norm-sq ] unit-test -[ 36 ] [ { 2 3 } norm-sq ] unit-test +[ 5 ] [ { 1 2 } norm-sq ] unit-test +[ 13 ] [ { 2 3 } norm-sq ] unit-test From 996dd6442e0e1bb36481f3315c51377b1119a105 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 12 Sep 2008 16:03:47 -0500 Subject: [PATCH 10/11] Add indices word --- core/sequences/sequences-tests.factor | 4 +++- core/sequences/sequences.factor | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/sequences/sequences-tests.factor b/core/sequences/sequences-tests.factor index 8018fe1cdc..f8765bc946 100755 --- a/core/sequences/sequences-tests.factor +++ b/core/sequences/sequences-tests.factor @@ -265,4 +265,6 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ; [ { 1 3 7 } ] [ 2 { 1 3 5 7 } remove-nth ] unit-test -[ { 1 3 "X" 5 7 } ] [ "X" 2 { 1 3 5 7 } insert-nth ] unit-test +[ { 1 3 "X" 5 7 } ] [ "X" 2 { 1 3 5 7 } insert-nth ] + +[ V{ 0 2 } ] [ "a" { "a" "b" "a" } indices ] unit-test diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 57dba9ed4e..b08d6eb2c7 100755 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -480,6 +480,11 @@ PRIVATE> : last-index-from ( obj i seq -- n ) rot [ = ] curry find-last-from drop ; +: indices ( obj seq -- indices ) + V{ } clone spin + [ rot = [ over push ] [ drop ] if ] + curry each-index ; + : nths ( seq indices -- seq' ) swap [ nth ] curry map ; From 162faace98ff164fece38e9e926738e63941a373 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 12 Sep 2008 16:04:01 -0500 Subject: [PATCH 11/11] Fix typo in 3bi docs --- core/kernel/kernel-docs.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/kernel/kernel-docs.factor b/core/kernel/kernel-docs.factor index 8483293274..c833325c41 100755 --- a/core/kernel/kernel-docs.factor +++ b/core/kernel/kernel-docs.factor @@ -550,7 +550,7 @@ HELP: 2bi HELP: 3bi { $values { "x" object } { "y" object } { "z" object } { "p" "a quotation with stack effect " { $snippet "( x y z -- ... )" } } { "q" "a quotation with stack effect " { $snippet "( x y z -- ... )" } } } -{ $description "Applies " { $snippet "p" } " to the two input values, then applies " { $snippet "q" } " to the two input values." } +{ $description "Applies " { $snippet "p" } " to the three input values, then applies " { $snippet "q" } " to the three input values." } { $examples "If " { $snippet "[ p ]" } " and " { $snippet "[ q ]" } " have stack effect " { $snippet "( x y z -- )" } ", then the following two lines are equivalent:" { $code