[racket] syntax-parse and literals

From: Shriram Krishnamurthi (sk at cs.brown.edu)
Date: Fri Sep 2 22:10:27 EDT 2011

That fixed the problem, thanks.

I was disappointed by some of the resulting error messages, though.
I'm bringing these up here because I don't know whether these error
messages are an artifact of the strategy Jay suggested.

To simplify, suppose I have

(define-syntax (defvar: stx)
  (syntax-parse stx #:literals(:)
   [(_ i:id : C:expr b:expr)

Here are some errors:

  (defvar: y : 4)
  -> defvar:: bad syntax in: (defvar: y : 4)

Could have indicated a missing expression?

  (defvar: y number? 4)
  -> defvar:: expected the identifier `:' in: number?

I have two nits with this:

- : is meant to be a literal, not an identifier, and

- the prose "expected the identifier `:' _in_ number?" is particularly
bad (putting a ":" inside "number?" isn't going to change anything --
it means "in place of" or "before", not "in").

It might have been better to just say that the literal : is missing,
and it was expected in the position where "number?" is.

  (defvar: : number? 4)
  -> defvar:: expected the identifier `:' in: number?

Ditto.  It would have been more useful, I think, to indicate that an
identifier needs to precede :.  Now the literal/identifier confusion
seems especially strong because it seems to have taken : for the i:id.


Posted on the users mailing list.