This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home.
Source for ticket #220
cc
changetime
2012-07-15 01:43:38
component
WG1 - Core
description
This accepts a character which is a numeric digit and returns its value as a digit, or `#f` if it's not a digit:
{{{
(digit-value #\3) => 3
(digit-value #\x0664) => 4
(digit-value #\x0EA6) => 0
}}}
You need the following list of zero-value characters to implement this for all of Unicode (currently); implementations that support only a subset of Unicode need only a subset of the list, of course:
{{{
(define zeros '(
#\x0030 ;DIGIT ZERO
#\x0660 ;ARABIC-INDIC DIGIT ZERO
#\x06F0 ;EXTENDED ARABIC-INDIC DIGIT ZERO
#\x07C0 ;NKO DIGIT ZERO
#\x0966 ;DEVANAGARI DIGIT ZERO
#\x09E6 ;BENGALI DIGIT ZERO
#\x0A66 ;GURMUKHI DIGIT ZERO
#\x0AE6 ;GUJARATI DIGIT ZERO
#\x0B66 ;ORIYA DIGIT ZERO
#\x0BE6 ;TAMIL DIGIT ZERO
#\x0C66 ;TELUGU DIGIT ZERO
#\x0CE6 ;KANNADA DIGIT ZERO
#\x0D66 ;MALAYALAM DIGIT ZERO
#\x0E50 ;THAI DIGIT ZERO
#\x0ED0 ;LAO DIGIT ZERO
#\x0F20 ;TIBETAN DIGIT ZERO
#\x1040 ;MYANMAR DIGIT ZERO
#\x1090 ;MYANMAR SHAN DIGIT ZERO
#\x17E0 ;KHMER DIGIT ZERO
#\x1810 ;MONGOLIAN DIGIT ZERO
#\x1946 ;LIMBU DIGIT ZERO
#\x19D0 ;NEW TAI LUE DIGIT ZERO
#\x1A80 ;TAI THAM HORA DIGIT ZERO
#\x1A90 ;TAI THAM THAM DIGIT ZERO
#\x1B50 ;BALINESE DIGIT ZERO
#\x1BB0 ;SUNDANESE DIGIT ZERO
#\x1C40 ;LEPCHA DIGIT ZERO
#\x1C50 ;OL CHIKI DIGIT ZERO
#\xA620 ;VAI DIGIT ZERO
#\xA8D0 ;SAURASHTRA DIGIT ZERO
#\xA900 ;KAYAH LI DIGIT ZERO
#\xA9D0 ;JAVANESE DIGIT ZERO
#\xAA50 ;CHAM DIGIT ZERO
#\xABF0 ;MEETEI MAYEK DIGIT ZERO
#\xFF10 ;FULLWIDTH DIGIT ZERO
#\x104A0 ;OSMANYA DIGIT ZERO
#\x11066 ;BRAHMI DIGIT ZERO
#\x1D7CE ;MATHEMATICAL BOLD DIGIT ZERO
#\x1D7D8 ;MATHEMATICAL DOUBLE-STRUCK DIGIT ZERO
#\x1D7E2 ;MATHEMATICAL SANS-SERIF DIGIT ZERO
#\x1D7EC ;MATHEMATICAL SANS-SERIF BOLD DIGIT ZERO
#\x1D7F6 ;MATHEMATICAL MONOSPACE DIGIT ZERO
))
(define (digit-value ch) (digit-value* ch zeros))
(define (digit-value* ch zeros)
(if
(null? zeros)
#f
(let*
((val (char->integer ch))
(val0 (char->integer (car zeros)))
(val9 (+ val0 9)))
(if
(<= val0 val val9)
(- val val0)
(digit-value* ch (cdr zeros))))))
}}}
CL provides this as `digit-char-p`, which is its substitute for `char-numeric?`.
id
220
keywords
milestone
owner
cowan
priority
major
reporter
cowan
resolution
duplicate
severity
status
closed
summary
New DIGIT-VALUE procedure
time
2011-06-17 09:22:20
type
defect
Changes
Change at time 2012-07-15 01:43:38
author
cowan
field
comment
newvalue
Being balloted as part of #452.
oldvalue
7
raw-time
1342291418984402
ticket
220
time
2012-07-15 01:43:38
Change at time 2012-07-15 01:43:38
author
cowan
field
resolution
newvalue
duplicate
oldvalue
raw-time
1342291418984402
ticket
220
time
2012-07-15 01:43:38
Change at time 2012-07-15 01:43:38
author
cowan
field
status
newvalue
closed
oldvalue
reopened
raw-time
1342291418984402
ticket
220
time
2012-07-15 01:43:38
Change at time 2012-07-09 21:22:52
author
alexshinn
field
comment
newvalue
oldvalue
6
raw-time
1341843772106498
ticket
220
time
2012-07-09 21:22:52
Change at time 2012-07-09 21:22:52
author
alexshinn
field
resolution
newvalue
oldvalue
fixed
raw-time
1341843772106498
ticket
220
time
2012-07-09 21:22:52
Change at time 2012-07-09 21:22:52
author
alexshinn
field
status
newvalue
reopened
oldvalue
closed
raw-time
1341843772106498
ticket
220
time
2012-07-09 21:22:52
Change at time 2012-07-09 21:22:45
author
alexshinn
field
comment
newvalue
oldvalue
5
raw-time
1341843765438872
ticket
220
time
2012-07-09 21:22:45
Change at time 2012-07-09 21:22:45
author
alexshinn
field
resolution
newvalue
fixed
oldvalue
raw-time
1341843765438872
ticket
220
time
2012-07-09 21:22:45
Change at time 2012-07-09 21:22:45
author
alexshinn
field
status
newvalue
closed
oldvalue
writing
raw-time
1341843765438872
ticket
220
time
2012-07-09 21:22:45
Change at time 2012-07-04 11:18:36
author
cowan
field
comment
newvalue
oldvalue
4
raw-time
1341375516791126
ticket
220
time
2012-07-04 11:18:36
Change at time 2012-07-04 11:18:36
author
cowan
field
description
newvalue
This accepts a character which is a numeric digit and returns its value as a digit, or `#f` if it's not a digit:
{{{
(digit-value #\3) => 3
(digit-value #\x0664) => 4
(digit-value #\x0EA6) => 0
}}}
You need the following list of zero-value characters to implement this for all of Unicode (currently); implementations that support only a subset of Unicode need only a subset of the list, of course:
{{{
(define zeros '(
#\x0030 ;DIGIT ZERO
#\x0660 ;ARABIC-INDIC DIGIT ZERO
#\x06F0 ;EXTENDED ARABIC-INDIC DIGIT ZERO
#\x07C0 ;NKO DIGIT ZERO
#\x0966 ;DEVANAGARI DIGIT ZERO
#\x09E6 ;BENGALI DIGIT ZERO
#\x0A66 ;GURMUKHI DIGIT ZERO
#\x0AE6 ;GUJARATI DIGIT ZERO
#\x0B66 ;ORIYA DIGIT ZERO
#\x0BE6 ;TAMIL DIGIT ZERO
#\x0C66 ;TELUGU DIGIT ZERO
#\x0CE6 ;KANNADA DIGIT ZERO
#\x0D66 ;MALAYALAM DIGIT ZERO
#\x0E50 ;THAI DIGIT ZERO
#\x0ED0 ;LAO DIGIT ZERO
#\x0F20 ;TIBETAN DIGIT ZERO
#\x1040 ;MYANMAR DIGIT ZERO
#\x1090 ;MYANMAR SHAN DIGIT ZERO
#\x17E0 ;KHMER DIGIT ZERO
#\x1810 ;MONGOLIAN DIGIT ZERO
#\x1946 ;LIMBU DIGIT ZERO
#\x19D0 ;NEW TAI LUE DIGIT ZERO
#\x1A80 ;TAI THAM HORA DIGIT ZERO
#\x1A90 ;TAI THAM THAM DIGIT ZERO
#\x1B50 ;BALINESE DIGIT ZERO
#\x1BB0 ;SUNDANESE DIGIT ZERO
#\x1C40 ;LEPCHA DIGIT ZERO
#\x1C50 ;OL CHIKI DIGIT ZERO
#\xA620 ;VAI DIGIT ZERO
#\xA8D0 ;SAURASHTRA DIGIT ZERO
#\xA900 ;KAYAH LI DIGIT ZERO
#\xA9D0 ;JAVANESE DIGIT ZERO
#\xAA50 ;CHAM DIGIT ZERO
#\xABF0 ;MEETEI MAYEK DIGIT ZERO
#\xFF10 ;FULLWIDTH DIGIT ZERO
#\x104A0 ;OSMANYA DIGIT ZERO
#\x11066 ;BRAHMI DIGIT ZERO
#\x1D7CE ;MATHEMATICAL BOLD DIGIT ZERO
#\x1D7D8 ;MATHEMATICAL DOUBLE-STRUCK DIGIT ZERO
#\x1D7E2 ;MATHEMATICAL SANS-SERIF DIGIT ZERO
#\x1D7EC ;MATHEMATICAL SANS-SERIF BOLD DIGIT ZERO
#\x1D7F6 ;MATHEMATICAL MONOSPACE DIGIT ZERO
))
(define (digit-value ch) (digit-value* ch zeros))
(define (digit-value* ch zeros)
(if
(null? zeros)
#f
(let*
((val (char->integer ch))
(val0 (char->integer (car zeros)))
(val9 (+ val0 9)))
(if
(<= val0 val val9)
(- val val0)
(digit-value* ch (cdr zeros))))))
}}}
CL provides this as `digit-char-p`, which is its substitute for `char-numeric?`.
oldvalue
This accepts a character which is a numeric digit and returns its value as a digit, or `#f` if it's not a digit:
{{{
(digit-value #\3) => 3
(digit-value #\x0664) => 4
(digit-value #\x0EA6) => 0
}}}
You need the following list of zero-value characters to implement this for all of Unicode (currently); implementations that support only a subset of Unicode need only a subset of the list, of course:
{{{
(define zeros '(
#\x0030 ;DIGIT ZERO
#\x0660 ;ARABIC-INDIC DIGIT ZERO
#\x06F0 ;EXTENDED ARABIC-INDIC DIGIT ZERO
#\x07C0 ;NKO DIGIT ZERO
#\x0966 ;DEVANAGARI DIGIT ZERO
#\x09E6 ;BENGALI DIGIT ZERO
#\x0A66 ;GURMUKHI DIGIT ZERO
#\x0AE6 ;GUJARATI DIGIT ZERO
#\x0B66 ;ORIYA DIGIT ZERO
#\x0BE6 ;TAMIL DIGIT ZERO
#\x0C66 ;TELUGU DIGIT ZERO
#\x0CE6 ;KANNADA DIGIT ZERO
#\x0D66 ;MALAYALAM DIGIT ZERO
#\x0E50 ;THAI DIGIT ZERO
#\x0ED0 ;LAO DIGIT ZERO
#\x0F20 ;TIBETAN DIGIT ZERO
#\x1040 ;MYANMAR DIGIT ZERO
#\x1090 ;MYANMAR SHAN DIGIT ZERO
#\x17E0 ;KHMER DIGIT ZERO
#\x1810 ;MONGOLIAN DIGIT ZERO
#\x1946 ;LIMBU DIGIT ZERO
#\x19D0 ;NEW TAI LUE DIGIT ZERO
#\x1A80 ;TAI THAM HORA DIGIT ZERO
#\x1A90 ;TAI THAM THAM DIGIT ZERO
#\x1B50 ;BALINESE DIGIT ZERO
#\x1BB0 ;SUNDANESE DIGIT ZERO
#\x1C40 ;LEPCHA DIGIT ZERO
#\x1C50 ;OL CHIKI DIGIT ZERO
#\xA620 ;VAI DIGIT ZERO
#\xA8D0 ;SAURASHTRA DIGIT ZERO
#\xA900 ;KAYAH LI DIGIT ZERO
#\xA9D0 ;JAVANESE DIGIT ZERO
#\xAA50 ;CHAM DIGIT ZERO
#\xABF0 ;MEETEI MAYEK DIGIT ZERO
#\xFF10 ;FULLWIDTH DIGIT ZERO
#\x104A0 ;OSMANYA DIGIT ZERO
#\x11066 ;BRAHMI DIGIT ZERO
#\x1D7CE ;MATHEMATICAL BOLD DIGIT ZERO
#\x1D7D8 ;MATHEMATICAL DOUBLE-STRUCK DIGIT ZERO
#\x1D7E2 ;MATHEMATICAL SANS-SERIF DIGIT ZERO
#\x1D7EC ;MATHEMATICAL SANS-SERIF BOLD DIGIT ZERO
#\x1D7F6 ;MATHEMATICAL MONOSPACE DIGIT ZERO
))
(define (digit-value ch) (digit-value* ch zeros))
(define (digit-value* ch zeros)
(if
(null? zeros)
#f
(let*
((val (char->integer ch))
(val0 (char->integer (car zeros)))
(val9 (+ val0 9)))
(if
(and (<= val0 val) (<= val val9))
(- val val0)
(digit-value* ch (cdr zeros))))))
}}}
CL provides this as `digit-char-p`, which is its substitute for `char-numeric?`.
raw-time
1341375516791126
ticket
220
time
2012-07-04 11:18:36
Change at time 2011-09-12 00:51:46
author
cowan
field
comment
newvalue
oldvalue
3
raw-time
1315763506000000
ticket
220
time
2011-09-12 00:51:46
Change at time 2011-09-12 00:51:46
author
cowan
field
owner
newvalue
cowan
oldvalue
alexshinn
raw-time
1315763506000000
ticket
220
time
2011-09-12 00:51:46
Change at time 2011-09-12 00:51:46
author
cowan
field
status
newvalue
writing
oldvalue
decided
raw-time
1315763506000000
ticket
220
time
2011-09-12 00:51:46
Change at time 2011-09-11 07:44:45
author
cowan
field
comment
newvalue
WG1 accepted this proposal.
oldvalue
2
raw-time
1315701885000000
ticket
220
time
2011-09-11 07:44:45
Change at time 2011-09-11 07:44:45
author
cowan
field
resolution
newvalue
oldvalue
raw-time
1315701885000000
ticket
220
time
2011-09-11 07:44:45
Change at time 2011-09-11 07:44:45
author
cowan
field
status
newvalue
decided
oldvalue
new
raw-time
1315701885000000
ticket
220
time
2011-09-11 07:44:45
Change at time 2011-07-23 11:39:19
author
cowan
field
comment
newvalue
This is particularly important now that `char-numeric?` has been defined to return `#t` on any Unicode numeric digit.
oldvalue
1
raw-time
1311395959000000
ticket
220
time
2011-07-23 11:39:19