Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Jarrod Swart
Okay, I see now.  

Thanks for the Socratic dialogue, at the onset of the day I knew nothing 
about core.reducers.  I feel fairly conversational now!

On Friday, January 24, 2014 7:44:03 PM UTC-5, Cedric Greevey wrote:
>
> No, the identity for intersection is a set that has everything, as 
> (intersection A Everything) = A no matter what A is.
>
>
> On Fri, Jan 24, 2014 at 7:38 PM, Jarrod Swart 
> > wrote:
>
>> Good points.  But the "identity" thing is still what gets me.  What is 
>> the identity of an intersection?
>>
>> Like you said it can't be #{}.  If you seed an intersection with #{} you 
>> get #{}, so you can't intersect from the empty set.  The identity for an 
>> intersection is whatever the common element is, but how would you know that?
>>
>> On Friday, January 24, 2014 7:03:40 PM UTC-5, Cedric Greevey wrote:
>>
>>> Intersection is associative and commutative: (intersection A B) = 
>>> (intersection B A) and (intersection A (intersection B C)) = (intersection 
>>> (intersection A B) C) = the elements common to all three sets. So it's 
>>> actually perfectly well-founded for use with reducers, at least in 
>>> principle, and intersecting A B C D can be parallelized sensibly by 
>>> parallel intersecting A B and C D and then intersecting the two resulting 
>>> sets.
>>>
>>>
>>> On Fri, Jan 24, 2014 at 6:43 PM, Jarrod Swart  wrote:
>>>
 If I understand you correctly I am in agreement.  I don't think you 
 could take this problem to clojure.core.reducers/reduce or fold because 
 the 
 problem is inherently sequential is it not?

 The reduction is basically (intersection (intersection (intersection A 
 B) C) D).  

 I was curious of this myself, how do I abstract out the order of the 
 (reduce set/intersection ...).  I couldn't think of one.

 Breaking this problem out into 'parallel' units of reduction isn't 
 possible because the problem is dependent on order.  Which reducers can't 
 have, or so I think after what I have read today.


 On Friday, January 24, 2014 3:56:23 PM UTC-5, Cedric Greevey wrote:

> An interesting question this raises is if there is any sensible way to 
> define (intersection). It would need to behave as an identity element for 
> intersection, so would need to behave as a set (so, (set? (intersection)) 
> => truthy) that contained everything (so, (contains? (intersection) foo) 
> => 
> foo no matter what foo is; (partial contains? (intersection)) => 
> identity). 
> The problem would be what to do with seq? Ideally an infinite seq that 
> will 
> produce any particular value after finite time would be produced, but 
> there's no way to sensibly produce "any particular value" given the wide 
> variety of constructor semantics, builders, factory methods, things not 
> known to this particular runtime instance but that conceptually exist 
> somewhere, etc.; of course, the seq return is a dummy of sorts anyway 
> since 
> you couldn't really use it sensibly to it might as well just return 
> (range). Printing should likely be overridden to just print 
> "(intersection)" rather than b0rk the REPL with a neverending stream of 
> integers (or whatever).
>
> But then it also subtly violates another property of Clojure set 
> objects: if (= a b), (not (identical? a b)), and (identical? (a-set a) 
> a), 
> then (identical? (a-set b) a) and thus (not (identical? (a-set b) b)). 
> The 
> latter is true under the hypothesis for every "real" set but would be 
> false 
> for (intersection).
>
> Perhaps this is why (intersection) is not supported at this time, even 
> though (union) returns an empty set object, the identity element for the 
> union operation.
>
>
>  On Fri, Jan 24, 2014 at 3:34 PM, Jarrod Swart wrote:
>
>> Ah cool, thanks for posting your solution!
>>
>> On Friday, January 24, 2014 3:29:49 PM UTC-5, Tassilo Horn wrote:
>>
>>> Jarrod Swart  writes: 
>>>
>>> > The reason you can't get this to work is that r/map returns a 
>>>  
>>> > not a  for reduce to operate on. 
>>>
>>> Ah, indeed.  I couldn't see the forest for the trees. 
>>>
>>> > I'm not sure of a solution because I'm not familiar with 
>>> > core.reducers. 
>>>
>>> This works: 
>>>
>>>   (reduce set/intersection (r/foldcat (r/map set [[1 2] [3 1] [1 
>>> 3]]))) 
>>>
>>> Bye, 
>>> Tassilo 
>>>
>>  -- 
>> -- 
>> 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

Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Cedric Greevey
No, the identity for intersection is a set that has everything, as
(intersection A Everything) = A no matter what A is.


