[plt-scheme] Help with ...

From: Eli Barzilay (eli at barzilay.org)
Date: Sat May 16 16:22:19 EDT 2009

On May 16, Todd O'Bryan wrote:
> 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:
> [...]

FWIW, understanding what this macro is doing is not necessary for the

> 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.

Yes.  To be a little more specific, when you say "`f' ends up as a
list of all function names" -- the way that `f' is related to that is
by binding it as a "pattern identifier", it doesn't have a real value,
and can only be used on output patterns on the right side of the `=>'.

> 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.

Well, since `f' (for example) is the list of function names, you could

  (rewrite (letfuns ([(f x) E] ...) B)
           => (list 'f ...))

This will make a `letfuns' expression evaluate to a list of the
function names as symbols.

> So, two things:
> 1. Which function am I looking for to handle this example?, and

You're just using `...' on the right side to do the right thing.
There are of course some `map's that are used somewhere to actually
construct the result, but for most such code (and definitely for this
hw), you don't need to know how exactly it is implemented.

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

[I pointed Todd to the relevant part in my notes.]

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.