Re: Implementation suggestions Lassi Kortela 26 Feb 2020 18:02 UTC

>> - Rewrite `maybe-read-number` so it doesn't rely on regular expressions
>> and `string->number`. This would remove the dependency on (chibi regexp)
>> making it easier to port SRFI 180 to other R7RS Schemes.
>
> I will not fix it myself.
>
> scheme regex is in r7rs-large. Recoding string->number to only accept
> JSON text numbers would be difficult.

(define (read-valid-number-and-eof?)
   (define (read-char? goal1 goal2)
     (let ((char (peek-char)))
       (and (not (eof-object? char))
            (or (eqv? goal1 char) (eqv? goal2 char))
            (begin (read-char) #t))))
   (define (read-char-range* minch maxch)
     (let loop ((found? #f))
       (let ((char (peek-char)))
         (if (or (eof-object? char) (not (char<=? minch char maxch)))
             found? (begin (read-char) (loop #t))))))
   (read-char? #\- #f)
   (and (or (read-char? #\0 #f)
            (and (read-char-range* #\1 #\9)
                 (begin (read-char-range* #\0 #\9) #t)))
        (or (not (read-char? #\. #f))
            (read-char-range* #\0 #\9))
        (or (not (read-char? #\e #\E))
            (begin (read-char? #\+ #\-)
                   (read-char-range* #\0 #\9)))
        (eof-object? (peek-char))))

(define (valid-number? string)
   (with-input-from-string string read-valid-number-and-eof?))

> I integrated some of your suggested changes.

Thank you.

> Feel free to make a pull request against my fork at:
>
>    https://github.com/amirouche/srfi-180
>
> I do not plan to change more code until the second draft is published,
> so there will be no merge conflicts if you only edit code. Do not
> forget to add yourself to the copyright notice in srfi-180.html.  We
> should also add copyright headers or spdx tags?
>
> I will work on the specification.

Again, thanks for your continued efforts.