Why String>>adaptToNumber: rcvr andSend: selector

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Why String>>adaptToNumber: rcvr andSend: selector

Guillermo Polito
Do we reeeeeally want to do

5 + '4'

5 + 'hello'

?

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Nicolas Cellier
Noooo, we dooon't want to.

Nicolas

2010/8/24 Guillermo Polito <[hidden email]>:

> Do we reeeeeally want to do
>
> 5 + '4'
>
> 5 + 'hello'
>
> ?
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Carla F. Griggio
In reply to this post by Guillermo Polito
What we've been discussing with Guille is that sometimes the 'type checking' (or actually, the conversion) is done, and sometimes not.

For example:

5 + true

true does not understand 'adaptToNumber:andSend:', so no magic conversion is done, but strings understand that message so we get things like:

5 + 'foo' = 5

This should be consistent regardless the type of the parameter.

Cheers,
Carla


On Tue, Aug 24, 2010 at 5:10 PM, Guillermo Polito <[hidden email]> wrote:
Do we reeeeeally want to do

5 + '4'

5 + 'hello'

?


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Nicolas Cellier
There are two superposed problems there

1) let String auto convert to Number when implied in arithmetic
2) let any malformed String asNumber answer zero

To my sense, both features:
* are not really necessary nor worth
* are a source of problems
* should better be removed.

Nicolas

2010/8/24 Carla F. Griggio <[hidden email]>:

> What we've been discussing with Guille is that sometimes the 'type checking'
> (or actually, the conversion) is done, and sometimes not.
>
> For example:
>
> 5 + true
>
> true does not understand 'adaptToNumber:andSend:', so no magic conversion is
> done, but strings understand that message so we get things like:
>
> 5 + 'foo' = 5
>
> This should be consistent regardless the type of the parameter.
>
> Cheers,
> Carla
>
>
> On Tue, Aug 24, 2010 at 5:10 PM, Guillermo Polito
> <[hidden email]> wrote:
>>
>> Do we reeeeeally want to do
>>
>> 5 + '4'
>>
>> 5 + 'hello'
>>
>> ?
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Guillermo Polito
In reply to this post by Carla F. Griggio
Well Collection and Point understand that message too.

One step at a time, but an issue entry now so we don't forget about it.

http://code.google.com/p/pharo/issues/detail?id=2858

On Tue, Aug 24, 2010 at 5:20 PM, Carla F. Griggio <[hidden email]> wrote:
What we've been discussing with Guille is that sometimes the 'type checking' (or actually, the conversion) is done, and sometimes not.

For example:

5 + true

true does not understand 'adaptToNumber:andSend:', so no magic conversion is done, but strings understand that message so we get things like:

5 + 'foo' = 5

This should be consistent regardless the type of the parameter.

Cheers,
Carla



On Tue, Aug 24, 2010 at 5:10 PM, Guillermo Polito <[hidden email]> wrote:
Do we reeeeeally want to do

5 + '4'

5 + 'hello'

?



_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Guillermo Polito
I feel these pieces of code aren't really explicit in what they do

5 + 'hello'

5 + (1 to: 10)

5 + (1@5)


On Tue, Aug 24, 2010 at 5:42 PM, Guillermo Polito <[hidden email]> wrote:
Well Collection and Point understand that message too.

One step at a time, but an issue entry now so we don't forget about it.

http://code.google.com/p/pharo/issues/detail?id=2858


On Tue, Aug 24, 2010 at 5:20 PM, Carla F. Griggio <[hidden email]> wrote:
What we've been discussing with Guille is that sometimes the 'type checking' (or actually, the conversion) is done, and sometimes not.

For example:

5 + true

true does not understand 'adaptToNumber:andSend:', so no magic conversion is done, but strings understand that message so we get things like:

5 + 'foo' = 5

This should be consistent regardless the type of the parameter.

Cheers,
Carla



On Tue, Aug 24, 2010 at 5:10 PM, Guillermo Polito <[hidden email]> wrote:
Do we reeeeeally want to do

5 + '4'

5 + 'hello'

?




_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Carla F. Griggio
I think 5 + 'hello' is plain wrong.

In these cases:

5 + (1 to: 10)

5 + (1@5)

the message shouldn't be conmutative. What I mean is that I don't want that to be the same as:

