[Q] A really silly question

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

[Q] A really silly question

Edgar J. De Cleene
| a b|
a := 14.
b := - a.
b inspect

is wrong


| a b|
a := 14.
b := 0 - a.
b inspect

is right

Why ?


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: [Q] A really silly question

Rob Van Pamel
To get the negative of a value use

a negated.

Greetz
  Rob

-----Oorspronkelijk bericht-----
Van: [hidden email]
[mailto:[hidden email]] Namens Edgar J. De
Cleene
Verzonden: donderdag 10 mei 2007 19:18
Aan: A friendly place to get answers to even the most basic questions about
Squeak.
Onderwerp: [Newbies] [Q] A really silly question

| a b|
a := 14.
b := - a.
b inspect

is wrong


| a b|
a := 14.
b := 0 - a.
b inspect

is right

Why ?


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: [Q] A really silly question

Edgar J. De Cleene



El 5/10/07 2:22 PM, "Rob Van Pamel" <[hidden email]> escribió:

> To get the negative of a value use
>
> a negated.
>
> Greetz
>   Rob

Yes, I know that.
What I ask is why you could't do b := - a.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re[2]: [Q] A really silly question

Herbert König
Hello Edgar,

EJDC> Yes, I know that.
EJDC> What I ask is why you could't do b := - a.

- is a message send. Who should be the receiver?

What's your idea to give this a chance to work?


Cheers,

Herbert                            mailto:[hidden email]

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: [Q] A really silly question

Rob Van Pamel
In reply to this post by Edgar J. De Cleene
This is because of the Architecture of Smalltalk ...

It is always so in Smalltalk that you send an message to an object ..
When you do the following

b := 0 - a.

You send the message '-' to the object 0. The parameter of the message is A.

These are called binary messages.
When you have

b := - a

You don't have an object where you send your message to.
Again like I said before when you do a negated you send the message negated
to the object a. I hope you understand it if you don't ask again and I'll
try to explain better

Greetz  

-----Oorspronkelijk bericht-----
Van: [hidden email]
[mailto:[hidden email]] Namens Edgar J. De
Cleene
Verzonden: donderdag 10 mei 2007 19:34
Aan: A friendly place to get answers to even the most basic questions about
Squeak.
Onderwerp: Re: [Newbies] [Q] A really silly question




El 5/10/07 2:22 PM, "Rob Van Pamel" <[hidden email]> escribió:

> To get the negative of a value use
>
> a negated.
>
> Greetz
>   Rob

Yes, I know that.
What I ask is why you could't do b := - a.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: [Q] A really silly question

Edgar J. De Cleene



El 5/10/07 2:43 PM, "Rob Van Pamel" <[hidden email]> escribió:

> You don't have an object where you send your message to.

a := - 15

Where you send the message ?






_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: [Q] A really silly question

Rob Van Pamel
hey

 a := - 15

Here - 15 is the complete message. But you don't have an object to receive
the message.
In 0 -15. The object who receives the message (- 15)is 0.

That is why a := -15 will not work

-----Oorspronkelijk bericht-----
Van: [hidden email]
[mailto:[hidden email]] Namens Edgar J. De
Cleene
Verzonden: donderdag 10 mei 2007 19:55
Aan: A friendly place to get answers to even the most basic questions about
Squeak.
Onderwerp: Re: [Newbies] [Q] A really silly question




El 5/10/07 2:43 PM, "Rob Van Pamel" <[hidden email]> escribió:

> You don't have an object where you send your message to.

a := - 15

Where you send the message ?






_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: [Q] A really silly question

Mathieu SUEN
In reply to this post by Edgar J. De Cleene
It's at compiled time no message is send.
-15 is a token
http://blog.3plus4.org/2007/05/06/whats-a-binary-selector/

        Mth



On May 10, 2007, at 7:55 PM, Edgar J. De Cleene wrote:

>
>
>
> El 5/10/07 2:43 PM, "Rob Van Pamel" <[hidden email]>  
> escribió:
>
>> You don't have an object where you send your message to.
>
> a := - 15
>
> Where you send the message ?
>
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: [Q] A really silly question

Edgar J. De Cleene



