> If you don't plan to use the &rest arguments, and in fact don't care > about them at all, why are you binding them to something? I omitted code for sake of simplicity. There are situations which require &rest arguments.
> Using rest would cause the xs part to always be true You're right. I see to use nthrest instead of nthnext can break code, so unfortunately this is unwelcome change. Thanks! On 3月24日, 午前11:28, Alan <a...@malloys.org> wrote: > If you don't plan to use the &rest arguments, and in fact don't care > about them at all, why are you binding them to something? > > More importantly, it would make the following idiom a lot more clumsy: > > (defn sum [list] > (let [[x & xs] list] > (+ x (if xs > (sum xs) > 0)))) > > Using rest would cause the xs part to always be true, because to > determine whether the sequence is empty you would have to call seq on > it. > > On Mar 23, 6:23 pm, Takahiro Hozumi <fat...@googlemail.com> wrote: > > > > > > > > > Hi, > > I think destructure should not produce nthnext, because it realize an > > element of sequence more than needed. > > > For example: > > (defn inc-seq [i] > > (iterate #(let [x (inc %)] (println "realize:" x) x) i)) > > ;=> #'user/inc-seq > > > (take 1 (inc-seq 0)) > > ;=> (0) > > > (take 1 (let [[x & xs] (inc-seq 0)] (cons x xs))) > > ; realize: 1 > > ;=> (0) > > > (macroexpand '(let [[x & xs] (inc-seq 0)] (cons x xs))) > > ;=> (let* [vec__2630 (inc-seq 0) > > x (clojure.core/nth vec__2630 0 nil) > > xs (clojure.core/nthnext vec__2630 1)] > > (cons x xs)) > > > Although nthrest isn't in clojure, why not to use nthrest instead of > > nthnext in destructure? > > What do you think? -- 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