Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-14 Thread Alan Malloy
On Dec 13, 8:37 pm, Cedric Greevey cgree...@gmail.com wrote: On Tue, Dec 13, 2011 at 11:25 PM, Alan Malloy a...@malloys.org wrote: On Dec 13, 7:56 pm, Stephen Compall stephen.comp...@gmail.com wrote: On Tue, 2011-12-13 at 16:28 -0800, Alan Malloy wrote: As you can see, only as many

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-14 Thread Cedric Greevey
On Wed, Dec 14, 2011 at 3:12 AM, Alan Malloy a...@malloys.org wrote: On Dec 13, 8:37 pm, Cedric Greevey cgree...@gmail.com wrote: On Tue, Dec 13, 2011 at 11:25 PM, Alan Malloy a...@malloys.org wrote: On Dec 13, 7:56 pm, Stephen Compall stephen.comp...@gmail.com wrote: On Tue, 2011-12-13 at

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-14 Thread Alan Malloy
On Dec 14, 1:18 am, Cedric Greevey cgree...@gmail.com wrote: On Wed, Dec 14, 2011 at 3:12 AM, Alan Malloy a...@malloys.org wrote: On Dec 13, 8:37 pm, Cedric Greevey cgree...@gmail.com wrote: On Tue, Dec 13, 2011 at 11:25 PM, Alan Malloy a...@malloys.org wrote: On Dec 13, 7:56 pm, Stephen

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-14 Thread Alan Malloy
On Dec 14, 2:22 am, Alan Malloy a...@malloys.org wrote: On Dec 14, 1:18 am, Cedric Greevey cgree...@gmail.com wrote: On Wed, Dec 14, 2011 at 3:12 AM, Alan Malloy a...@malloys.org wrote: On Dec 13, 8:37 pm, Cedric Greevey cgree...@gmail.com wrote: On Tue, Dec 13, 2011 at 11:25 PM,

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-13 Thread Stephen Compall
On Mon, 2011-12-12 at 10:53 -0800, Michael Jaaka wrote: (defn conr[ col item ] (lazy-seq (if (seq col) (cons (first col) (conr (rest col) item)) (list item And now stick with it. All works as desired: (conr (conr (conr

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-13 Thread Alan Malloy
On Dec 13, 3:05 pm, Stephen Compall stephen.comp...@gmail.com wrote: On Mon, 2011-12-12 at 10:53 -0800, Michael Jaaka wrote: (defn conr[ col item ]    (lazy-seq            (if (seq col)                    (cons (first col) (conr (rest col) item))                    (list item And

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-13 Thread Stephen Compall
On Tue, 2011-12-13 at 16:28 -0800, Alan Malloy wrote: As you can see, only as many elements are realized as are needed to satisfy the user's request. Yes, in the expression (conr (conr (conr '( 1 2 3) 4) 6) 7), all the lazy-seqs implied by the conr calls must be forced immediately to yield (1 .

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-13 Thread Alan Malloy
On Dec 13, 7:56 pm, Stephen Compall stephen.comp...@gmail.com wrote: On Tue, 2011-12-13 at 16:28 -0800, Alan Malloy wrote: As you can see, only as many elements are realized as are needed to satisfy the user's request. Yes, in the expression (conr (conr (conr '( 1 2 3) 4) 6) 7), all the

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-13 Thread Cedric Greevey
On Tue, Dec 13, 2011 at 11:25 PM, Alan Malloy a...@malloys.org wrote: On Dec 13, 7:56 pm, Stephen Compall stephen.comp...@gmail.com wrote: On Tue, 2011-12-13 at 16:28 -0800, Alan Malloy wrote: As you can see, only as many elements are realized as are needed to satisfy the user's request.

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-12 Thread Michael Jaaka
Thanks to all for responses. I just wanted to use that in higher-order composition in mind, not to construct any data structures. I have tweaked a bit the function: (defn conr[ col item ] (lazy-seq (if (seq col) (cons (first col) (conr (rest col)

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-11 Thread Marco Abis
Hi, total newbie here but what about conj? (conj (conj (conj [ 1 2 3] 4) 6) 7) would return [1 2 3 4 6 7] -- Marco Abis -- 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

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-10 Thread Andy Fingerhut
conj adds an element to a data structure in a place most efficient for the particular type of data structure. For lists, this is at the beginning. For vectors, it is at the end: user= (conj (conj (conj '(1 2 3) 4) 6) 7) (7 6 4 1 2 3) user= (conj (conj (conj [1 2 3] 4) 6) 7) [1 2 3 4 6 7] If you

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-10 Thread Tamreen Khan
Conj (http://clojuredocs.org/clojure_core/clojure.core/conj) does what you need for vectors. It's behavior depends on the type of collection passed, so if you did: (conj '(1 2 3) 4) you would end up with '(4 1 2 3). For vectors it appends to the end of the list, for lists the beginning. On Sat,

Re: Opposite function to cons, but in terms of construction, not destruction.

2011-12-10 Thread Andy Fingerhut
I forgot to mention, if you want a Clojure persistent data structure that is efficient (O(1) or O(log n)) for all of these operations: + adding to/removing from beginning + adding to/removing from end + concatenating + splitting into two sequences, at any specified item in the middle look at