On Sat, 17 Jul 2010 00:59:35 -0700 (PDT)
Quzanti <quza...@googlemail.com> wrote:

> Thanks Michał
> 
> I suppose this raises a deeper question - should an expression and
> what it evaluates to always be interchangeable in source code?

This is essentially what I was trying to say, stated much more
clearly :)

> On Jul 17, 2:18 am, Michał Marczyk <michal.marc...@gmail.com> wrote:
> > This is an instance of the broader issue whereby records currently
> > evaluate to maps. There was a ticket open for that on Assembla. I'm
> > not sure what's the current status on that, but whenever it gets
> > fixed, macros will be able to use records in their expansions.
> >

I was asking about other things as well besides records, like Java
objects or fn's or other objects that the reader would never emit, but
that a macro conceivably could. Is it specified behavior (modulo the
"records evaluate as maps" bug) that *anything* that isn't a list or
symbol evaluates to itself if it appears in a macro-expansion or is
otherwise eval'ed?

Here's an example that doesn't work, but should by this hypothetical
evaluate-to-self rule which I just made up. Bug, unspecified behavior,
or have I just made a mistake?

  ;; Regular run-of-the-mill macro, works fine. Expansion only contains
  ;; things that can be read.

  user=> (defmacro list-of-list [action]
           `(println (~action)))
  #'user/list-of-list
  user=> (macroexpand '(list-of-list (constantly 1)))
  (clojure.core/println ((constantly 1)))
  user=> (list-of-list (constantly 1))
  1
  nil

  ;; Martian macro. Note the expansion contains the actual fn instead
  ;; of the expression that creates it. The reader would never output
  ;; such a construction.

  user=> (defmacro list-of-fn [action]
           `(println (~(eval action))))
  #'user/list-of-fn
  user=> (macroexpand '(list-of-fn (constantly 1)))
  (clojure.core/println (#<core$constantly__4695$fn__4697
      clojure.core$constantly__4695$fn__4...@7087e9bf>))
  user=> (list-of-fn (constantly 1))
  #<CompilerException java.lang.ExceptionInInitializerError (REPL:14)>

-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