edw on 23 Aug 2007 12:50:11 -0000


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

[philly-lambda] Re: Good references for syntax-case?


I agree with Andrew: that chapter of TSPL is a pretty good guide to
SYNTAX-CASE macros. Kent devised SYNTAX-CASE, I believe.

But -- and I say this as someone whose comment got modded down to
negative eight or so in the Reddit discussion -- SYNTAX-CASE and
unhygienic macros are evil. A few Scheme programming tips:

* If you think you need to use EVAL, you're probably wrong.
* If you think you need to use a macro, you're probably wrong.
* If you think you need to use unhygienic macros, you're probably
wrong.

What are you trying to do?

I wrote an article a year or two ago on Python generators, Java 1.5,
and why most programming languages suck:

<http://xmog.com/java-sucks/>

In it I developed a SYNTAX-RULES macro for defining generators. Pascal
Costanza took me to task for my too-quick use of macros. He said what
I could do could be done with macros of any kind. I blew him off. Last
week, I was thinking about his comments and wondered if it was
possible to do what he said was possible. It is, and the source is
included at the end of this message. I'm going to update my article
when I get a chance. The point is no longer will no longer be that
"macros let you bend real programming languages to your will" but that
"first-class continuations and procedures and (maybe, sometimes)
macros let you bend real programming languages to your will."

(define fibonacci
  (make-generator
   (lambda (yield)
     (let loop ((a 0) (b 1))
       (loop b (+ (yield a) b))))))

(define generator-complete (vector "generator complete"))

(define (make-generator proc)
  (let ((continue #f))
    (lambda arguments
      (call-with-current-continuation
       (lambda (exit)
         (if (not continue)
             (let ((yield
                    (lambda return-values
                      (apply (lambda return-values
                               (call-with-current-continuation
                                (lambda (k)
                                  (set! continue
                                        (lambda () (apply k return-
values)))
                                  (apply exit return-values))))
                             return-values))))
               (apply proc yield arguments)
               coroutine-complete)
             (continue)))))))


On Aug 23, 7:37 am, Andrew Gwozdziewycz <apg...@gmail.com> wrote:
> On Aug 22, 2007, at 9:50 PM, Kyle R. Burton wrote:
>
>
>
> > I've found JRM's primer [1] on syntax-rules to be mind-expanding, but
> > I was wondering if anyone had any good references for syntax-case.
> > I'm asking because something went across p.r.c today asking about the
> > differences between CL and Scheme's macro systems and syntax-case came
> > up a lot in the comments/discussion.
>
> You might try out _The Scheme Programming Language_ chapter freely
> available herehttp://scheme.com/tspl3/syntax.html#./syntax:h3
> It's from R. Kent Dyvbig, who I *think* is the original author (or  
> one of) of syntax-case.
>
> It's not as enlightening as JRM's primer on syntax-rules, but if you  
> now are
> comfortable with syntax-rules, syntax-case does nothing more than  
> allow you to
> break hygiene. The pattern language is still the same. The only thing  
> to really
> learn are the techniques used to create the unhygienic portions of  
> your macro. I
> admittedly haven't done much with syntax-case, so I may be off a bit.
>
> Good Luck
>
> --
> Andrew Gwozdziewycz
> apg...@gmail.comhttp://www.apgwoz.com |  http://www.photub.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Philly Lambda" group.
To unsubscribe from this group, send email to philly-lambda-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/philly-lambda?hl=en
-~----------~----~----~----~------~----~------~--~---