Hello,

2010/9/9 Sean Corfield <seancorfi...@gmail.com>:
> On Wed, Sep 8, 2010 at 7:28 AM, CuppoJava <patrickli_2...@hotmail.com> wrote:
>> I found the easiest way to introduce macros is just to introduce them
>> as small syntactic sugaring. For example, getting rid of the explicit
>> (fn [] ...) for macros like (with-open file ...).
>
> Interesting. I don't see any real difference between macros and C
> preprocessor stuff and C++ templates at a conceptual level. I think
> Clojure macros are much cleaner, but essentially they are similar. So
> in the Java world, generics (templates) are not yet widely used
> outside the libraries and maybe that's why Java devs find macros hard
> to comprehend?

I think that even at the conceptual level, the differences are big:

  a. C/C++ is a "pre-processor". It does a first pass on the code.
Only at the end is the C/C++ compiler invoked. In Lisps, there is
still this "first pass/second pass" thing, but it's at a waay finer
granularity level: the top level form. At the end of the evaluation of
each top level form, a new macro may have been defined and can be
called immediately by the next top level form. So not only is the
"set" of macros not closed in Lisp (and in C/C++, to some extent, it's
also not closed, even if rather limited), but it can be expanded
during the compilation of the "program".
  b. The second major difference is that you stay in the same language
for writing macros or non macros code in Lisp, whereas you have a
preprocessor language with very limited possibilities in C/C++. Same
language in the syntactic and semantic level. Macro/non-macro code
executions are intermingled.

But maybe I'm overemphasizing things.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to