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 } 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" 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 ] 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" 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 diff --git a/basis/mime-types/mime-types-docs.factor b/basis/mime-types/mime-types-docs.factor new file mode 100644 index 0000000000..058a71d838 --- /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" 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/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/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 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 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 ; 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 ; -