Re: Macros applied to entire programs

2009-06-03 Thread Christophe Grand
I attached a better patch: no eval and a more standard "inline". Christophe Grand a écrit : > I'm sure there's something wrong with my patch (the "eval" smell) and > the fact that I'm assoc-ing a closure in the metadat map. > I'll rework it if you agree with the idea of this patch > > Christophe

Re: Macros applied to entire programs

2009-06-03 Thread Christophe Grand
I'm sure there's something wrong with my patch (the "eval" smell) and the fact that I'm assoc-ing a closure in the metadat map. I'll rework it if you agree with the idea of this patch Christophe Grand a écrit : > Rich Hickey a écrit : > >> On May 13, 9:57 am, Christophe Grand wrote: >> >>

Re: Macros applied to entire programs

2009-06-03 Thread Christophe Grand
Rich Hickey a écrit : > > On May 13, 9:57 am, Christophe Grand wrote: > >> Mark Reid a écrit : >> >> >>> In particular, it seems converting `(+ 1 2 3)` to `(+ 1 (+ >>> 2 3))` can speed things up. >>> >> Rich, would you accept a patch to make all arities inlinable for basic >> math o

Re: Macros applied to entire programs

2009-05-13 Thread Christophe Grand
Rich Hickey a écrit : > > On May 13, 9:57 am, Christophe Grand wrote: > >> Mark Reid a écrit : >> >> >>> In particular, it seems converting `(+ 1 2 3)` to `(+ 1 (+ >>> 2 3))` can speed things up. >>> >> Rich, would you accept a patch to make all arities inlinable for basic >> math

Re: Macros applied to entire programs

2009-05-13 Thread Rich Hickey
On May 13, 9:57 am, Christophe Grand wrote: > Mark Reid a écrit : > > > In particular, it seems converting `(+ 1 2 3)` to `(+ 1 (+ > > 2 3))` can speed things up. > > Rich, would you accept a patch to make all arities inlinable for basic > math ops? > What does the patch do? Rich --~--~-

Re: Macros applied to entire programs

2009-05-13 Thread Christophe Grand
Mark Reid a écrit : > In particular, it seems converting `(+ 1 2 3)` to `(+ 1 (+ > 2 3))` can speed things up. Rich, would you accept a patch to make all arities inlinable for basic math ops? -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) --~--~--

Re: Macros applied to entire programs

2009-05-13 Thread Konrad Hinsen
On 13.05.2009, at 08:32, Konrad Hinsen wrote: > I have done exactly that recently when writing clojure.contrib.macro- > utils, which contains a full macro expansion engine because that's > the only way to implement symbol macros and local macros. It was an > interesting exercice in macro programm

Re: Macros applied to entire programs

2009-05-12 Thread Konrad Hinsen
On 13.05.2009, at 02:43, Mark Reid wrote: > Konrad, I agree, it would make more sense to add simple optimisations > like the one for addition to Clojure itself. However, the potential > problem you mention regarding the clash of multiple definitions of `+` > doesn't seem like that big an issue si

Re: Macros applied to entire programs

2009-05-12 Thread Mark Reid
I should clarify: I asked my original question not because I wanted to actually write an optimiser but rather I was interested in how far the idea of code-modifying code could be pushed in a Lisp-like language such as Clojure. The example I gave was just the simplest thing I could think of that de

Re: Macros applied to entire programs

2009-05-12 Thread Stuart Sierra
On May 12, 12:17 am, Mark Reid wrote: > I guess what I'm really looking for now is the "how". It's relatively easy to write a program that transforms Clojure source code: (loop [] (when-let [code (read *in* false nil)] ... do some transformation on code ... (prn transformed-co

Re: Macros applied to entire programs

2009-05-12 Thread Sean Devlin
One thing hit me as I went to bed last night about this problem: Writing a macro to optimize an s-exp *is* writing a compiler. The good news is that you *don't* have to write a parser. There is some low hanging fruit here (like the + macro described above), but I imagine there will be a lot of

Re: Macros applied to entire programs

2009-05-12 Thread Paul Stadig
You could write a Clojure program that took in a Clojure program and spit out an optimized Clojure program. You could do something similar to the meta-circular evaluator, where you step through the program (which is just a data structure) recursively matching the head each time against different sy

Re: Macros applied to entire programs

2009-05-11 Thread Konrad Hinsen
On 12.05.2009, at 05:42, Mark Reid wrote: > I'm quite new to macros so forgive me if this is a naïve question, but > is it possible to write macros that are applied to an entire Clojure > program? It depends on what you call a "program". Clojure code is structured in the form of namespaces, an

Re: Macros applied to entire programs

2009-05-11 Thread Mark Reid
Hi, I have read Graham's "On Lisp". That, and my background in Java and Haskell programming were the main reasons I was drawn to Clojure. Based on that article and others like it I had the impression that program transformations like the one I suggested were relatively easy in homoiconic language

Re: Macros applied to entire programs

2009-05-11 Thread Sean Devlin
Macros are definitely the tool to do this. Take a look here at Paul Graham's "The Roots of Lisp". In it you'll get an idea of why eval is so powerful, and why macros are exactly the tool for the job you're thinking of. http://lib.store.yahoo.net/lib/paulgraham/jmc.ps I'll let someone else answ

Macros applied to entire programs

2009-05-11 Thread Mark Reid
Hi, I'm quite new to macros so forgive me if this is a naïve question, but is it possible to write macros that are applied to an entire Clojure program? The reason I ask is that, in other threads in this group, some simple transformations to improve efficiency of Clojure programs were mentioned.