(1 to: 10) + 5

(1 @ 5) + 5

On Tue, Aug 24, 2010 at 5:44 PM, Guillermo Polito <[hidden email]> wrote:
I feel these pieces of code aren't really explicit in what they do

5 + 'hello'

5 + (1 to: 10)

5 + (1@5)



On Tue, Aug 24, 2010 at 5:42 PM, Guillermo Polito <[hidden email]> wrote:
Well Collection and Point understand that message too.

One step at a time, but an issue entry now so we don't forget about it.

http://code.google.com/p/pharo/issues/detail?id=2858


On Tue, Aug 24, 2010 at 5:20 PM, Carla F. Griggio <[hidden email]> wrote:
What we've been discussing with Guille is that sometimes the 'type checking' (or actually, the conversion) is done, and sometimes not.

For example:

5 + true

true does not understand 'adaptToNumber:andSend:', so no magic conversion is done, but strings understand that message so we get things like:

5 + 'foo' = 5

This should be consistent regardless the type of the parameter.

Cheers,
Carla



On Tue, Aug 24, 2010 at 5:10 PM, Guillermo Polito <[hidden email]> wrote:
Do we reeeeeally want to do

5 + '4'

5 + 'hello'

?





_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Guillermo Polito
But... What do they do? They are not clean.

Does the collection one add the element to the collection?

Does the point one add the number to the first, the second or both components?  I remember that a point might be added to other point, multiplied by another point or a scalar :).

On Tue, Aug 24, 2010 at 5:53 PM, Carla F. Griggio <[hidden email]> wrote:
I think 5 + 'hello' is plain wrong.

In these cases:


5 + (1 to: 10)

5 + (1@5)

the message shouldn't be conmutative. What I mean is that I don't want that to be the same as:

(1 to: 10) + 5

(1 @ 5) + 5


On Tue, Aug 24, 2010 at 5:44 PM, Guillermo Polito <[hidden email]> wrote:
I feel these pieces of code aren't really explicit in what they do

5 + 'hello'

5 + (1 to: 10)

5 + (1@5)



On Tue, Aug 24, 2010 at 5:42 PM, Guillermo Polito <[hidden email]> wrote:
Well Collection and Point understand that message too.

One step at a time, but an issue entry now so we don't forget about it.

http://code.google.com/p/pharo/issues/detail?id=2858


On Tue, Aug 24, 2010 at 5:20 PM, Carla F. Griggio <[hidden email]> wrote:
What we've been discussing with Guille is that sometimes the 'type checking' (or actually, the conversion) is done, and sometimes not.

For example:

5 + true

true does not understand 'adaptToNumber:andSend:', so no magic conversion is done, but strings understand that message so we get things like:

5 + 'foo' = 5

This should be consistent regardless the type of the parameter.

Cheers,
Carla



On Tue, Aug 24, 2010 at 5:10 PM, Guillermo Polito <[hidden email]> wrote:
Do we reeeeeally want to do

5 + '4'

5 + 'hello'

?






_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Carla F. Griggio
(1 to: 10) + 5

is a shortcut for (1 to: 10) collect:[:number | number + 5]

(1 @ 5) + 5

is a shortcut for (1 @ 5) + (5 @ 5)



On Tue, Aug 24, 2010 at 6:02 PM, Guillermo Polito <[hidden email]> wrote:
But... What do they do? They are not clean.

Does the collection one add the element to the collection?

Does the point one add the number to the first, the second or both components?  I remember that a point might be added to other point, multiplied by another point or a scalar :).


On Tue, Aug 24, 2010 at 5:53 PM, Carla F. Griggio <[hidden email]> wrote:
I think 5 + 'hello' is plain wrong.

In these cases:


5 + (1 to: 10)

5 + (1@5)

the message shouldn't be conmutative. What I mean is that I don't want that to be the same as:

(1 to: 10) + 5

(1 @ 5) + 5


On Tue, Aug 24, 2010 at 5:44 PM, Guillermo Polito <[hidden email]> wrote:
I feel these pieces of code aren't really explicit in what they do

5 + 'hello'

5 + (1 to: 10)

5 + (1@5)