On Fri, Jan 24, 2014 at 7:38 PM, Jarrod Swart  wrote:

> Good points.  But the "identity" thing is still what gets me.  What is the
> identity of an intersection?
>
> Like you said it can't be #{}.  If you seed an intersection with #{} you
> get #{}, so you can't intersect from the empty set.  The identity for an
> intersection is whatever the common element is, but how would you know that?
>
> On Friday, January 24, 2014 7:03:40 PM UTC-5, Cedric Greevey wrote:
>
>> Intersection is associative and commutative: (intersection A B) =
>> (intersection B A) and (intersection A (intersection B C)) = (intersection
>> (intersection A B) C) = the elements common to all three sets. So it's
>> actually perfectly well-founded for use with reducers, at least in
>> principle, and intersecting A B C D can be parallelized sensibly by
>> parallel intersecting A B and C D and then intersecting the two resulting
>> sets.
>>
>>
>> On Fri, Jan 24, 2014 at 6:43 PM, Jarrod Swart  wrote:
>>
>>> If I understand you correctly I am in agreement.  I don't think you
>>> could take this problem to clojure.core.reducers/reduce or fold because the
>>> problem is inherently sequential is it not?
>>>
>>> The reduction is basically (intersection (intersection (intersection A
>>> B) C) D).
>>>
>>> I was curious of this myself, how do I abstract out the order of the
>>> (reduce set/intersection ...).  I couldn't think of one.
>>>
>>> Breaking this problem out into 'parallel' units of reduction isn't
>>> possible because the problem is dependent on order.  Which reducers can't
>>> have, or so I think after what I have read today.
>>>
>>>
>>> On Friday, January 24, 2014 3:56:23 PM UTC-5, Cedric Greevey wrote:
>>>
 An interesting question this raises is if there is any sensible way to
 define (intersection). It would need to behave as an identity element for
 intersection, so would need to behave as a set (so, (set? (intersection))
 => truthy) that contained everything (so, (contains? (intersection) foo) =>
 foo no matter what foo is; (partial contains? (intersection)) => identity).
 The problem would be what to do with seq? Ideally an infinite seq that will
 produce any particular value after finite time would be produced, but
 there's no way to sensibly produce "any particular value" given the wide
 variety of constructor semantics, builders, factory methods, things not
 known to this particular runtime instance but that conceptually exist
 somewhere, etc.; of course, the seq return is a dummy of sorts anyway since
 you couldn't really use it sensibly to it might as well just return
 (range). Printing should likely be overridden to just print
 "(intersection)" rather than b0rk the REPL with a neverending stream of
 integers (or whatever).

 But then it also subtly violates another property of Clojure set
 objects: if (= a b), (not (identical? a b)), and (identical? (a-set a) a),
 then (identical? (a-set b) a) and thus (not (identical? (a-set b) b)). The
 latter is true under the hypothesis for every "real" set but would be false
 for (intersection).

 Perhaps this is why (intersection) is not supported at this time, even
 though (union) returns an empty set object, the identity element for the
 union operation.


  On Fri, Jan 24, 2014 at 3:34 PM, Jarrod Swart wrote:

> Ah cool, thanks for posting your solution!
>
> On Friday, January 24, 2014 3:29:49 PM UTC-5, Tassilo Horn wrote:
>
>> Jarrod Swart  writes:
>>
>> > The reason you can't get this to work is that r/map returns a
>> 
>> > not a  for reduce to operate on.
>>
>> Ah, indeed.  I couldn't see the forest for the trees.
>>
>> > I'm not sure of a solution because I'm not familiar with
>> > core.reducers.
>>
>> This works:
>>
>>   (reduce set/intersection (r/foldcat (r/map set [[1 2] [3 1] [1
>> 3]])))
>>
>> Bye,
>> Tassilo
>>
>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+u...@googlegroups.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

  --
>>> --
>>> You received this mess

Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Jarrod Swart
Good points.  But the "identity" thing is still what gets me.  What is the 
identity of an intersection?

