Re: [Scheme-reports] digit-value
John Cowan 02 Jul 2012 00:26 UTC
Peter Bex scripsit:
> Alternatively, change it to accept just the ASCII number characters,
> and possibly with Marc's suggestion of accepting digits in any base
> (and perhaps an optional second argument to specify which base we're
> working in). That would really be useful, since that could be used
> to implement very common char->number conversion and could even be
> used internally in string->number (at least conceptually).
It's quite common (though technically not portable) to determine that a
character is a digit using `char-numeric?` and then determine its value
using `(- (char->integer x) (char->integer #\0))` or the equivalent.
Because the WG decided that `char-numeric?` returns `#t` on all decimal
digits (but not other numeric characters), providing a method of
determining the value seemed a Good Thing.
--
Where the wombat has walked, John Cowan <cowan@ccil.org>
it will inevitably walk again. http://www.ccil.org/~cowan
(even through brick walls!)
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports