Hi
I wrote a function to transform a variable number of arguments into embedded
maps.
Here is what it does:
(enmap 1 2)
{1 2}
(enmap 1 2 3)
{1 {2 3}}
(enmap 1 2 3 4)
{1 {2 {3 4}}}
(enmap 1 2 3 4 {5 6 7 8})
{1 {2 {3 {4 {5 6, 7 8}
Here is my implementation:
(defn enmap [arg args]
(let [[tail more] ((juxt last (comp reverse butlast)) [1 2 3 4 {5 6 7
8}])]
(reduce #(hash-map %2 %1) tail more))
{1 {2 {3 {4 {5 6, 7 8}
On Mar 10, 9:46 am, Damien Lepage damienlep...@gmail.com wrote:
Hi
I wrote a function to transform a variable number of arguments into embedded
On Thu, Mar 10, 2011 at 12:46 PM, Damien Lepage damienlep...@gmail.com wrote:
Hi
I wrote a function to transform a variable number of arguments into embedded
maps.
Here is what it does:
(enmap 1 2)
{1 2}
(enmap 1 2 3)
{1 {2 3}}
(enmap 1 2 3 4)
{1 {2 {3 4}}}
(enmap 1 2 3 4 {5 6 7 8})
On Mar 10, 12:46 pm, Damien Lepage damienlep...@gmail.com wrote:
Hi
I wrote a function to transform a variable number of arguments into embedded
maps.
Here is what it does:
(enmap 1 2)
{1 2}
(enmap 1 2 3)
{1 {2 3}}
(enmap 1 2 3 4)
{1 {2 {3 4}}}
(enmap 1 2 3 4 {5 6 7 8})
{1 {2 {3
On Mar 10, 10:05 am, Aaron Cohen aa...@assonance.org wrote:
On Thu, Mar 10, 2011 at 12:46 PM, Damien Lepage damienlep...@gmail.com
wrote:
Hi
I wrote a function to transform a variable number of arguments into embedded
maps.
Here is what it does:
(enmap 1 2)
{1 2}
(enmap 1 2 3)
On Thu, Mar 10, 2011 at 12:46 PM, Damien Lepage damienlep...@gmail.com wrote:
Hi
(apply enmap arg (concat even-more (list (hash-map k v
Is there something simpler than (concat even-more (list (hash-map k v)) to
append an element at the end of a sequence?
To answer your second
- Is there a way to make this function less complicated? without
recursion maybe?
Looks like you're covered on this one.
- Is there something simpler than (concat even-more (list (hash-map k
v)) to append an element at the end of a sequence?
Clojure is opinionated in this sense.
Interesting. Here is my attempt.
(defn enmap [args]
(let [[fs res] (reverse args)]
(reduce (fn [v k] (hash-map k v)) fs res)))
(enmap [1 2 3 4 {5 6 7 8}])
= {1 {2 {3 {4 {5 6, 7 8}
(let [[tail more] ((juxt last (comp reverse butlast)) [1 2 3 4 {5 6 7 8}])]
(reduce #(hash-map %2 %1)
more concise:
(defn enmap [args]
(reduce #(hash-map %2 %1) (reverse args)))
2011/3/11 Takahiro fat...@googlemail.com:
Interesting. Here is my attempt.
(defn enmap [args]
(let [[fs res] (reverse args)]
(reduce (fn [v k] (hash-map k v)) fs res)))
(enmap [1 2 3 4 {5 6 7 8}])
= {1 {2
Thanks a lot for your help, there's an awesome community here.
Sorry for the dumb questions, I'll try no to be too noisy on this list.
BTW, shouldn't it be better to create a separate mailing list for beginners?
Well, we would still need some experienced clojurers to answer the questions
though
Ah, thanks. I think the pulling-apart of last and butlast was a
remnant of my trying to do this with foldl instead of foldr :P.
On Mar 10, 10:38 am, Takahiro fat...@googlemail.com wrote:
more concise:
(defn enmap [args]
(reduce #(hash-map %2 %1) (reverse args)))
2011/3/11 Takahiro
Thanks a lot for your help, there's an awesome community here.
Sorry for the dumb questions, I'll try no to be too noisy on this list.
BTW, shouldn't it be better to create a separate mailing list for beginners?
Well, we would still need some experienced clojurers to answer the questions
On Mar 10, 7:48 pm, Damien Lepage damienlep...@gmail.com wrote:
Sorry for the dumb questions, I'll try no to be too noisy on this list.
I found this thread useful. Please keep asking questions.
Saul
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To
Real nice and short. Doing [ args] avoids the vector:
user= (enmap 1 2 3 4 {5 6 7 8})
{1 {2 {3 {4 {5 6, 7 8}
On Mar 10, 10:38 am, Takahiro fat...@googlemail.com wrote:
more concise:
(defn enmap [args]
(reduce #(hash-map %2 %1) (reverse args)))
2011/3/11 Takahiro
Hi,
here something different. But also using the ugly butlast and last.
user= (defn enmap [ args] (assoc-in {} (butlast args) (last args)))
#'user/enmap
user= (enmap 1 2 3 4 {5 6 7 8})
{1 {2 {3 {4 {5 6, 7 8}
Sincerely
Meikel
--
You received this message because you are subscribed to the
15 matches
Mail list logo