diff --git a/basis/roman/roman.factor b/basis/roman/roman.factor index 92202da8ca..817b6637d6 100644 --- a/basis/roman/roman.factor +++ b/basis/roman/roman.factor @@ -1,10 +1,9 @@ ! Copyright (C) 2007 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays assocs fry generalizations grouping -kernel lexer macros make math math.order math.vectors +USING: accessors arrays assocs effects fry generalizations +grouping kernel lexer macros math math.order math.vectors namespaces parser quotations sequences sequences.private -splitting.monotonic stack-checker strings unicode.case -words effects ; +splitting.monotonic stack-checker strings unicode.case words ; IN: roman = ( ch1 ch2 -- ? ) [ roman-digit-index ] bi@ >= ; : roman>n ( ch -- n ) roman-digit-index roman-values nth ; -: (>roman) ( n -- ) - roman-values roman-digits [ - [ /mod swap ] dip concat % - ] 2each drop ; - : (roman>) ( seq -- n ) [ [ roman>n ] map ] [ all-eq? ] bi [ sum ] [ first2 swap - ] if ; @@ -41,12 +35,15 @@ ERROR: roman-range-error n ; PRIVATE> : >roman ( n -- str ) - dup roman-range-check [ (>roman) ] "" make ; + roman-range-check + roman-values roman-digits [ + [ /mod swap ] dip concat + ] 2map "" concat-as nip ; : >ROMAN ( n -- str ) >roman >upper ; : roman> ( str -- n ) - >lower [ roman<= ] monotonic-split [ (roman>) ] sigma ; + >lower [ roman>= ] monotonic-split [ (roman>) ] sigma ; << + SYNTAX: ROMAN-OP: scan-word [ name>> "roman" prepend create-in ] keep 1quotation '[ _ binary-roman-op ] dup infer [ in>> ] [ out>> ] bi [ "string" ] bi@ define-declared ; + >> ROMAN-OP: + diff --git a/core/sets/sets-docs.factor b/core/sets/sets-docs.factor index 1e4ceb5680..298fcbeeae 100755 --- a/core/sets/sets-docs.factor +++ b/core/sets/sets-docs.factor @@ -168,8 +168,8 @@ HELP: sequence>assoc { "assoc" assoc } } { $examples - { $example "! Count the number of times the elements of two sequences appear." - "USING: prettyprint sets ;" + { $example "! Iterate over a sequence and increment the count at each element" + "USING: assocs prettyprint sets ;" "\"aaabc\" [ inc-at ] H{ } sequence>assoc ." "H{ { 97 3 } { 98 1 } { 99 1 } }" } @@ -182,8 +182,8 @@ HELP: sequence>assoc* { "assoc" assoc } } { $examples - { $example "! Count the number of times the elements of two sequences appear." - "USING: prettyprint sets ;" + { $example "! Iterate over a sequence and add the counts to an existing assoc" + "USING: assocs prettyprint sets kernel ;" "H{ { 97 2 } { 98 1 } } clone \"aaabc\" [ inc-at ] sequence>assoc* ." "H{ { 97 5 } { 98 2 } { 99 1 } }" } @@ -196,8 +196,8 @@ HELP: sequence>hashtable { "hashtable" hashtable } } { $examples - { $example "! Count the number of times the elements of two sequences appear." - "USING: prettyprint sets ;" + { $example "! Count the number of times an element occurs in a sequence" + "USING: assocs prettyprint sets ;" "\"aaabc\" [ inc-at ] sequence>hashtable ." "H{ { 97 3 } { 98 1 } { 99 1 } }" }