Hi Konrad,

many thanks. Thats stuff to ponder ;-)

(map (fn [s v]  `(def ~s ~v)) '(a b c) '(1 2 3))

Thats impressive. I'm still, hm, puzzled. Nice example of something
that can only be done with syntax-quote, and outside of a macro. (Or
can this be done without syntax-quote, and I just dont see it?)

Is there any predicate like (macro? my-macro), and, if we are at it
(special-form? my-form) ?

We could even generalise map with the thing you just described!(?)


One more thing. I'm still heavily irritated about the expansion of
'`(foo (bar ~a) ~b)


>From clojure.org/reader, I learned "For Lists/Vectors/Sets/Maps,
syntax-quote establishes a template of the corresponding data
structure.", and from that, what I expected was
(user/foo (user/bar a) b)

Why is this so utterly wrong, and where should I know?

Many thanks, alux

On 3 Jun., 11:51, Konrad Hinsen <konrad.hin...@fastmail.net> wrote:
> On 03.06.2010, at 10:36, alux wrote:
>
> > 1. I can use syntax-quote in the REPL, outside of a macro-definition.
> > Is this of any use? Does this mean the REPL always macroexpands
> > everything?
>
> Macro expansion is part of evaluation, whether at the REPL or elsewhere.
>
> Syntax quote is not macro expansion. It is a shorhand to write code that, 
> when executed, returns a specific form. It is more frequently used in macro 
> definitions, but you can use it anywhere. You can even look at the code it 
> generates:
>
> Clojure> '`(foo (bar ~a) ~b)
> (clojure.core/seq (clojure.core/concat (clojure.core/list (quote 
> clojure.core/foo)) (clojure.core/list (clojure.core/seq (clojure.core/concat 
> (clojure.core/list (quote clojure.core/bar)) (clojure.core/list a)))) 
> (clojure.core/list b)))
>
> > 2. maxroexpand and macroexpand-1 dont extend macros in subforms. Is
> > there anything that does?
>
> clojure.contrib.macro-utils/mexpandall
>
> > 3. Is there a way to use macros in higher order functions? Say along
> > the lines of
>
> > (map def [a b c] [1 2 3])
>
> No. Macros are not functions. BTW, def is a special form, not a macro. But 
> neither can be passed as a function.
>
> What you can do, however, is this:
>
> Clojure> (map (fn [s v]  `(def ~s ~v)) '(a b c) '(1 2 3))
> ((def a 1) (def b 2) (def c 3))
>
> Add a "do" in front, and you can pass it to eval:
>
> (eval (cons 'do (map (fn [s v]  `(def ~s ~v)) '(a b c) '(1 2 3))))
>
> > Btw, am I right that this might be possible in a lazy language?
>
> It's not impossible to imagine such a language, but I don't know of any.
>
> Konrad.

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