Maybe I should have put quotation marks around the ... so you'd know that was what I needed help with. :-)<br><br>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.<br>
<br>Eli provided this macro:<br><br>(provide rewrite (for-syntax ...))<br>(define-syntax (rewrite stx)<br> (define (sym=? x y)<br> (eq? (if (identifier? x) (syntax-e x) x)<br> (if (identifier? y) (syntax-e y) y)))<br>
(syntax-case* stx (=>) sym=?<br> [(rewrite (name . xs) => y more ...)<br> (let loop ([stx #'(more ...)] [clauses (list #'[(name . xs) y])])<br> (syntax-case* stx (=>) sym=?<br> [((x . xs) => y more ...) (free-identifier=? #'x #'name)<br>
(loop #'(more ...) (cons #'[(x . xs) y] clauses))]<br> [() (with-syntax ([(clause ...) (reverse clauses)])<br> (syntax/loc stx<br> (define-syntax name<br> (syntax-rules () clause ...))))]))]))<br>
<br>And I'm supposed to rewrite letfuns so that it can handle mutually recursive functions. More concretely, I write<br><br>(rewrite (letfuns ([(f x) E] ...) B)<br> => (my-code-here))<br><br>so that something like this<br>
<br>(letfuns <br> ([(even? n) (if (= n 0) #t (odd? (- n 1)))]<br> [(odd? n) (if (= n 0 #f (even? (- n 1))))])<br> (even? 123))<br><br>would produce the expected answer.<br><br>I think I understand what I need to do if I could figure out what the heck that ... is doing.<br>
<br>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<br>
<br>(match name<br> ['f? (more stuff here including things from x and E)] for each value in f, x, and E<br><br>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.<br>
<br>So, two things:<br><br>1. Which function am I looking for to handle this example?, and<br><br>2. Is there a good, very basic, easy to understand explanation of what ... does in patterns that someone could suggest?<br>
<br>Thanks,<br>Todd<br>