On Nov 3, 2008, at 8:35 PM, Mark H. wrote:

>
> On Nov 3, 5:39 pm, "Paul Stadig" <[EMAIL PROTECTED]> wrote:
>> Could/Should the max function be modified to work against the
>> Comparable interface instead of expecting its arguments to be  
>> numbers?
>>
>> I'm working with a sequence of strings that are dates in the
>> "yyyy-mm-dd" format, and I want to find the max. Calling max gives an
>> exception about not being able to cast to a java.lang.Number.
>
> I vote "no, max shouldn't be modified" because
>
> 1. The notation is ambiguous in the context of dates.  What's the
> "max" date?  The most recent one, or the oldest one?
> 2. Even if everyone agrees on what the "max date" of a sequence of
> dates means, you're asking what "max" means for a sequence of
> strings.  You're thinking of some kind of dictionary order, but some
> people might want to use string length.  Since your version of max
> would accept arbitrary strings, it would break for dates represented
> using a different string format.
>
> The semantics of "max string" are unclear enough that it would be
> better to write out the operation explicitly so that all readers of
> the code know what you mean.
>

I think clearly spelling out how objects of a type should be sorted is  
the point of the Comparable interface. Therefore if the authors of a  
given class have determined an absolute ordering for instances of that  
class I'd expect max or anything that sorts a list to follow that  
definition. Users are free to create subclasses that overwrite that  
definition, to use a different function, or ideally to to pass some  
kind of function as a parameter to max (and functions like it) and use  
that parameter for the purpose of the comparison.

- Cosmin

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to