Re: not= counterintuitive?

2011-09-06 Thread ax2groin
The clojure.contrib.combinatorics/combinations does do exactly what I
was trying to do, although I was doing the problem as an exercise in
how to do it, and not in really needing combinations for something
else. The combinatorics library certainly does it in a more generic
way.

Since I knew that I was dealing with numbers as input, I actually
ended up using (> m n o) as my test condition, which has the same
effect of guaranteeing all the numbers are distinct. I was looking for
unique sets where order didn't matter.

Thanks for the input, all!

-- 
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: not= counterintuitive?

2011-09-04 Thread Ken Wesson
On Sat, Sep 3, 2011 at 1:30 PM, Despite  wrote:
> So, you want to make sure each value in the vector is unique?  My
> first thought was to put them into a set, then see if the set was
> equal to the vector, but clojure's equality doesn't allow for that.
> And if you put the set back into a vector, you've changed the order.

Just see if the set is the same *size* as the vector. If there were
duplicates, it will be smaller instead.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: not= counterintuitive?

2011-09-03 Thread Alan Malloy
(= (seq v) (distinct v)) will short-circuit as soon as an inequality
is found.

On Sep 3, 12:47 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> Am 03.09.2011 um 19:30 schrieb Despite:
>
> > So, you want to make sure each value in the vector is unique?  My
> > first thought was to put them into a set, then see if the set was
> > equal to the vector, but clojure's equality doesn't allow for that.
> > And if you put the set back into a vector, you've changed the order.
>
> You can check (= (count v) (count (set v))) whether there are no duplicates.
>
> Sincerley
> Meikel

-- 
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: not= counterintuitive?

2011-09-03 Thread Meikel Brandmeyer
Hi,

Am 03.09.2011 um 19:30 schrieb Despite:

> So, you want to make sure each value in the vector is unique?  My
> first thought was to put them into a set, then see if the set was
> equal to the vector, but clojure's equality doesn't allow for that.
> And if you put the set back into a vector, you've changed the order.

You can check (= (count v) (count (set v))) whether there are no duplicates.

Sincerley
Meikel

-- 
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: not= counterintuitive?

2011-09-03 Thread Despite
On Sep 2, 4:48 pm, ax2groin  wrote:
> That's what I get for posting a question while feeding a 1-year-old
> child and getting ready to leave for lunch.
>
> I was trying to put together a (for) construct to output the
> combinations of a set, and my logic was flawed.
>
> Here's what I really wanted [for sets of 3]:
>
> (for [m x n x o x :while (and (not= m n) (not= m o) (not= n o))] [m n
> o])
>
> Maybe not the most efficient, but the smallest construct I've come up
> with, but it isn't generic enough for me yet.
>
> I'll keep working on it.

So, you want to make sure each value in the vector is unique?  My
first thought was to put them into a set, then see if the set was
equal to the vector, but clojure's equality doesn't allow for that.
And if you put the set back into a vector, you've changed the order.

Now I think you might be asking for the permutations.
clojure.contrib.combinatorics as a permutations function:

user=> (clojure.contrib.combinatorics/permutations [1 2 3])
((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 2 1))

-- 
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: not= counterintuitive?

2011-09-03 Thread Chouser
On Sat, Sep 3, 2011 at 10:59 AM, Alex Baranosky
 wrote:
> Sounds like you want a function such as:
>
> none=

...which could be written as #(not-any? #{1} [1 2 3])

--Chouser

-- 
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: not= counterintuitive?

2011-09-03 Thread Alex Baranosky
Sounds like you want a function such as:

none=
On Sep 3, 2011 4:30 AM, "Vijay Lakshminarayanan" 
wrote:
> ax2groin  writes:
>
>> This code doesn't return the value I intuitively expect:
>>
>> user=> (not= 1 2 1)
>> true
>>
>> When I write that, I was expecting the equivalent of (and (= 1 2) (= 1
>> 1)), but the macro expansion is essentially (not (= 1 2 1)).
>
> If you were expecting (not (and (= 1 2) (= 1 1))) then it would match
> your expectations.
>
> --
> Cheers
> ~vijay
>
> --
> 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: not= counterintuitive?

2011-09-03 Thread Vijay Lakshminarayanan
ax2groin  writes:

> This code doesn't return the value I intuitively expect:
>
>   user=> (not= 1 2 1)
>   true
>
> When I write that, I was expecting the equivalent of (and (= 1 2) (= 1
> 1)), but the macro expansion is essentially (not (= 1 2 1)).

If you were expecting (not (and (= 1 2) (= 1 1))) then it would match
your expectations.

-- 
Cheers
~vijay

-- 
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: not= counterintuitive?

2011-09-02 Thread ax2groin
That's what I get for posting a question while feeding a 1-year-old
child and getting ready to leave for lunch.

I was trying to put together a (for) construct to output the
combinations of a set, and my logic was flawed.

Here's what I really wanted [for sets of 3]:

(for [m x n x o x :while (and (not= m n) (not= m o) (not= n o))] [m n
o])

Maybe not the most efficient, but the smallest construct I've come up
with, but it isn't generic enough for me yet.

I'll keep working on it.

-- 
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: not= counterintuitive?

2011-09-02 Thread Alan Malloy
On Sep 2, 11:14 am, ax2groin  wrote:
> This code doesn't return the value I intuitively expect:
>
>   user=> (not= 1 2 1)
>   true
>
> When I write that, I was expecting the equivalent of (and (= 1 2) (= 1
> 1)), but the macro expansion is essentially (not (= 1 2 1)).

This is not a macro.

-- 
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: not= counterintuitive?

2011-09-02 Thread Laurent PETIT
2011/9/2 Mark Engelberg 

>
> On Fri, Sep 2, 2011 at 11:14 AM, ax2groin  wrote:
>
>> This code doesn't return the value I intuitively expect:
>>
>>  user=> (not= 1 2 1)
>>  true
>>
>> This is exactly what I expect. Those values are not all equal.
>

same for me


>  --
> 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: not= counterintuitive?

2011-09-02 Thread Mark Engelberg
On Fri, Sep 2, 2011 at 11:14 AM, ax2groin  wrote:

> This code doesn't return the value I intuitively expect:
>
>  user=> (not= 1 2 1)
>  true
>
> This is exactly what I expect. Those values are not all equal.

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

not= counterintuitive?

2011-09-02 Thread ax2groin
This code doesn't return the value I intuitively expect:

  user=> (not= 1 2 1)
  true

When I write that, I was expecting the equivalent of (and (= 1 2) (= 1
1)), but the macro expansion is essentially (not (= 1 2 1)).

Note: This came out of the :while condition of a (for) expression not
returning what I expected on three separate values, where (= x z).

I can work around it to get what I want, but I was curious if perhaps
the (not=) was not in the spirit it was intended.

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