From 296974a0579647601c63d1f19b101bc86129929d Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 19 Jul 2015 18:06:51 -0700 Subject: [PATCH] math.parser: remove digits>integer. --- core/math/parser/parser-docs.factor | 5 ----- core/math/parser/parser.factor | 25 ++++++------------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/core/math/parser/parser-docs.factor b/core/math/parser/parser-docs.factor index 9cefe52319..66456d7bfd 100644 --- a/core/math/parser/parser-docs.factor +++ b/core/math/parser/parser-docs.factor @@ -28,11 +28,6 @@ $nl 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." } diff --git a/core/math/parser/parser.factor b/core/math/parser/parser.factor index ec424716b9..4fef37287a 100644 --- a/core/math/parser/parser.factor +++ b/core/math/parser/parser.factor @@ -16,6 +16,12 @@ PRIVATE> [ 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 ; : dec> ( str -- n/f ) 10 base> ; inline : hex> ( str -- n/f ) 16 base> ; inline -: string>digits ( str -- digits ) - [ digit> ] B{ } map-as ; inline - -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 -