Building off of something Benoit mentioned about conj not being about order,
but about adding to a collection, consider conj’s behavior when adding a
map-entry to a hash-map:
(conj (hash-map :a 4 :c 1) [:b 3])
=> {:c 1, :b 3, :a 4}
conj is an interface for adding– not to be conflated with order.
On Jul 19, 2018, at 10:23 AM, Christian Seberino <[email protected]
<mailto:[email protected]> > wrote:
Thanks. I caught that yesterday. Like I said, I'm definitely a beginner. ;)
On Thursday, July 19, 2018 at 2:05:20 AM UTC-5, Vladimir Bokov wrote:
First of all, def in a fn body is antipattern (use let), then do into on a
itself
(defn concat_ [a b]
(if (vector? a)
(into a b)
(concat a b)))
четверг, 19 июля 2018 г., 4:07:46 UTC+7 пользователь Christian Seberino написал:
I'm just a Clojure beginner but it seems that the Lisp Way(TM) is to append and
prepend one or more elements
with a single command if possible. The logical name for this command seems to
be concat which led to this..
(defn concat_ [a b]
(def c (concat a b))
(if (vector? a)
(into [] c)
c))
(concat_ [1 2] [3 4]) => [1 2 3 4]
(concat_ '(1 2) '(3 4)) => (1 2 3 4)
(concat_ [1] [2 3]) => [1 2 3]
Lists return lists and vectors return vectors. Simple.
Yes yes I know it is slow. I also know I need to expand concat_ to handle
other data structures.
In my little newbie world, this "feels" like the ultimate "right" solution.
Chris
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
<mailto:[email protected]>
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
<mailto:[email protected]>
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
<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 [email protected]
<mailto:[email protected]> .
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.