El 5/10/07 3:18 PM, "Mathieu Suen" <[hidden email]> escribió:

> It's at compiled time no message is send.
> -15 is a token
> http://blog.3plus4.org/2007/05/06/whats-a-binary-selector/
>
> Mth

At last a good why .
Very, very thanks.

Edgar


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re[2]: [Q] A really silly question

Herbert König
In reply to this post by Mathieu SUEN
Hello Mathieu,

MS> It's at compiled time no message is send.
MS> -15 is a token
MS> http://blog.3plus4.org/2007/05/06/whats-a-binary-selector/

the original question was
MS> | a b|
MS> a := 14.
MS> b := - a.
MS> b inspect

I believe - a is not parsed as a token here.

Up to now I believed that the Smalltalk compiler does not look at
previous statements to compile a given statement.

Am I wrong here? (no cs background, it's a real question).


Cheers,

Herbert                            mailto:[hidden email]

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re[2]: [Q] A really silly question

Mathieu SUEN
nextLiteral

        | prevToken |
        prevToken _ self advance.
        (prevToken == #- and: [token isKindOf: Number])
                ifTrue:
                        [^self advance negated].
        ^prevToken


        Mth



On May 10, 2007, at 8:43 PM, Herbert König wrote:

> Up to now I believed that the Smalltalk compiler does not look at
> previous statements to compile a given statement.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re[4]: [Q] A really silly question

Herbert König
Hello Mathieu,

MS> | prevToken |
MS> prevToken _ self advance.
MS> (prevToken == #- and: [token isKindOf: Number])
MS> ifTrue:
MS> [^self advance negated].
MS> ^prevToken

imho that doesn't contradict me (at least what I wanted to say :-)

In the example I quoted, the compiler (parser?) would have to look at
the previous line (a := 14.) to know that in the current line
(b := - a.) a is representing a number. Only then it makes sense to
try building a literal.

I was not successful in finding senders of nextLiteral in Scanner or
Parser so I still don't know. Also no luck with searching all sources.

Only hits in xml-parser which is a different beast.


Thanks for your patience anyway!

Herbert                            mailto:[hidden email]

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re[2]: [Q] A really silly question

Mathieu SUEN
In reply to this post by Herbert König
Oops sorry I missunderstood

of course -a is not parsed as a token but -14 it's

        Mth



On May 10, 2007, at 8:43 PM, Herbert König wrote:

> I believe - a is not parsed as a token here.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re[4]: [Q] A really silly question

Mathieu SUEN
In reply to this post by Herbert König
Yes actually I was pointing out the wrong method here  is the good  
one but really ugly(idea is still the same):
scanLitVec
...
                                                [(token == #-
                                                                        and: [((typeTable at: hereChar charCode ifAbsent:  
[#xLetter])) = #xDigit])
                                                                ifTrue:
                                                                        [self scanToken.
                                                                        token _ token negated]]].
...

        Mth



On May 10, 2007, at 9:31 PM, Herbert König wrote:

> I was not successful in finding senders of nextLiteral in Scanner or
> Parser so I still don't know. Also no luck with searching all sources.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: [Q] A really silly question

Nicolas Cellier-3
Mathieu Suen a écrit :

> Yes actually I was pointing out the wrong method here  is the good one
> but really ugly(idea is still the same):
> scanLitVec
> ...
>                         [(token == #-
>                                     and: [((typeTable at: hereChar
> charCode ifAbsent: [#xLetter])) = #xDigit])
>                                 ifTrue:
>                                     [self scanToken.
>                                     token _ token negated]]].
> ...
>
>     Mth
>
>
>
> On May 10, 2007, at 9:31 PM, Herbert König wrote:
>
>> I was not successful in finding senders of nextLiteral in Scanner or
>> Parser so I still don't know. Also no luck with searching all sources.

- 15 is a job of the parser, not the scanner as early noted by Mathieu.

See http://bugs.squeak.org/view.php?id=3616

It is specific to squeak and does not work in other Smalltalks.
And it is of course interpreted as two different tokens in a literal
array, try #(- 15) = #(-15)

I find it very confusing and already suggested to remove such a feature.
I am happy that Edgar pointed the problem out.

Nicolas

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners