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 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/d/optout.