Re: question about a macro

2012-04-20 Thread Cedric Greevey
On Thu, Apr 19, 2012 at 7:28 AM, Thomas wrote: > Hi, > > I'd like to write a macro which transforms > > (my-macro SomeClass. a b [x y] c [e f]) > > into > > (SomeClass. a b x y c e f) > > (the order of collections and single values in the arguments should be > arbitrary) > > The closest I came was

Re: question about a macro

2012-04-20 Thread nicolas.o...@gmail.com
On Fri, Apr 20, 2012 at 11:14 AM, Marc Limotte wrote: > Thomas, > > Try this: > > (defmacro my-macro2 [func & args] `(~func ~@(flatten (eval (vec args) > > This won't work for: (let [a [2 3]] (my-macro2 SomeClass. a)) -- You received this message because you are subscribed to the Google Gr

Re: question about a macro

2012-04-20 Thread nicolas.o...@gmail.com
Part of the problem is that you confuse compile time and runtime. Macro are evaluated at compile-time. So when you write: (my-macro SomeClass. a b) , my-macro can't access the runtime value of a and b. So if you want your second example to work, you need flatten to be called at runtime and not

Re: question about a macro

2012-04-20 Thread Marc Limotte
Thomas, Try this: (defmacro my-macro2 [func & args] `(~func ~@(flatten (eval (vec args) Marc On Wed, Apr 18, 2012 at 4:57 PM, thomas kalbe wrote: > Hi, > > I'd like to write a macro which transforms > > (my-macro SomeClass. a b [x y] c [e f]) > > into > > (SomeClass. a b x y c e f) > > (t

Re: question about a macro

2012-04-19 Thread Armando Blancas
Flatten isn't the problem. You can't put together a special form with apply. Try taking the class name as a symbol or string and use reflection. On Wednesday, April 18, 2012 1:57:27 PM UTC-7, Thomas wrote: > > Hi, > > I'd like to write a macro which transforms > > (my-macro SomeClass. a b [x y] c

question about a macro

2012-04-19 Thread Thomas
Hi, I'd like to write a macro which transforms (my-macro SomeClass. a b [x y] c [e f]) into (SomeClass. a b x y c e f) (the order of collections and single values in the arguments should be arbitrary) The closest I came was (defmacro my-macro [func & args] `(~func ~@(flatten args))) This

question about a macro

2012-04-19 Thread thomas kalbe
Hi, I'd like to write a macro which transforms (my-macro SomeClass. a b [x y] c [e f]) into (SomeClass. a b x y c e f) (the order of collections and single values in the arguments should be arbitrary) The closest I came was (defmacro my-macro [func & args] `(~func ~@(flatten args))) Th

Re: A new lisper's question about a macro

2010-01-25 Thread joel r
On Mon, Jan 25, 2010 at 3:09 AM, ataggart wrote: > > (zipmap >  (map keyword (take-nth 2 ~params)) >  (map (comp var-get resolve) (take-nth 2 (next ~params > Neat :-) Thanks! - Joel Rosario. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To po

Re: A new lisper's question about a macro

2010-01-25 Thread joel r
On Mon, Jan 25, 2010 at 3:42 AM, Richard Newman wrote: >> The former is a lot clearer to read, as it uses standard Clojure >> datastructures. > > ... which offers other advantages beyond the human, such as > > (def page-names keys) > > user=> (page-names foobar) > (:page :posts :post) > > Power co

Re: A new lisper's question about a macro

2010-01-24 Thread Richard Newman
The former is a lot clearer to read, as it uses standard Clojure datastructures. ... which offers other advantages beyond the human, such as (def page-names keys) user=> (page-names foobar) (:page :posts :post) Power comes from algorithms × data structures, and hiding the data structures —

Re: A new lisper's question about a macro

2010-01-24 Thread James Reeves
On Jan 24, 5:05 pm, joel r wrote: > It's meant to be called like this: > (define-template some-template-name >   page some-function-1 >   posts some-function-2 >   post some-function-3) > > It defs a var called some-template-name bound to a map that looks like this: > {:page some-function-1 >   :p

Re: A new lisper's question about a macro

2010-01-24 Thread ataggart
On Jan 24, 9:05 am, joel r wrote: > Hi, > > I was wondering whether there was an elegant way to make this macro do > more work: > > (defmacro define-template [template-name & template-params] >   `(def ~template-name (apply merge (map (fn [[k# v#]] >                                             {

A new lisper's question about a macro

2010-01-24 Thread joel r
Hi, I was wondering whether there was an elegant way to make this macro do more work: (defmacro define-template [template-name & template-params] `(def ~template-name (apply merge (map (fn [[k# v#]] {(keyword k#) (var-get (resolve v#))})