On Thu, 15 Jul 2010 23:08:27 -0700 (PDT)
Quzanti <quza...@googlemail.com> wrote:

> Kyle
> 
> I think I understand what you are saying.
> 
> So in practice you should prevent functions called from a macro from
> evaluating the records (using quoting), so that the output is in a
> form that looks like source code should?
> 

Precisely; I think my first instinct would be that macros should
probably only expand to forms that look like regular Clojure source.

However there are situations where it is appropriate and indeed very
useful to unquote function calls in a macro. For example you may wish to
call some regular function that returns a data structure which you then
insert into the macro expansion. Personally I find this is actually
a very useful technique for writing macros: write a regular, private
function that does the "hard work" of transforming the source code data
structures without having to worry about macros' "abnormal" evaluation
rules, and then call that function from a much simpler macro, inserting
the result in the macro expansion using unquote.

However, I would think any data structure returned from a function used
in this way would still need to be something that can be interpreted as
Clojure source code: lists, vectors, maps, and sets containing symbols,
keywords, and so on. Any sort of user defined objects or Java objects,
*as far as I can tell*, don't make any sense in the result of a macro
expansion, but that is why I wrote this part:

> > What I don't know is, is it meaningful for a macro to expand to
> > something that contains stuff that couldn't ever appear in the
> > output of the reader, like instances of user-defined types, or even
> > Java objects for that matter? What is the expected behavior here?
> >

This was actually sort of an open question to the Clojure experts on the
mailing list, since I'm not actually sure about the answer. Should
this be done at all? Is it always an error (or at least bad style), or
should/could it be a meaningful operation in some cases? As I said, I
don't see any useful reason to do this, but maybe I just can't think of
one. I'd be interested to know what others think.

-Kyle

-- 
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