Like you said it can't be #{}.  If you seed an intersection with #{} you 
get #{}, so you can't intersect from the empty set.  The identity for an 
intersection is whatever the common element is, but how would you know that?

On Friday, January 24, 2014 7:03:40 PM UTC-5, Cedric Greevey wrote:
>
> Intersection is associative and commutative: (intersection A B) = 
> (intersection B A) and (intersection A (intersection B C)) = (intersection 
> (intersection A B) C) = the elements common to all three sets. So it's 
> actually perfectly well-founded for use with reducers, at least in 
> principle, and intersecting A B C D can be parallelized sensibly by 
> parallel intersecting A B and C D and then intersecting the two resulting 
> sets.
>
>
> On Fri, Jan 24, 2014 at 6:43 PM, Jarrod Swart 
> > wrote:
>
>> If I understand you correctly I am in agreement.  I don't think you could 
>> take this problem to clojure.core.reducers/reduce or fold because the 
>> problem is inherently sequential is it not?
>>
>> The reduction is basically (intersection (intersection (intersection A B) 
>> C) D).  
>>
>> I was curious of this myself, how do I abstract out the order of the 
>> (reduce set/intersection ...).  I couldn't think of one.
>>
>> Breaking this problem out into 'parallel' units of reduction isn't 
>> possible because the problem is dependent on order.  Which reducers can't 
>> have, or so I think after what I have read today.
>>
>>
>> On Friday, January 24, 2014 3:56:23 PM UTC-5, Cedric Greevey wrote:
>>
>>> An interesting question this raises is if there is any sensible way to 
>>> define (intersection). It would need to behave as an identity element for 
>>> intersection, so would need to behave as a set (so, (set? (intersection)) 
>>> => truthy) that contained everything (so, (contains? (intersection) foo) => 
>>> foo no matter what foo is; (partial contains? (intersection)) => identity). 
>>> The problem would be what to do with seq? Ideally an infinite seq that will 
>>> produce any particular value after finite time would be produced, but 
>>> there's no way to sensibly produce "any particular value" given the wide 
>>> variety of constructor semantics, builders, factory methods, things not 
>>> known to this particular runtime instance but that conceptually exist 
>>> somewhere, etc.; of course, the seq return is a dummy of sorts anyway since 
>>> you couldn't really use it sensibly to it might as well just return 
>>> (range). Printing should likely be overridden to just print 
>>> "(intersection)" rather than b0rk the REPL with a neverending stream of 
>>> integers (or whatever).
>>>
>>> But then it also subtly violates another property of Clojure set 
>>> objects: if (= a b), (not (identical? a b)), and (identical? (a-set a) a), 
>>> then (identical? (a-set b) a) and thus (not (identical? (a-set b) b)). The 
>>> latter is true under the hypothesis for every "real" set but would be false 
>>> for (intersection).
>>>
>>> Perhaps this is why (intersection) is not supported at this time, even 
>>> though (union) returns an empty set object, the identity element for the 
>>> union operation.
>>>
>>>
>>>  On Fri, Jan 24, 2014 at 3:34 PM, Jarrod Swart  wrote:
>>>
 Ah cool, thanks for posting your solution!

 On Friday, January 24, 2014 3:29:49 PM UTC-5, Tassilo Horn wrote:

> Jarrod Swart  writes: 
>
> > The reason you can't get this to work is that r/map returns a 
>  
> > not a  for reduce to operate on. 
>
> Ah, indeed.  I couldn't see the forest for the trees. 
>
> > I'm not sure of a solution because I'm not familiar with 
> > core.reducers. 
>
> This works: 
>
>   (reduce set/intersection (r/foldcat (r/map set [[1 2] [3 1] [1 
> 3]]))) 
>
> Bye, 
> Tassilo 
>
  -- 
 -- 
 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 unsubscribe from this group and stop receiving emails from it, send 
 an email to clojure+u...@googlegroups.com.

 For more options, visit https://groups.google.com/groups/opt_out.

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

Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Cedric Greevey
Intersection is associative and commutative: (intersection A B) =
(intersection B A) and (intersection A (intersection B C)) = (intersection
(intersection A B) C) = the elements common to all three sets. So it's
actually perfectly well-founded for use with reducers, at least in
principle, and intersecting A B C D can be parallelized sensibly by
parallel intersecting A B and C D and then intersecting the two resulting
sets.


