[plt-scheme] Help with ...

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Sat May 16 13:34:36 EDT 2009

Maybe I should have put quotation marks around the ... so you'd know that
was what I needed help with. :-)

At any rate, I'm working through Eli Barzilay's CSU660 (Programming
Languages) assignments, which are largely based on Shriram Krishnamurthi's
PLAI, and I've had some issues with understanding ... already, but they've
finally come to a head.

Eli provided this macro:

(provide rewrite (for-syntax ...))
(define-syntax (rewrite stx)
  (define (sym=? x y)
    (eq? (if (identifier? x) (syntax-e x) x)
         (if (identifier? y) (syntax-e y) y)))
  (syntax-case* stx (=>) sym=?
    [(rewrite (name . xs) => y more ...)
     (let loop ([stx #'(more ...)] [clauses (list #'[(name . xs) y])])
       (syntax-case* stx (=>) sym=?
         [((x . xs) => y more ...) (free-identifier=? #'x #'name)
          (loop #'(more ...) (cons #'[(x . xs) y] clauses))]
         [() (with-syntax ([(clause ...) (reverse clauses)])
               (syntax/loc stx
                 (define-syntax name
                   (syntax-rules () clause ...))))]))]))

And I'm supposed to rewrite letfuns so that it can handle mutually recursive
functions. More concretely, I write

(rewrite (letfuns ([(f x) E] ...) B)
         => (my-code-here))

so that something like this

(letfuns
  ([(even? n) (if (= n 0) #t (odd? (- n 1)))]
   [(odd? n) (if (= n 0 #f (even? (- n 1))))])
         (even? 123))

would produce the expected answer.

I think I understand what I need to do if I could figure out what the heck
that ... is doing.

I think f ends up as a list of all the function names, x as a list of all
the function arguments, and E as a list of all the bodies. I need to convert
that into a big (match name ---) expression with a branch for each function
name. I'd like to do something like

(match name
   ['f? (more stuff here including things from x and E)] for each value in
f, x, and E

but I don't want for-each and I'm not even sure I can build up a list of
branches this way. I *am* sure that I don't know how to do it if it's
possible.

So, two things:

1. Which function am I looking for to handle this example?, and

2. Is there a good, very basic, easy to understand explanation of what ...
does in patterns that someone could suggest?

Thanks,
Todd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090516/ee32106f/attachment.html>

Posted on the users mailing list.