question about "into"

1 view
Skip to first unread message

Base

unread,
Apr 7, 2010, 8:35:32 PM4/7/10
to Clojure
Hi All -

I have a question about into.

When you run the into against a map you get a vector of

(into [] {:a 1 :b 2})

=> [[:a 1] [:b 2]]

However when you use a for in front of this you get the full map.

(into [] (for [_ (range 1)] {:a 1 :b 2}))

=> [{:a 1, :b 2}]

Why is this? I would have expected them both to yield the same
results...

Thanks

Bassel

Per Vognsen

unread,
Apr 7, 2010, 8:45:30 PM4/7/10
to clo...@googlegroups.com
The second case is equivalent to (into [] [{:a 1 :b 2}]). You're
passing a singleton list containing a single element which happens to
be a map.

-Per

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
> To unsubscribe, reply using "remove me" as the subject.
>

Sean Devlin

unread,
Apr 8, 2010, 9:38:01 AM4/8/10
to Clojure
The REPL is you best friend whenever you have a question like this.
It's often useful to execute the offending form step by step, to see
what the result of each computation is.

Love the REPL.

Sean

On Apr 7, 8:45 pm, Per Vognsen <per.vogn...@gmail.com> wrote:
> The second case is equivalent to (into [] [{:a 1 :b 2}]). You're
> passing a singleton list containing a single element which happens to
> be a map.
>
> -Per
>

Per Vognsen

unread,
Apr 8, 2010, 10:11:10 AM4/8/10
to clo...@googlegroups.com
Indeed, and in the absence of single stepping (manual or automatic),
some simple trace macros can be very useful. Here's what I use right
now:

http://gist.github.com/360102

-Per

Reply all
Reply to author
Forward
0 new messages