On Fri, Jan 24, 2014 at 6:43 PM, Jarrod Swart  wrote:

> If I understand you correctly I am in agreement.  I don't think you could
> take this problem to clojure.core.reducers/reduce or fold because the
> problem is inherently sequential is it not?
>
> The reduction is basically (intersection (intersection (intersection A B)
> C) D).
>
> I was curious of this myself, how do I abstract out the order of the
> (reduce set/intersection ...).  I couldn't think of one.
>
> Breaking this problem out into 'parallel' units of reduction isn't
> possible because the problem is dependent on order.  Which reducers can't
> have, or so I think after what I have read today.
>
>
> On Friday, January 24, 2014 3:56:23 PM UTC-5, Cedric Greevey wrote:
>
>> An interesting question this raises is if there is any sensible way to
>> define (intersection). It would need to behave as an identity element for
>> intersection, so would need to behave as a set (so, (set? (intersection))
>> => truthy) that contained everything (so, (contains? (intersection) foo) =>
>> foo no matter what foo is; (partial contains? (intersection)) => identity).
>> The problem would be what to do with seq? Ideally an infinite seq that will
>> produce any particular value after finite time would be produced, but
>> there's no way to sensibly produce "any particular value" given the wide
>> variety of constructor semantics, builders, factory methods, things not
>> known to this particular runtime instance but that conceptually exist
>> somewhere, etc.; of course, the seq return is a dummy of sorts anyway since
>> you couldn't really use it sensibly to it might as well just return
>> (range). Printing should likely be overridden to just print
>> "(intersection)" rather than b0rk the REPL with a neverending stream of
>> integers (or whatever).
>>
>> But then it also subtly violates another property of Clojure set objects:
>> if (= a b), (not (identical? a b)), and (identical? (a-set a) a), then
>> (identical? (a-set b) a) and thus (not (identical? (a-set b) b)). The
>> latter is true under the hypothesis for every "real" set but would be false
>> for (intersection).
>>
>> Perhaps this is why (intersection) is not supported at this time, even
>> though (union) returns an empty set object, the identity element for the
>> union operation.
>>
>>
>> On Fri, Jan 24, 2014 at 3:34 PM, Jarrod Swart  wrote:
>>
>>> Ah cool, thanks for posting your solution!
>>>
>>> On Friday, January 24, 2014 3:29:49 PM UTC-5, Tassilo Horn wrote:
>>>
 Jarrod Swart  writes:

 > The reason you can't get this to work is that r/map returns a
 
 > not a  for reduce to operate on.

 Ah, indeed.  I couldn't see the forest for the trees.

 > I'm not sure of a solution because I'm not familiar with
 > core.reducers.

 This works:

   (reduce set/intersection (r/foldcat (r/map set [[1 2] [3 1] [1 3]])))

 Bye,
 Tassilo

>>>  --
>>> --
>>> 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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+u...@googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this

Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Ben Wolfson
On Fri, Jan 24, 2014 at 12:56 PM, Cedric Greevey  wrote:

> An interesting question this raises is if there is any sensible way to
> define (intersection). It would need to behave as an identity element for
> intersection, so would need to behave as a set (so, (set? (intersection))
> => truthy) that contained everything (so, (contains? (intersection) foo) =>
> foo no matter what foo is; (partial contains? (intersection)) => identity).
> The problem would be what to do with seq? Ideally an infinite seq that will
> produce any particular value after finite time would be produced, but
> there's no way to sensibly produce "any particular value" given the wide
> variety of constructor semantics, builders, factory methods, things not
> known to this particular runtime instance but that conceptually exist
> somewhere, etc.; of course, the seq return is a dummy of sorts anyway since
> you couldn't really use it sensibly to it might as well just return
> (range). Printing should likely be overridden to just print
> "(intersection)" rather than b0rk the REPL with a neverending stream of
> integers (or whatever).
>

Why should printing be overridden? If I print (range) I don't get "(range)".

Also, contains? returns true if the first argument contains the second, not
the second; (partial contains? (intersection)) => (constantly true).


> But then it also subtly violates another property of Clojure set objects:
> if (= a b), (not (identical? a b)), and (identical? (a-set a) a), then
> (identical? (a-set b) a) and thus (not (identical? (a-set b) b)). The
> latter is true under the hypothesis for every "real" set but would be false
> for (intersection).
>

