diff --git a/library.scm b/library.scm
index 8ceb7de..defadb3 100644
a
|
b
|
EOF |
1070 | 1070 | (##sys#lcm head n2) |
1071 | 1071 | (##sys#slot next 1)) #f) ) ) ) ) ) ) |
1072 | 1072 | |
1073 | | (define (##sys#string->number str #!optional (radix 10)) |
1074 | | (##core#inline_allocate ("C_a_i_string_to_number" 4) str radix)) |
| 1073 | (define (##sys#string->number str #!optional (radix 10) exactness) |
| 1074 | (let ((num (##core#inline_allocate ("C_a_i_string_to_number" 4) str radix))) |
| 1075 | (case exactness |
| 1076 | ((i) (##core#inline_allocate ("C_a_i_exact_to_inexact" 4) num)) |
| 1077 | ((e) (##core#inline "C_i_inexact_to_exact" num)) |
| 1078 | (else num)))) |
1075 | 1079 | |
1076 | 1080 | (define string->number ##sys#string->number) |
1077 | 1081 | (define ##sys#number->string (##core#primitive "C_number_to_string")) |
… |
… |
EOF |
2526 | 2530 | (##sys#list->vector lst) |
2527 | 2531 | (##sys#read-error port "invalid vector syntax" lst) ) ) ) |
2528 | 2532 | |
2529 | | (define (r-number radix) |
| 2533 | (define (r-number radix exactness) |
2530 | 2534 | (set! rat-flag #f) |
2531 | 2535 | (let ([tok (r-token)]) |
2532 | 2536 | (if (string=? tok ".") |
2533 | 2537 | (##sys#read-error port "invalid use of `.'") |
2534 | | (let ([val (##sys#string->number tok (or radix 10))] ) |
| 2538 | (let ([val (##sys#string->number tok (or radix 10) exactness)] ) |
2535 | 2539 | (cond [val |
| 2540 | ;;XXX move this into ##sys#string->number ? |
2536 | 2541 | (when (and (##sys#inexact? val) rat-flag) |
2537 | 2542 | (##sys#read-warning |
2538 | 2543 | port |
… |
… |
EOF |
2547 | 2552 | (let ([c2 (##sys#read-char-0 port)]) |
2548 | 2553 | (cond [(eof-object? c2) |
2549 | 2554 | (##sys#read-error port "unexpected end of numeric literal")] |
2550 | | [(char=? c2 #\i) (##sys#exact->inexact (r-number radix))] |
2551 | | [(char=? c2 #\e) (##sys#inexact->exact (r-number radix))] |
| 2555 | [(char=? c2 #\i) (r-number radix 'i)] |
| 2556 | [(char=? c2 #\e) (r-number radix 'e)] |
2552 | 2557 | [else |
2553 | 2558 | (##sys#read-error |
2554 | 2559 | port |
2555 | 2560 | "illegal number syntax - invalid exactness prefix" c2)] ) ) ] |
2556 | | [else (r-number radix)] ) ) |
| 2561 | [else (r-number radix #f)] ) ) |
2557 | 2562 | |
2558 | | (define (r-number-with-radix) |
| 2563 | (define (r-number-with-radix exactness) |
2559 | 2564 | (cond [(char=? #\# (##sys#peek-char-0 port)) |
2560 | 2565 | (##sys#read-char-0 port) |
2561 | 2566 | (let ([c2 (##sys#read-char-0 port)]) |
2562 | 2567 | (cond [(eof-object? c2) (##sys#read-error port "unexpected end of numeric literal")] |
2563 | | [(char=? c2 #\x) (r-number 16)] |
2564 | | [(char=? c2 #\d) (r-number 10)] |
2565 | | [(char=? c2 #\o) (r-number 8)] |
2566 | | [(char=? c2 #\b) (r-number 2)] |
| 2568 | [(char=? c2 #\x) (r-number 16 exactness)] |
| 2569 | [(char=? c2 #\d) (r-number 10 exactness)] |
| 2570 | [(char=? c2 #\o) (r-number 8 exactness)] |
| 2571 | [(char=? c2 #\b) (r-number 2 exactness)] |
2567 | 2572 | [else (##sys#read-error port "illegal number syntax - invalid radix" c2)] ) ) ] |
2568 | | [else (r-number 10)] ) ) |
| 2573 | [else (r-number 10 exactness)] ) ) |
2569 | 2574 | |
2570 | 2575 | (define (r-token) |
2571 | 2576 | (let loop ((c (##sys#peek-char-0 port)) (lst '())) |
… |
… |
EOF |
2783 | 2788 | ((#\d) (##sys#read-char-0 port) (r-number-with-exactness 10)) |
2784 | 2789 | ((#\o) (##sys#read-char-0 port) (r-number-with-exactness 8)) |
2785 | 2790 | ((#\b) (##sys#read-char-0 port) (r-number-with-exactness 2)) |
2786 | | ((#\i) (##sys#read-char-0 port) (##sys#exact->inexact (r-number-with-radix))) |
2787 | | ((#\e) (##sys#read-char-0 port) (##sys#inexact->exact (r-number-with-radix))) |
| 2791 | ((#\i) (##sys#read-char-0 port) (r-number-with-radix 'i)) |
| 2792 | ((#\e) (##sys#read-char-0 port) (r-number-with-radix 'e)) |
2788 | 2793 | ((#\c) |
2789 | 2794 | (##sys#read-char-0 port) |
2790 | 2795 | (let ([c (##sys#read-char-0 port)]) |
… |
… |
EOF |
2852 | 2857 | ((#\() (r-list #\( #\))) |
2853 | 2858 | ((#\)) (##sys#read-char-0 port) (container c)) |
2854 | 2859 | ((#\") (##sys#read-char-0 port) (r-string #\")) |
2855 | | ((#\.) (r-number #f)) |
2856 | | ((#\- #\+) (r-number #f)) |
| 2860 | ((#\.) (r-number #f #f)) |
| 2861 | ((#\- #\+) (r-number #f #f)) |
2857 | 2862 | (else |
2858 | 2863 | (cond [(eof-object? c) c] |
2859 | | [(char-numeric? c) (r-number #f)] |
| 2864 | [(char-numeric? c) (r-number #f #f)] |
2860 | 2865 | ((memq c reserved-characters) |
2861 | 2866 | (reserved-character c)) |
2862 | 2867 | (else |