Re: Clojure cons vs. conj

2014-04-27 Thread Joshua Ballanco
I think you’ve actually answered your own question without realizing it. At least, the way I was taught is that “conj” is always constant time w.r.t. the collection being appended to. Since different collections have different internal storage mechanisms, that means that “conj” will do different

Re: Clojure cons vs. conj

2014-04-24 Thread Jiacai Liu
thank Guru,the solution of my problem may not difficult,I first didn't understand the usage of cons and conj,now I can grasp them deeper than before. Clojure is so flexible that it both have cons and conj for different situation,which accounts for its advantages over mit-lisp. On Friday, April

Re: Clojure cons vs. conj

2014-04-24 Thread Guru Devanla
Another option is to explore "concat" On Thu, Apr 24, 2014 at 8:46 AM, Jiacai Liu wrote: > Well,I understand you. > list only support front insert since it only takes O(1). > If insert in the back,it would require O(n) time. > Maybe clojure has its own reasons for having both cons and conj. > T

Re: Clojure cons vs. conj

2014-04-24 Thread Jiacai Liu
Well,I understand you. list only support front insert since it only takes O(1). If insert in the back,it would require O(n) time. Maybe clojure has its own reasons for having both cons and conj. Thank again for telling me their differences. On Thursday, April 24, 2014 11:36:13 PM UTC+8, Gary Trak

Re: Clojure cons vs. conj

2014-04-24 Thread Gary Trakhman
Well, maybe I shouldn't bash MIT-scheme unintentionally :-). I bet some people use it for serious stuff, and I have no bad experiences with it. On Thu, Apr 24, 2014 at 11:33 AM, Gary Trakhman wrote: > MIT-lisp is more for teaching than industrial use.. > > We also have hash-maps, vectors, sets,

Re: Clojure cons vs. conj

2014-04-24 Thread Gary Trakhman
MIT-lisp is more for teaching than industrial use.. We also have hash-maps, vectors, sets, queues, conj works with all of them, leaving the details up to the collection. Cons always adds to the front. Conj only adds to the back for certain collections (vector, queue). You could work around it b

Re: Clojure cons vs. conj

2014-04-24 Thread Jiacai Liu
Oh,Thank you for answer. But if I just want to insert a element to list,and meantime want to insert in the back.How should I do? Another question: why clojure need both cons and conj? In mit-lisp cons just do all things. On Thursday, April 24, 2014 11:12:49 PM UTC+8, Gary Trakhman wrote: > > Con

Re: Clojure cons vs. conj

2014-04-24 Thread Gary Trakhman
Conj is polymorphic on its first argument. If you pass it a vector, it'll add to the back, if a list, the front. The collection is responsible for deciding the most efficient way to add an element. Cons always adds to the front, creating a linked-list node pointing to the rest. Also, cons takes

Clojure cons vs. conj

2014-04-24 Thread Jiacai Liu
hi everyone: I use Clojure to solve SICP 2.22 . The problem is to rewrite a map fn in a iterative way,here it want to get the square of each element in a list Method 1: (defn square-list [items] (defn iter [things answe