Is this a real property of Clojure's sets or an artifact of their present
implementation? Is it something that anything impleneting IPersistentSet
has to promise to uphold?

-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure."
[Larousse, "Drink" entry]

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Jarrod Swart
If I understand you correctly I am in agreement.  I don't think you could 
take this problem to clojure.core.reducers/reduce or fold because the 
problem is inherently sequential is it not?

The reduction is basically (intersection (intersection (intersection A B) 
C) D).  

I was curious of this myself, how do I abstract out the order of the 
(reduce set/intersection ...).  I couldn't think of one.

Breaking this problem out into 'parallel' units of reduction isn't possible 
because the problem is dependent on order.  Which reducers can't have, or 
so I think after what I have read today.

On Friday, January 24, 2014 3:56:23 PM UTC-5, Cedric Greevey wrote:
>
> An interesting question this raises is if there is any sensible way to 
> define (intersection). It would need to behave as an identity element for 
> intersection, so would need to behave as a set (so, (set? (intersection)) 
> => truthy) that contained everything (so, (contains? (intersection) foo) => 
> foo no matter what foo is; (partial contains? (intersection)) => identity). 
> The problem would be what to do with seq? Ideally an infinite seq that will 
> produce any particular value after finite time would be produced, but 
> there's no way to sensibly produce "any particular value" given the wide 
> variety of constructor semantics, builders, factory methods, things not 
> known to this particular runtime instance but that conceptually exist 
> somewhere, etc.; of course, the seq return is a dummy of sorts anyway since 
> you couldn't really use it sensibly to it might as well just return 
> (range). Printing should likely be overridden to just print 
> "(intersection)" rather than b0rk the REPL with a neverending stream of 
> integers (or whatever).
>
> But then it also subtly violates another property of Clojure set objects: 
> if (= a b), (not (identical? a b)), and (identical? (a-set a) a), then 
> (identical? (a-set b) a) and thus (not (identical? (a-set b) b)). The 
> latter is true under the hypothesis for every "real" set but would be false 
> for (intersection).
>
> Perhaps this is why (intersection) is not supported at this time, even 
> though (union) returns an empty set object, the identity element for the 
> union operation.
>
>
> On Fri, Jan 24, 2014 at 3:34 PM, Jarrod Swart 
> > wrote:
>
>> Ah cool, thanks for posting your solution!
>>
>> On Friday, January 24, 2014 3:29:49 PM UTC-5, Tassilo Horn wrote:
>>
>>> Jarrod Swart  writes: 
>>>
>>> > The reason you can't get this to work is that r/map returns a 
>>>  
>>> > not a  for reduce to operate on. 
>>>
>>> Ah, indeed.  I couldn't see the forest for the trees. 
>>>
>>> > I'm not sure of a solution because I'm not familiar with 
>>> > core.reducers. 
>>>
>>> This works: 
>>>
>>>   (reduce set/intersection (r/foldcat (r/map set [[1 2] [3 1] [1 3]]))) 
>>>
>>> Bye, 
>>> Tassilo 
>>>
>>  -- 
>> -- 
>> 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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Cedric Greevey
An interesting question this raises is if there is any sensible way to
define (intersection). It would need to behave as an identity element for
intersection, so would need to behave as a set (so, (set? (intersection))
=> truthy) that contained everything (so, (contains? (intersection) foo) =>
foo no matter what foo is; (partial contains? (intersection)) => identity).
The problem would be what to do with seq? Ideally an infinite seq that will
produce any particular value after finite time would be produced, but
there's no way to sensibly produce "any particular value" given the wide
variety of constructor semantics, builders, factory methods, things not
known to this particular runtime instance but that conceptually exist
somewhere, etc.; of course, the seq return is a dummy of sorts anyway since
you couldn't really use it sensibly to it might as well just return
(range). Printing should likely be overridden to just print
"(intersection)" rather than b0rk the REPL with a neverending stream of
integers (or whatever).

But then it also subtly violates another property of Clojure set objects:
if (= a b), (not (identical? a b)), and (identical? (a-set a) a), then
(identical? (a-set b) a) and thus (not (identical? (a-set b) b)). The
latter is true under the hypothesis for every "real" set but would be false
for (intersection).

