macrolet?

100 views
Skip to first unread message

jc

unread,
Jul 25, 2008, 2:17:43 PM7/25/08
to Clojure
I've been messing around with Clojure trying to familiarize myself
with it, and I've run into a little snag: want of macrolet.

My apologies if this has been discussed elsewhere, but if it was I
didn't find it. I did see that using lambdas with let is the
idiomatic way to do flet, and that Rich would like to add symbol-
macrolet (http://clojure-log.n01se.net/date/2008-06-16.html), but what
is the general feeling in the community about adding macrolet?

I was trying to re-write the macro `..' in terms of reduce, and here's
what I came up with. (Am I wrong in assuming that in this case a
(sub) macro is required to keep `call' from being evaluated? Is there
some better way of doing this while still using reduce?)

(defmacro doubledot [obj & calls]
(defmacro make-dot [callee call] `(. ~callee ~call))
(reduce make-dot obj calls))

The above seems to work, but `make-dot' is interned at the top level,
which I think is less-than-ideal.

Rich Hickey

unread,
Jul 25, 2008, 2:49:26 PM7/25/08
to Clojure


On Jul 25, 2:17 pm, jc <justinc...@gmail.com> wrote:
> I've been messing around with Clojure trying to familiarize myself
> with it, and I've run into a little snag: want of macrolet.
>
> My apologies if this has been discussed elsewhere, but if it was I
> didn't find it. I did see that using lambdas with let is the
> idiomatic way to do flet, and that Rich would like to add symbol-
> macrolet (http://clojure-log.n01se.net/date/2008-06-16.html), but what
> is the general feeling in the community about adding macrolet?
>
> I was trying to re-write the macro `..' in terms of reduce, and here's
> what I came up with. (Am I wrong in assuming that in this case a
> (sub) macro is required to keep `call' from being evaluated?

Yes. Once in the macro the forms are just data.

> Is there
> some better way of doing this while still using reduce?)
>
> (defmacro doubledot [obj & calls]
> (defmacro make-dot [callee call] `(. ~callee ~call))
> (reduce make-dot obj calls))
>
> The above seems to work, but `make-dot' is interned at the top level,
> which I think is less-than-ideal.

You are not actually using make-dot as a macro above, but as a
function, and the job can be done with a local function:

(defmacro doubledot [obj & calls]
(let [make-dot (fn [callee call]
`(. ~callee ~call))]
(reduce make-dot obj calls)))

Rich

Chouser

unread,
Jul 25, 2008, 2:56:16 PM7/25/08
to clo...@googlegroups.com
On Fri, Jul 25, 2008 at 2:17 PM, jc <justi...@gmail.com> wrote:
>
> I've been messing around with Clojure trying to familiarize myself
> with it, and I've run into a little snag: want of macrolet.
>
> My apologies if this has been discussed elsewhere, but if it was I
> didn't find it.

18:58: rhickey: ah, local macros like CL macrolet, and symbol-macrolet
- nope, don't have those yet
That's from: http://clojure-log.n01se.net/date/2008-06-19.html

Not much to on, is it? :-)

> I was trying to re-write the macro `..' in terms of reduce, and here's
> what I came up with. (Am I wrong in assuming that in this case a
> (sub) macro is required to keep `call' from being evaluated? Is there
> some better way of doing this while still using reduce?)
>
> (defmacro doubledot [obj & calls]
> (defmacro make-dot [callee call] `(. ~callee ~call))
> (reduce make-dot obj calls))

I don't think you need a sub-macro at all:

(defmacro doubledot [obj & calls]

(reduce (fn [callee call] (list `. callee call)) obj calls))

or:

(defmacro doubledot [obj & calls]

(reduce (partial list `.) obj calls))

--Chouser

Reply all
Reply to author
Forward
0 new messages