Christian, Nice to have you here. I guess a couple of things are being discussed in parallel - a few trivial points:
- 'you always get back a value of the concrete type you supplied for argument X' isn't obviously less cognitively burdensome than 'you always get back a sequence' - doesn't Python, in all its teachability, just throw a TypeError if you try and concatenate differently typed collections, even in trivial cases (e.g. (1,) + [2])? Is there a way to do that in Python which doesn't involve writing a concat function w/ a bunch of type checks - runtime list construction in Clojure is comparatively rare. I'm not a teacher, but in a practical educational setting I would focus on vectors as the general-purpose ordered collection type - esp. if i were interested in appending to them. Take care, Moe On Wed, Jul 18, 2018 at 10:07 PM, Christian Seberino <cseber...@gmail.com> wrote: > 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. > -- 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.