Re: optional first map argument

2013-06-07 Thread Alice
sn't it worth including in the core? On Jun 4, 6:48 pm, Alice wrote: > What about adding this new binding syntax? > > [(attrs map?) & contents]       ; optional first map argument > [(attrs map? {}) & contents]    ; with default value > > [(s String)] > > ; is sh

Re: optional first map argument

2013-06-04 Thread Alice
What about adding this new binding syntax? [(attrs map?) & contents]       ; optional first map argument [(attrs map? {}) & contents]    ; with default value [(s String)] ; is shorthand for [(s #(instance? String %))] ; a function taking optional map, vector, string arguments. [(m

Re: optional first map argument

2013-06-03 Thread Meikel Brandmeyer (kotarak)
Hi, there is always the possibility of a macro. (defmacro defwidget [name & body] (let [[docstring [attrs _ contents] body] (if (string? (first body)) [(first body) (second body) (nthnext body 2)] [nil (first body) (next body)])] `(d

Re: optional first map argument

2013-06-03 Thread Alice
> (defn my-widget >     ([attrs contents] (apply widget-creator attrs contents)) ;;I have no idea > what widget-creator might be >     ([contents] (my-widget {} contents)) >     ([] (my-widget {} [])) contents of one arity version can be a map. so the code should be (defn my-widget ([attrs c

Re: optional first map argument

2013-06-03 Thread Jim - FooBar();
On 03/06/13 19:04, Alice wrote: It's more readable. (my-widget {:id "id1"} "hello" "world") you can get to almost exactly that with the last variant I posted. (defn my-widget ([attrs contents] (apply widget-creator attrs contents)) ;;I have no idea what widget-creator might be ([conten

Re: optional first map argument

2013-06-03 Thread Alice
The same reason that hiccup tag vector is taking optional attribute map. It's more readable. (my-widget {:id "id1"} "hello" "world") vs. (my-widget {:attr {:id "id1"} :contents '("hello" "world")}) On Jun 4, 2:38 am, "Jim - FooBar();" wrote: > On 03/06/13 18:22, Alice wrote: > > > I often need

Re: optional first map argument

2013-06-03 Thread Alice
I sometimes need to inspect or modify the map in the function, but defelem only merges the map. On Jun 4, 2:30 am, gaz jones wrote: > You could look at the impl: > > https://github.com/weavejester/hiccup/blob/master/src/hiccup/def.clj > > > > > > > > On Mon, Jun 3, 2013 at 12:22 PM, Alice wrote:

Re: optional first map argument

2013-06-03 Thread Jim - FooBar();
On 03/06/13 18:22, Alice wrote: I often need to do this when writing hiccup helper functions: (defn my-widget [& args] (let [attrs(if (map? (first args)) (first args) {}) contents (if (map? (first args)) (next args) args)] ... I found this post, but considering that it

Re: optional first map argument

2013-06-03 Thread gaz jones
You could look at the impl: https://github.com/weavejester/hiccup/blob/master/src/hiccup/def.clj On Mon, Jun 3, 2013 at 12:22 PM, Alice wrote: > I often need to do this when writing hiccup helper functions: > > (defn my-widget > [& args] > (let [attrs(if (map? (first args)) (first args

optional first map argument

2013-06-03 Thread Alice
I often need to do this when writing hiccup helper functions: (defn my-widget [& args] (let [attrs(if (map? (first args)) (first args) {}) contents (if (map? (first args)) (next args) args)] ... I found this post, but considering that it is 4 years old, is there any new libra