Re: Python gets macros - now XML does too

From: Manuel Lemos (mlemos_at_acm.org)
Date: 01/12/05


Date: Wed, 12 Jan 2005 01:19:12 -0200

Hello,

on 01/05/2005 06:19 AM Adrian Kubala said the following:
> Manuel Lemos <mlemos@acm.org> schrieb:
>>MetaL compiler flow module provides support for level 0 (macro
>>expansion) metaprogramming but IMO that is a very limited form of
>>metaprogramming.
>
> Not in Lisp. In Lisp, with macro expansion you can do arbitrary
> source->source transformations, using the full power of Lisp to do so.
> Which I think is what you mean by:
>
>>The real power comes from level 2 metaprogramming features and
>>eventually beyhond. Level 2 means that you write a code specification in
>>an high level syntax. That that specification is translated into MetaL
>>level 1/level 0 XML source code, which gets translated to the final
>>target language of choice.
>
> I guess the special thing about Level 2 is the translation can be
> arbitrarily complex, which is true of Lisp macros. And in practice, Lisp
> macros are often used to implement the "compilation" of a high-level
> domain-specific language as you describe.

This explanation sounds confusing to me. Are you saying that you can use
LISP macros to generate code in another language, say PHP, Java, Perl,
etc...?

You see, I do not have an interest now in using Lisp specifically.
Actually my main concern right now is PHP. I just developed MetaL
because I may need to switch to start developing in other languages.

So, if Lisp macros are only useful for those that program in Lisp, they
are indeed a limited form of metaprogramming as I stated above.

>>Despite currently I only use PHP because I only develop Web
>>applications, I don't know about the future. If I need to switch to
>>another target language, I just need to develop the lower level
>>translation modules of MetaL to support another language, and so my
>>current work supporting PHP applications will not be wasted.
>
> Something about this doesn't make sense to me, but it's hard to put my
> finger on it. It just seems like, to whatever degree two languages are
> different enough that you'd choose one over the other, it would be that
> much harder (and pointless) to create one source file that generates
> good libraries for both. Like if you use Java it's probably because you
> want packages, Swing, the JVM, threads, or static typing, and if you use
> PHP it's probably because you want dynamic typing, eval, builtin
> bindings for every useful-for-web-apps C library in existence, and so
> on, and by programming in MetaL you get neither.
>
> There's opportunities for convergence but I personally think it's at the
> level of the virtual machine, and even there you get impedance
> mismatches -- there's complaints that all the .Net CLR-supported
> languages are just superficial variations on C#, and you can bet we'll
> never see a good Haskell->CLI compiler.

You seem to be making too many assumptions about the potential of MetaL
without really knowing it.

The MetaL engine is implemented by modules that generate code in a
target language that may indeed use certain libraries that may even
exist only for a specific language.

Most MetaL modules for specific purposes, say database access for
instamce, indeed generate code that calls existing libraries specific
for each language. If I need a module to work for a different language I
may have to develop adapter code that implements equivalent
functionality for the new language.

As you may understand by now, the portability is not immediately
guaranteed. Some work may need to be done to support a new language.
This is still a fraction of the work that I would have to do if I had to
rewrite my applications that depend specific purpose libraries.

For instance, Metastorage is a level 2 metaprogramming application for
generating classes that basically perform object relational mappings.
The part that generates level 1 code will not need to be touched to
support a new language.

-- 
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/
Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html


Relevant Pages

  • Re: Python gets macros - now XML does too
    ... >>final target language of choice. ... Currently PHP, Java, and Perl are ... > What you called level 2 metaprogramming is possible in Lisp, ... of business in 1994 and that marked the end of the Amiga computers era, ...
    (comp.lang.lisp)
  • Re: Two questions together
    ... How powerful are the macros? ... > "programmable language" and as far as I know this feature is provided ... It is also said that one can hammer the Lisp so that ... I really love Lisp's syntax:) But I just want ...
    (comp.lang.lisp)
  • Re: macro for shorter array syntax
    ... How is OCaml on adding readmacros, which Lisp can do easily. ... I would not ask that of a parsed language. ... We're confident that using macros is useful to us, ... debate has legitimate points on both sides. ...
    (comp.lang.lisp)
  • Re: Python gets macros - now XML does too
    ... >> use LISP macros to generate code in another language, say PHP, Java, ... > bytecode, PHP is simple. ...
    (comp.lang.lisp)
  • Re: A "killer" macro
    ... but then Ruby is dog slow anyway: ... Having notational convenience via macros plus efficiency is a big win ... From my perspective as a Ruby programmer learning Lisp, ... thought of having a more powerful language *and* orderof magnitude ...
    (comp.lang.lisp)