Page 1 of 1

Makros in Dylan, CL, Schene

Posted: Mon Apr 12, 2010 5:26 pm
by nickik
Hallo all,

I have started learning dylan a while ago (3-4 weeks). At the time I wasn't realy interessted in Programming Languages. Didn't know about LISP whene I listen to a podcast about dylan (in witch talked about all the history). That got my interessted in Programming Languages and there diffrences. Since then im learning dylan. I only learnd C,C#, VB in school and at work for two years.

So mutch about me. I learnd dylan makros and heard a lot about LISP (CL) Makros. I want to learn CL or Scheme at some point too but I don't have the time atm.

So what I wanted to ask.
What are the diffrences of the makro systems?
Does one of them have more power?

The dylan one is probably more verbose is there more?

(I only know that CL has the meta object protocall witch isn't included in dylan)

Re: Makros in Dylan, CL, Schene

Posted: Tue Apr 13, 2010 8:03 am
by Jasper
'Full power' for macros is essentially that you can do anything with their input. (Although i have once implemented a type calculation system that could also give macros access to the type calculator and hance also has access to types. I think it is a bad idea to actually use that. Working on a little writeup about that)

In CL one can actually do pretty much everything with the input/output, it is just an arbitrary function upon code. Not sure about Scheme, i think they have such macros, but i think they had something to make especially limited macros with.(As can be done in a library in CL, of course) I keep macros in a subset myself. I heard about Dylan, but don't really know anything about it.

Re: Makros in Dylan, CL, Schene

Posted: Tue Apr 13, 2010 9:09 pm
by nuntius
Dylan is a Lisp descendant, with an Algol-like syntax added. As such, I've heard its macro system is rather powerful.

Common Lisp has a "primitive" macro system in that you simply register functions (macros) with the compiler. They get passed lists of symbols (code), do whatever they want, and return the code to compile.

Scheme has what are known as hygienic macros. Apparently Dylan's macros are hygienic as well. Hygiene protects against a certain class of errors; but there are cases when those "errors" are intentional. One of the big YMMV flame wars in lisp.

Pascal Costanza showed how to layer hygiene on CL macros.

Re: Makros in Dylan, CL, Schene

Posted: Sat Apr 17, 2010 7:24 am
by Kompottkin
Common Lisp's macro system is defmacro, which is a procedural macro system that allows you to execute arbitrary Lisp code at macro expansion time to transform code represented as data structures in quite a natural way. defmacro is very powerful, yet simple to understand and use.

The macro system of R5RS is syntax-rules, a hygienic, pattern-matching macro system. In contrast to defmacro, you cannot simply execute Scheme code in your syntax-rules macros. Instead, you must transform code using a special rule language. syntax-rules provides automatic hygiene, and most macros written using it are arguably more readable than the same ones written using defmacro, but on the other hand, the syntax-rules language is pretty limited, which makes the macro system awkward to use in more complex cases and consequently less general than defmacro in practice.

Finally, R6RS adds yet another macro system, which is called syntax-case. It tries to combine the benefits of both procedural and pattern-matching macro systems by unifying the two concepts. This yields a macro system that is both hygienic by default and strictly more powerful than defmacro(*), but also adds a significant amount of complexity.

There are also other approaches to combining the power of procedural macros with hygiene, such as syntactic closures and explicit renaming. Support in Scheme systems tends to vary, and I'm not aware of a Common Lisp implementation that supports any kind of procedural hygienic macros, but if you're interested in learning more about macro systems, these are some things to google for.

Personally, I like the trade-off between power and simplicity chosen by defmacro, but I must confess that I don't have any real-world experience in using other kinds of macro systems, so take this opinion with a grain of salt.

(*)or at least it seems so, see for example: http://groups.google.com/group/comp.lan ... 7a167f4589