On May 3, 5:22 pm, André Thieme <splendidl...@googlemail.com> wrote:
> Am 02.05.2011 23:14, schrieb David Nolen:
>
> > The relevant clojure-dev thread.
> >http://groups.google.com/group/clojure-dev/browse_thread/thread/f4907...
>
> > It's not clear whether the core team and the various contributors are
> > interested in supporting the behavior you want. It's also not clear
> > whether the issue is matter of the difficulty of a good implementation
> > or simply disinterest.
>
> Thanks for that link. I would really like to hear (read) a statement of
> one member of the core team.
> Some of the limitations:
> 1. (defmacro x [] `(let [a# ~(atom 0)]))
>
> 2. (defmacro y [] `(let [a# ~(comp inc inc)])) ; from that link
>
> 3. (defmacro z [] `(let [a# ~((fn [x#] (fn [] x#)) 0)]))
>
> All three calls fail, (x) and (y) and (z).
> I see no plausible reason why it *should* be that way.
> Instead this is useful and idiomatic lisp.
>
> Normally I wanted to write:
> `(~(get @loggers level @logger)
>    ~(get *level-name* level)
>    ~domain ~msg ~e)
>
> The first get will see if for the given level there is a level
> specific log function. If not it will fall back to the default logger
> logger . So, loggers is a mapping from level to closures and
> logger is a closure. Those closures are functions that take 4 args:
> the log level, a domain, a message and an exception.
>
> Now I have to write instead
> (let [l (get @loggers level @logger)
>        f (gensym "logger")]
>    (intern 'mylib.log f l)
>    `(~f ~(get *level-name* level) ~domain ~msg ~e))
>
> which is plain ugly. I need to artificially invent a name, pollute the
> NS of my logging lib and probably create less efficient code, because
> a lookup of my gensymed ~f will be required at runtime.
> Would be great if this could be fixed easily enough to get included in
> a (near) future version.
>
> Regards,
> Andre

You can do this the original way you were trying to do if you change
your closure factory into a 'closure-code-factory'.

Essentially, instead of returning a (fn [x] ...), you want to return
something that's been syntax-quoted (but of the same form). (You could
make this pretty using a macro).

Then you would insert this anonymous lambda wherever you need it, and
call it inline (after binding with let or using apply). There needn't
be any lookup and It shouldn't be any less efficient than what you are
trying to do.

Of course, you should note that the downside to this entire approach
is that to change the logging settings, you have to recompile the
entire program, which could get quite annoying. (Particularly if you
wanted to turn logging on at a breakpoint or something).

It might be better to take the hit on dereferencing, as it would be
more useful, and then also include an option to eliminate all logging
code by flipping a variable.

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