jdevries@zodiac.UUCP (11/01/87)
(This has posted to the Scheme mailing list. I've learned that there may be interest here, so I'm posting it here also...) In the book "The Scheme Programming Language", Kent Dybvig describes a powerful tool for syntactic extension called extend-syntax. Basically, it allows you to specify transformations from input representations to the corresponding code to be executed. For a quick example, consider we wish to implement the LET syntactic form. This could be done with extend-syntax as follows: (extend-syntax (PIGLET) ((PIGLET ((x v) ...) e1 e2 ...) (andmap symbol? '(x ...)) ((lambda (x ...) e1 e2 ...) v ...))) This would define a new syntactic form (i.e. macro) named PIGLET that translates things of the form (PIGLET ((x v) ...) e1 e2 ...) to the corresponding LAMBDA form after verifying that all the x's are symbols. Notice the powerful pattern matching abilities provided by using the ellipsis (...). There is a *LOT* more to extend-syntax than this example would indicate. For the full glories, (defstruct in about 20 lines of code, objects (as in OOP) in about the same), see the book. Well, I coveted the power of extend-syntax and desired it greatly, so I asked Kent Dybvig if he would part with the necessary incantations... Behold! I had Mail! (thanks kent!) I am running MacScheme Version 1.22 and have converted the extend-syntax code to work under such. If you would like a copy, send me e-mail to that effect and I'll see that a copy is sent to you. If I get swamped with requests, I might just post the whole thing to here. Jeff De Vries (ARPA: jdevries@ads.arpa)
dwt@zippy.eecs.umich.edu (David West) (11/13/87)
In article <756@zodiac.UUCP> jdevries@zodiac.UUCP (Jeff De Vries) writes: >I am running MacScheme Version 1.22 and have converted the extend-syntax >code to work under such. If you would like a copy, send me e-mail to >that effect and I'll see that a copy is sent to you. If I get swamped >with requests, I might just post the whole thing to here. Post it!