On Tue, Aug 24, 2010 at 5:42 PM, Guillermo Polito <[hidden email]> wrote:
Well Collection and Point understand that message too.

One step at a time, but an issue entry now so we don't forget about it.

http://code.google.com/p/pharo/issues/detail?id=2858


On Tue, Aug 24, 2010 at 5:20 PM, Carla F. Griggio <[hidden email]> wrote:
What we've been discussing with Guille is that sometimes the 'type checking' (or actually, the conversion) is done, and sometimes not.

For example:

5 + true

true does not understand 'adaptToNumber:andSend:', so no magic conversion is done, but strings understand that message so we get things like:

5 + 'foo' = 5

This should be consistent regardless the type of the parameter.

Cheers,
Carla



On Tue, Aug 24, 2010 at 5:10 PM, Guillermo Polito <[hidden email]> wrote:
Do we reeeeeally want to do

5 + '4'

5 + 'hello'

?







_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

johnmci
In reply to this post by Guillermo Polito

On 2010-08-24, at 2:02 PM, Guillermo Polito wrote:

5 + (1 to: 10)

5 + (1@5)



I would think that becomes 5 to: 15  and 6@11

BTW don't let   'garbage' asNumber -> 0   that just is a hassle when importing character data that should be a number, but because of 
a mistake upstream it's not a number. Silently converting to zero is just evil...


--
===========================================================================
John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================





_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Stéphane Ducasse
+1

On Aug 24, 2010, at 11:07 PM, John M McIntosh wrote:

>
> On 2010-08-24, at 2:02 PM, Guillermo Polito wrote:
>
>> 5 + (1 to: 10)
>>
>> 5 + (1@5)
>>
>
>
> I would think that becomes 5 to: 15  and 6@11
>
> BTW don't let   'garbage' asNumber -> 0   that just is a hassle when importing character data that should be a number, but because of
> a mistake upstream it's not a number. Silently converting to zero is just evil...
>
>
> --
> ===========================================================================
> John M. McIntosh <[hidden email]>   Twitter:  squeaker68882
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> ===========================================================================
>
>
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Stéphane Ducasse
In reply to this post by Nicolas Cellier
:)

I accept code. We are in unstable so this is the time to shake the system.

On Aug 24, 2010, at 10:17 PM, Nicolas Cellier wrote:

> Noooo, we dooon't want to.
>
> Nicolas
>
> 2010/8/24 Guillermo Polito <[hidden email]>:
>> Do we reeeeeally want to do
>>
>> 5 + '4'
>>
>> 5 + 'hello'
>>
>> ?
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Guillermo Polito
Wow, morphic doesn't allow me to change the point aritmethic :D.  I supossed it ¬¬.

Here is already some code:  http://code.google.com/p/pharo/issues/detail?id=2858

On Wed, Aug 25, 2010 at 4:35 AM, Stéphane Ducasse <[hidden email]> wrote:
:)

I accept code. We are in unstable so this is the time to shake the system.

On Aug 24, 2010, at 10:17 PM, Nicolas Cellier wrote:

> Noooo, we dooon't want to.
>
> Nicolas
>
> 2010/8/24 Guillermo Polito <[hidden email]>:
>> Do we reeeeeally want to do
>>
>> 5 + '4'
>>
>> 5 + 'hello'
>>
>> ?
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Why String>>adaptToNumber: rcvr andSend: selector

Carla F. Griggio
(5 @ 1 ) + 5 doesn't really bother me :S In fact, when I started working with points, some kind of magic made me write that hoping it would work.

2010/8/25 Guillermo Polito <[hidden email]>
Wow, morphic doesn't allow me to change the point aritmethic :D.  I supossed it ¬¬.

Here is already some code:  http://code.google.com/p/pharo/issues/detail?id=2858


On Wed, Aug 25, 2010 at 4:35 AM, Stéphane Ducasse <[hidden email]> wrote:
:)

I accept code. We are in unstable so this is the time to shake the system.

On Aug 24, 2010, at 10:17 PM, Nicolas Cellier wrote:

> Noooo, we dooon't want to.
>
> Nicolas
>
> 2010/8/24 Guillermo Polito <[hidden email]>:
>> Do we reeeeeally want to do
>>
>> 5 + '4'
>>
>> 5 + 'hello'
>>
>> ?
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project