Perhaps this is why (intersection) is not supported at this time, even
though (union) returns an empty set object, the identity element for the
union operation.


On Fri, Jan 24, 2014 at 3:34 PM, Jarrod Swart  wrote:

> Ah cool, thanks for posting your solution!
>
> On Friday, January 24, 2014 3:29:49 PM UTC-5, Tassilo Horn wrote:
>
>> Jarrod Swart  writes:
>>
>> > The reason you can't get this to work is that r/map returns a
>> 
>> > not a  for reduce to operate on.
>>
>> Ah, indeed.  I couldn't see the forest for the trees.
>>
>> > I'm not sure of a solution because I'm not familiar with
>> > core.reducers.
>>
>> This works:
>>
>>   (reduce set/intersection (r/foldcat (r/map set [[1 2] [3 1] [1 3]])))
>>
>> Bye,
>> Tassilo
>>
>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Jarrod Swart
Ah cool, thanks for posting your solution!

On Friday, January 24, 2014 3:29:49 PM UTC-5, Tassilo Horn wrote:
>
> Jarrod Swart > writes: 
>
> > The reason you can't get this to work is that r/map returns a 
>  
> > not a  for reduce to operate on. 
>
> Ah, indeed.  I couldn't see the forest for the trees. 
>
> > I'm not sure of a solution because I'm not familiar with 
> > core.reducers. 
>
> This works: 
>
>   (reduce set/intersection (r/foldcat (r/map set [[1 2] [3 1] [1 3]]))) 
>
> Bye, 
> Tassilo 
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Tassilo Horn
Jarrod Swart  writes:

> The reason you can't get this to work is that r/map returns a  
> not a  for reduce to operate on.

Ah, indeed.  I couldn't see the forest for the trees.

> I'm not sure of a solution because I'm not familiar with
> core.reducers.

This works:

  (reduce set/intersection (r/foldcat (r/map set [[1 2] [3 1] [1 3]])))

Bye,
Tassilo

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Jarrod Swart
The reason you can't get this to work is that r/map returns a  
not a  for reduce to operate on.  I'm not sure of a solution because 
I'm not familiar with core.reducers.  But reading this: 
http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html
 informed 
me of your problems.  Sorry I can only point you in the right direction 
rather than provide a solution.



On Friday, January 24, 2014 5:26:11 AM UTC-5, Tassilo Horn wrote:
>
> Hi all, 
>
> in the following, set is clojure.set, and r is clojure.core reducers. 
>
> Why is 
>
> user> (reduce set/intersection (map set [[1 2] [3 1] [1 3]])) 
> #{1} 
>
> but 
>
> user> (reduce set/intersection (r/map set [[1 2] [3 1] [1 3]])) 
> ArityException Wrong number of args (0) passed to: set$intersection 
> clojure.lang.AFn.throwArity (AFn.java:437) 
>
> The clojure.core/reduce docs state that when there's no init value, the 
> reduce function is called with the first two elements of the coll. 
>
> The behavior of calling the reduce function with no arguments to create 
> an init value is specified for r/reduce, but I'm not using that. 
>
> Is that a bug, or should I not expect that clojure.core/reduce works 
> with reducible collections?  (I've not followed which reducer changes 
> were made in clojure 1.5.1.) 
>
> Bye, 
> Tassilo 
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


clojure.core/reduce calls (f) if given a reducible coll and no init value

2014-01-24 Thread Tassilo Horn
Hi all,

in the following, set is clojure.set, and r is clojure.core reducers.

Why is

user> (reduce set/intersection (map set [[1 2] [3 1] [1 3]]))
#{1}

but

user> (reduce set/intersection (r/map set [[1 2] [3 1] [1 3]]))
ArityException Wrong number of args (0) passed to: set$intersection
clojure.lang.AFn.throwArity (AFn.java:437)

The clojure.core/reduce docs state that when there's no init value, the
reduce function is called with the first two elements of the coll.

The behavior of calling the reduce function with no arguments to create
an init value is specified for r/reduce, but I'm not using that.

Is that a bug, or should I not expect that clojure.core/reduce works
with reducible collections?  (I've not followed which reducer changes
were made in clojure 1.5.1.)

Bye,
Tassilo

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.