[R6RS] How to make -> a valid identifier [was: 3 things we may want to vote on]

Michael Sperber sperber
Wed Jun 8 03:12:42 EDT 2005


Marc Feeley <feeley at iro.umontreal.ca> writes:

> I'm all for it, and even more.  But how to specify it, in an easily  
> understandable way?

That's definitely the issue.  I'd be interested how the readers in the
various Scheme implementations work.  The relevant part in the Scheme
48 reader goes like this when it sees a token that's either a
numerical literal or a symbol:

(define (parse-token string port)
  (if (let ((c (string-ref string 0)))
	(or (char-numeric? c) (char=? c #\+) (char=? c #\-) (char=? c #\.)))
      (cond ((string->number string))
	    ((member string strange-symbol-names)
	     (string->symbol (make-immutable! string)))
	    ((string=? string ".")
	     dot)
	    (else
	     (reading-error port "unsupported number syntax" string)))
      (string->symbol (make-immutable! string))))

This could easily be simplified to:

(define (parse-token string port)
  (if (let ((c (string-ref string 0)))
	(or (char-numeric? c) (char=? c #\+) (char=? c #\-) (char=? c #\.)))
      (cond ((string->number string))
	    ((string=? string ".") dot)
	    (else
	     (string->symbol (make-immutable! string))))
      (string->symbol (make-immutable! string))))

... and I suspect many other readers work this way as well.  This
suggests specifying the lexical syntax in a similar way,
i.e. essentially:

<token constituent> -> ! | $ | % | & | * | + | - | . | / | | : | < | = | > | ? | @ | ^ | _ | ~
                     | <digit> | < letter>
<token> -> <token constituent>+

... and then saying that any <token> that also matches <number> is
indeed a number, and the rest are identifiers.  (We may want to omit
<digit> from the initial characters of a symbol.  But note that 1+ and
1- also have some tradition in the Scheme community---I believe SICP
1st edition used them.)

-- 
Cheers =8-} Mike
Friede, V?lkerverst?ndigung und ?berhaupt blabla


More information about the R6RS mailing list