I've modified clojure.core/destructure to support this new binding
syntax.

https://gist.github.com/doffltmiw/5730721

Here are some tests:

(let2 [[(a map?) b] [{:p 1} 2]]
  [a b])
;= [{:p1 1} 2]

(let2 [[(a map?) b] [2]]
  [a b])
;= [nil 2]

(let2 [[(a map? {:p "default"}) b] [2]]
  [a b])
;= [{:p "default"} 2]

(let2 [[a (b map?) (c String) d] ["abc" "def" "ghi"]]
  [a b c d])
;= ["abc" nil "def" "ghi"]


What do you think? Considering that everyone is writing their own
macros or helper functions, isn't it worth including in the core?



On Jun 4, 6:48 pm, Alice <dofflt...@gmail.com> wrote:
> 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 map?) (v vector?) (s String) n]
>
> On Jun 4, 2:22 am, Alice <dofflt...@gmail.com> 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 is 4 years old, is there
> > any new library developed to help with this situation?.
>
> >https://groups.google.com/group/clojure/browse_frm/thread/125a8af6881...

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to