ABOUT: "number-strings"
-HELP: digits>integer
-{ $values { "seq" "a sequence of integers" } { "radix" "an integer between 2 and 16" } { "n/f" { $maybe integer } } }
-{ $description "Converts a sequence of digits (with most significant digit first) into an integer." }
-{ $notes "This is one of the factors of " { $link string>number } "." } ;
-
HELP: >digit
{ $values { "n" "an integer between 0 and 15" } { "ch" "a character" } }
{ $description "Outputs a character representation of a digit." }
[ CHAR: a 10 - - dup 10 < [ drop 255 ] when ]
} cond ; inline
+: string>digits ( str -- digits )
+ [ digit> ] B{ } map-as ; inline
+
+: >digit ( n -- ch )
+ dup 10 < [ CHAR: 0 + ] [ 10 - CHAR: a + ] if ; inline
+
ERROR: invalid-radix radix ;
<PRIVATE
: dec> ( str -- n/f ) 10 base> ; inline
: hex> ( str -- n/f ) 16 base> ; inline
-: string>digits ( str -- digits )
- [ digit> ] B{ } map-as ; inline
-
-<PRIVATE
-
-: (digits>integer) ( valid? accum digit radix -- valid? accum )
- 2dup < [ swapd * + ] [ 4drop f 0 ] if ; inline
-
-: each-digit ( seq radix quot -- n/f )
- [ t 0 ] 3dip curry each swap [ drop f ] unless ; inline
-
-PRIVATE>
-
-: digits>integer ( seq radix -- n/f )
- [ (digits>integer) ] each-digit ; inline
-
-: >digit ( n -- ch )
- dup 10 < [ CHAR: 0 + ] [ 10 - CHAR: a + ] if ; inline
-
<PRIVATE
CONSTANT: TENS B{