On 19 February 2010 15:18, Mike K <mbk.li...@gmail.com> wrote: > Hey Clojurians, > > I'm a Clojure and Common Lisp newbie. I heard that Norvig's PAIP was a > good book to study idiomatic CL code, so I've embarked on a project to > translate the examples to / work the exercises in Clojure. I hope to > complete this project before the end of this century :-) > > Regarding "append" from CL: ISTM that this is similar to "concat" in > Clojure. I tried the following definition: > > (defn append [& parts] (concat parts)) > > but it is not quite correct: > > (concat '(a b c) '(d e f) '(g)) > > -> (a b c d e f g) > > (append '(a b c) '(d e f) '(g)) > > -> ((a b c) (d e f) (g)) > > What is the correct way to do this? Is it possible to code the idea > that append == concat two ways, one explicitly defining a parameter > list like "parts" and one just aliasing the concat symbol somehow?
parts is a collection of the arguments. so you need to use apply to supply them individually to concat: foo=> (defn append [& parts] (apply concat parts)) #'foo/append foo=> (append '(a b c) '(d e f) '(g)) (a b c d e f g) But as you rightly noted, you could just alias append as concat: foo=> (def append concat) #'foo/append foo=> (append '(a b c) '(d e f) '(g)) (a b c d e f g) -- 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