Re: Closures in macros

2011-05-08 Thread André Thieme
Hello Ken, thanks for your explanations. It seems that you basically outlined a strategy that can be used to implement that feature. Very good! :-) Am 05.05.2011 02:21, schrieb Ken Wesson: As for concerns that this kind of extension might mask common macro errors, adding some *warn-on-foo*

Re: Closures in macros

2011-05-08 Thread André Thieme
Am 05.05.2011 02:01, schrieb Ken Wesson: (There's an ugly workaround involving explicitly calling intern; you create a dummy namespace with a var holding the object, and then eval code that refers to that var by fully-qualified name in order to retrieve the object.) Yes, this is what I

Re: Closures in macros

2011-05-05 Thread Ken Wesson
On Wed, May 4, 2011 at 8:01 PM, Ken Wesson kwess...@gmail.com wrote: Note that instantiating the class with 4 gives us an add-4-to function instead of the original add-3-to function here. To actually convert that particular closure into code that reproduces it, the array of constructor

Re: Closures in macros

2011-05-04 Thread Alessio Stalla
On 4 Mag, 01:34, Chris Perkins chrisperkin...@gmail.com wrote: On May 3, 5:22 pm, André Thieme splendidl...@googlemail.com wrote: 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

Re: Closures in macros

2011-05-04 Thread Simon Katz
For example Common Lisp does support this. That's not true, or at least it's only partly true. Here's a translation of your example into Common Lisp (I added a use of a# in the macro to avoid compiler optimization making the problem go away): (defun f (x) (lambda () x)) (defparameter foo

Re: Closures in macros

2011-05-04 Thread Marshall T. Vandegrift
André Thieme splendidl...@googlemail.com writes: Please try this minimal example in your REPL: (defn f [x] (fn [] x)) ; the closure factory (def foo (f 0)) ; a useful instance (defmacro bar [] `(let [a# ~foo])) and then call (bar) I'm new to Clojure and don't have much experience with Lisps

Re: Closures in macros

2011-05-04 Thread Armando Blancas
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. As it's been pointed out, the compiler won't re-compile compiled code. Those macros work if you don't unquote the expressions: (defmacro x

Re: Closures in macros

2011-05-04 Thread Alessio Stalla
On 4 Mag, 16:29, Marshall T. Vandegrift llas...@gmail.com wrote: André Thieme splendidl...@googlemail.com writes: Please try this minimal example in your REPL: (defn f [x] (fn [] x)) ; the closure factory (def foo (f 0)) ; a useful instance (defmacro bar [] `(let [a# ~foo])) and then

Re: Closures in macros

2011-05-04 Thread Jonathan Smith
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

Re: Closures in macros

2011-05-04 Thread Jonathan Smith
On May 4, 8:50 am, Simon Katz nomisk...@gmail.com wrote: For example Common Lisp does support this. That's not true, or at least it's only partly true. Here's a translation of your example into Common Lisp (I added a use of a# in the macro to avoid compiler optimization making the problem

Re: Closures in macros

2011-05-04 Thread Marshall T. Vandegrift
Alessio Stalla alessiosta...@gmail.com writes: The key point is that in Lisp code does not mean text [1]. Code is made of data structures - lists, symbols, vectors, numbers, ... - and macros are just functions that operate on those data structures. Hmm, interesting. One of the things that's

Re: Closures in macros

2011-05-04 Thread David Nolen
On Wed, May 4, 2011 at 6:31 PM, André Thieme splendidl...@googlemail.comwrote: You need to wrap it into eval-when or separate functions and macros from their use into different files and make sure the right load order is used. Then this will work in CL. Which are probably some of the reasons

Re: Closures in macros

2011-05-04 Thread Simon Katz
On May 4, 11:31 pm, André Thieme splendidl...@googlemail.com wrote: Am 04.05.2011 14:50, schrieb Simon Katz: For example Common Lisp does support this. That's not true, or at least it's only partly true. Here's a translation of your example into Common Lisp (I added a use of a# in the

Re: Closures in macros

2011-05-04 Thread Ken Wesson
On Wed, May 4, 2011 at 7:03 PM, Simon Katz nomisk...@gmail.com wrote: It is not possible to write out a function object (something returned by lambda, Common Lisp's equivalent of fn) to a compiled file.  No mix of eval-when, separating functions and macros, and load order can change that. The

Re: Closures in macros

2011-05-04 Thread Ken Wesson
On Wed, May 4, 2011 at 8:01 PM, Ken Wesson kwess...@gmail.com wrote: Note that instantiating the class with 4 gives us an add-4-to function instead of the original add-3-to function here. To actually convert that particular closure into code that reproduces it, the array of constructor

Re: Closures in macros

2011-05-04 Thread Ken Wesson
On Wed, May 4, 2011 at 8:16 PM, Ken Wesson kwess...@gmail.com wrote: Closures, including ones whose arguments can't be known until runtime, can easily be slapped with implements Serializable if they haven't been already. Indeed, an extends Serializable on IFn, on top of the above compiler

Re: Closures in macros

2011-05-03 Thread André Thieme
Am 02.05.2011 23:14, schrieb David Nolen: The relevant clojure-dev thread. http://groups.google.com/group/clojure-dev/browse_thread/thread/f4907ebca8ef6e11 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

Re: Closures in macros

2011-05-03 Thread Chris Perkins
On May 3, 5:22 pm, André Thieme splendidl...@googlemail.com wrote: 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)

Re: Closures in macros

2011-05-02 Thread André Thieme
: “With macros, closures, and run-time typing, Lisp transcends object- oriented programming.” A modern Lisp like Clojure should indeed support closures in macros. Instead, return code that will be evaluated in the expansion context and have the effect you want. The idea about “static logging

Re: Closures in macros

2011-05-02 Thread David Nolen
On Mon, May 2, 2011 at 4:49 PM, André Thieme splendidl...@googlemail.comwrote: Maybe there are good reasons why closures should not be real first class objects, as it is the case in other programming languages that support them. If that is the case I would really like to hear it. I am not

Re: Closures in macros

2011-05-02 Thread David Nolen
On Mon, May 2, 2011 at 4:49 PM, André Thieme splendidl...@googlemail.comwrote: I am not interested in the answers of religious fanatics who defend any behaviour that the current implementation has, even if it obviously limits the expressiveness. Regards, André The relevant clojure-dev

Closures in macros

2011-05-01 Thread André Thieme
I am currently writing a neat logging lib and want it to support dynamic and static logging. When I activate (static-logging!) then the log macro (log :warn message) will check during macro expansion time which log level is currently set and decides based on that if code will be generated that

Re: Closures in macros

2011-05-01 Thread Alan
On May 1, 4:42 pm, André Thieme splendidl...@googlemail.com wrote: I am currently writing a neat logging lib and want it to support dynamic and static logging. When I activate (static-logging!) then the log macro (log :warn message) will check during macro expansion time which log level is