[R6RS] SYNTAX-CASE

Manuel Serrano Manuel.Serrano
Fri Apr 8 03:01:22 EDT 2005


> I'm curious on how you'd like to change this particular bit of the
> notation.  (I also rather like the ... notation, as it allows me to
> express nesting and its decomposition in a---to me---intuitive
> manner.)  Previously, I was under the impression you wanted to propose
> using a variation of the Bigloo matching facility---but that also has
> ..., right?  Could you give a preview?
When I have added added R5Rs macros to Bigloo I have looked at various
implementations for DEFINE-SYNTAX and SYNTAX-RULE. At that time I have failed
to find a100% compliant implementation (except, may be, Kent's one, I don't 
remember). More surprisingly I have noticed that it was relatively easy to
design relatively tricky patterns using ellipses that were confusing these
implementations. That is, for this patterns the implementations I have tested
were producing totally different results. At that time, I have even noticed
that for some patterns using ellipses I was not even sure of what the result
was supposed to be! I will try to give you examples as soon as I will
start working on the pattern matching language.

Bigloo does support ellipses but in a way that is different from the
R5Rs' one. The R5Rs the pattern:

   (foo ...)

is written in Bigloo

   (foo . ?ellipse)

I think that naming ellipses avoid confusion. For instance, how would
you write the following macro in R5Rs pattern matching style:

    (define-expander foo
       (lambda (x e)
          (match-case x
             ((?- (bar1 (gee (hux . ?ellipse1) . ?ellipse2) . ?ellipse3)
                  (bar2 (gee (hux . ?ellipse4) . ?ellipse5) . ?ellipse6)
              SOMETHING THAT USES ALL THE ELLIPSES
             (else
              ...))))

It also enlarges the set of transformations you can operate in the results
of the expansion. In the following example, the ellipses are inverted.

    (define-expander flatten
       (lambda (x e)
          (match-case x
             ((?- (foo . ?rest1) (bar . ?rest2))
              (e `(begin , at rest2 , at rest1) e))
             (else
              ...))))

Naming ellipses also permits non linear patterns such as:

    (define-expander flatten
       (lambda (x e)
          (match-case x
             ((?- (foo . ?rest1) (bar . ?rest1))
              ;; matches if (foo ...) and (bar ...) are equal
              (e `(begin , at rest1) e))
             ((?- (foo . ?rest1) (bar . ?rest2))
              (e `(begin , at rest2 , at rest1) e))
             (else
              ...))))

-- 
Manuel


More information about the R6RS mailing list