[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Choose-Your-Own-Ellipsis



> From: Taylor Campbell <campbell@xxxxxxxxxxxx>

> In improving Andre van Tonder's monadic CPS macro stuff, I wrote an
> MSYNTAX-RULES.

> But I found this problem: should the user not specify the ellipsis,
> and let it default to ..., how will MSYNTAX-RULES deal with it?

Your code is too fragmentary for me to understand what you're trying
to do.  You talk about expanding into a SYNTAX-RULES form, but in
r5rs, any macro use must ultimately expand into an expression,
definition, or BEGIN form.  I guess what you're trying to write is
something like this:

  (define-syntax define-msyntax-rules
    (syntax-rules ()
      ((define-msyntax-rules name ?ellipsis ?literals
	 ((?ignored . ?pattern)
	  (?macro . ?args))
	 ...)
       (define-syntax name
	 (syntax-rules ?ellipsis ?literals
	   ((?ignored (k ?ellipsis) . ?pattern)
	    (?macro (k ?ellipsis) . ?args))
	   ...)))))

  I
> Am I missing some macro magic here, is there a problem with choose-
> your-own-ellipsis, or should the implicit ... stuff be thrown away?
> The last option would break lots of macros, and it would look rather
> ugly to me, but I can't think of a better way to solve this.

If we specified that syntax-rules from now on requires an ellipsis
argument, then that would of course break the entire existing body of
syntax-rules macros.

However, if you specify that define-msyntax-rules requires an ellipsis
argument, I don't think there's any body of define-msyntax-rules code
out there to be worried about breaking.

Nevertheless, if you want define-msyntax-rules's ellipsis argument to
be optional, with the implicit (and essentially non-hygienic) choice
of "..." when it is missing, you could do this:

  (define-syntax define-msyntax-rules
    (syntax-rules ::: ()
      ((define-msyntax-rules name (?literal :::)
	 ((?ignored . ?pattern)
	  (?macro . ?args))
	 :::)
       (define-syntax name
	 (syntax-rules (?literal :::)
	   ((?ignored (k ...) . ?pattern)
	    (?macro (k ...) . ?args))
	   :::)))
      ((define-msyntax-rules name ?ellipsis ?literals
	 ((?ignored . ?pattern)
	  (?macro . ?args))
	 :::)
       (define-syntax name
	 (syntax-rules ?ellipsis ?literals
	   ((?ignored (k ?ellipsis) . ?pattern)
	    (?macro (k ?ellipsis) . ?args))
	   :::)))))


> What are some thoughts on non-linear patterns and guards

I think they are probably incompatible with the title of the SRFI,
"Basic SYNTAX-RULES Extensions".

-al