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 finger trees, which Chouser has implemented for Clojure:

https://github.com/clojure/data.finger-tree

Andy

On Sat, Dec 10, 2011 at 6:43 AM, Andy Fingerhut wrote:

> 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 want something that adds to the end of a list, or the beginning of
> a vector, you must implement it yourself, and it won't be O(1) as the above
> are (OK, the vector version above is not quite O(1), but it is O(log n)).
> Here are functions that can do the job, but take time linear in the size of
> the list/vector being added to:
>
> user=> (defn add-at-end [l item] (concat l (list item)))
> #'user/add-at-end
> user=> (add-at-end '(1 2 3) 4)
> (1 2 3 4)
> user=> (defn add-at-front [v item] (vec (cons item (seq v
> #'user/add-at-front
> user=> (add-at-front [1 2 3] 4)
> [4 1 2 3]
>
> Andy
>
>
>
>
> On Sat, Dec 10, 2011 at 3:13 AM, Michael Jaaka <
> michael.ja...@googlemail.com> wrote:
>
>> Is there something like:
>>
>> (defn snoc[ col item ]
>>(lazy-seq
>>(if (seq col)
>>(let[ [f &  r] col ]
>>(if (seq r)
>>(cons f (snoc r item))
>>(cons f [item])))
>>[item])))
>>
>> already here?
>>
>>
>> (snoc (snoc (snoc [ 1 2 3] 4) 6) 7)
>>
>> gives:
>>
>> (1 2 3 4 5 6 7)
>>
>> --
>> 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 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

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, Dec 10, 2011 at 6:13 AM, Michael Jaaka
 wrote:
> Is there something like:
>
> (defn snoc[ col item ]
>        (lazy-seq
>                (if (seq col)
>                        (let[ [f &  r] col ]
>                                (if (seq r)
>                                        (cons f (snoc r item))
>                                        (cons f [item])))
>                        [item])))
>
> already here?
>
>
> (snoc (snoc (snoc [ 1 2 3] 4) 6) 7)
>
> gives:
>
> (1 2 3 4 5 6 7)
>
> --
> 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 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


Re: Bug in core.match?

2011-12-10 Thread David Nolen
Thanks.

On Saturday, December 10, 2011, Benny Tsai  wrote:
> Done!
> On Saturday, December 10, 2011 9:08:22 AM UTC-7, David Nolen wrote:
>>
>> Please open a ticket on JIRA with this case -
http://dev.clojure.org/jira/browse/MATCH
>> Thanks!
>> David
>> On Sat, Dec 10, 2011 at 5:33 AM, Benny Tsai  wrote:
>>>
>>> Hi all,
>>> Ran into what appears to be a bug tonight.  This is the simplest
example I could come up with:
>>>
>>> (defn f [xs]
>>>   (match xs
>>>  [:a] "a"
>>>  [:b b] b
>>>  [:c] "c"
>>>  :else "problem!"))
>>> [:a] and [:b b] can be matched with no problems, but [:c] can't be
matched for some reason:
>>>
>>> user=> (f [:a])
>>> "a"
>>> user=> (f [:b 1])
>>> 1
>>> user=> (f [:c])
>>> "problem!"
>>> I'm using Clojure 1.3 and core.match 0.2.0-alpha8.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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 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 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

Re: Bug in core.match?

2011-12-10 Thread Benny Tsai
Done!

On Saturday, December 10, 2011 9:08:22 AM UTC-7, David Nolen wrote:
>
> Please open a ticket on JIRA with this case - 
> http://dev.clojure.org/jira/browse/MATCH
>
> Thanks!
> David
>
> On Sat, Dec 10, 2011 at 5:33 AM, Benny Tsai  wrote:
>
>> Hi all,
>>
>> Ran into what appears to be a bug tonight.  This is the simplest example 
>> I could come up with:
>>
>> (defn f [xs]
>>   (match xs
>>  [:a] "a"
>>  [:b b] b
>>  [:c] "c"
>>  :else "problem!"))
>>
>> [:a] and [:b b] can be matched with no problems, but [:c] can't be 
>> matched for some reason:
>>
>> user=> (f [:a])
>> "a"
>> user=> (f [:b 1])
>> 1
>> user=> (f [:c])
>> "problem!"
>>
>> I'm using Clojure 1.3 and core.match 0.2.0-alpha8.
>>  
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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 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

Re: Bug in core.match?

2011-12-10 Thread David Nolen
Please open a ticket on JIRA with this case -
http://dev.clojure.org/jira/browse/MATCH

Thanks!
David

On Sat, Dec 10, 2011 at 5:33 AM, Benny Tsai  wrote:

> Hi all,
>
> Ran into what appears to be a bug tonight.  This is the simplest example I
> could come up with:
>
> (defn f [xs]
>   (match xs
>  [:a] "a"
>  [:b b] b
>  [:c] "c"
>  :else "problem!"))
>
> [:a] and [:b b] can be matched with no problems, but [:c] can't be matched
> for some reason:
>
> user=> (f [:a])
> "a"
> user=> (f [:b 1])
> 1
> user=> (f [:c])
> "problem!"
>
> I'm using Clojure 1.3 and core.match 0.2.0-alpha8.
>
> --
> 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 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

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 want something that adds to the end of a list, or the beginning of a
vector, you must implement it yourself, and it won't be O(1) as the above
are (OK, the vector version above is not quite O(1), but it is O(log n)).
Here are functions that can do the job, but take time linear in the size of
the list/vector being added to:

user=> (defn add-at-end [l item] (concat l (list item)))
#'user/add-at-end
user=> (add-at-end '(1 2 3) 4)
(1 2 3 4)
user=> (defn add-at-front [v item] (vec (cons item (seq v
#'user/add-at-front
user=> (add-at-front [1 2 3] 4)
[4 1 2 3]

Andy



On Sat, Dec 10, 2011 at 3:13 AM, Michael Jaaka  wrote:

> Is there something like:
>
> (defn snoc[ col item ]
>(lazy-seq
>(if (seq col)
>(let[ [f &  r] col ]
>(if (seq r)
>(cons f (snoc r item))
>(cons f [item])))
>[item])))
>
> already here?
>
>
> (snoc (snoc (snoc [ 1 2 3] 4) 6) 7)
>
> gives:
>
> (1 2 3 4 5 6 7)
>
> --
> 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 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

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

2011-12-10 Thread Michael Jaaka
Is there something like:

(defn snoc[ col item ]
(lazy-seq
(if (seq col)
(let[ [f &  r] col ]
(if (seq r)
(cons f (snoc r item))
(cons f [item])))
[item])))

already here?


(snoc (snoc (snoc [ 1 2 3] 4) 6) 7)

gives:

(1 2 3 4 5 6 7)

-- 
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


Bug in core.match?

2011-12-10 Thread Benny Tsai
Hi all,

Ran into what appears to be a bug tonight.  This is the simplest example I 
could come up with:

(defn f [xs]
  (match xs
 [:a] "a"
 [:b b] b
 [:c] "c"
 :else "problem!"))

[:a] and [:b b] can be matched with no problems, but [:c] can't be matched 
for some reason:

user=> (f [:a])
"a"
user=> (f [:b 1])
1
user=> (f [:c])
"problem!"

I'm using Clojure 1.3 and core.match 0.2.0-alpha8.

-- 
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

Re: Trying to use CDT on 1.3.0

2011-12-10 Thread Ulises
Alternatively you can just do:

$ lein plugin install swank-clojure 1.3.3

and have swank across projects without having to add your
:dev-dependencies for each one.

U

-- 
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