[Pharo-dev] Spaceship?

phil at highoctane.be phil at highoctane.be
Mon Nov 4 08:21:28 EST 2013


Type and double dispatch + nil considérations come to mind.

nil <=> 7 gives?
7.0 <=> 3 gives ?

Object <=>: anObject

(self = anObject) ifTrue: [ ^0].

(self < anObject) ifTrue: [ ^ -1] ifFalse: [ ^ 1].

"otherwise let's raise an error"

What can now go wrong from here ?


Phil
On Monday, November 4, 2013, Stéphane Ducasse wrote:

> do you have a real use case?
>
> Stef
>
> On Nov 4, 2013, at 1:32 PM, Yuriy Tymchuk <yuriy.tymchuk at me.com<javascript:;>>
> wrote:
>
> > Hi everyone.
> >
> > I’m wandering if there was any sort of a discussion about a spaceship
> method used in Ruby.
> >
> > The concept is that you should implement a method <=>
> > that returns something negative if the receiver is smaller then a
> parameter,
> > positive when the receiver is greater then a parameter,
> > and 0 if they are equal.
> >
> > This way if you are implementing comparable object’s the only method you
> have to redefine is spaceship (<=>).
> >
> > Yes, I know that i Pharo you have to only redefine < and =. But maybe it
> would be interesting to use spaceship :)
> >
> > What do you think?
> > Cheers!
> > Uko
>
>
>

-- 
---
Philippe Back
Dramatic Performance Improvements
Mob: +32(0) 478 650 140 | Fax: +32 (0) 70 408 027
Mail:phil at highoctane.be | Web: http://philippeback.eu
Blog: http://philippeback.be | Twitter: @philippeback
Youtube: http://www.youtube.com/user/philippeback/videos

High Octane SPRL
rue cour Boisacq 101 | 1301 Bierges | Belgium

Pharo Consortium Member - http://consortium.pharo.org/
Featured on the Software Process and Measurement Cast -
http://spamcast.libsyn.com
Sparx Systems Enterprise Architect and Ability Engineering EADocX Value
Added Reseller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20131104/22c2b688/attachment-0002.html>


More information about the Pharo-dev mailing list