| a b| a := 14. b := - a. b inspect
is wrong
| a b| a := 14. b := 0 - a. b inspect
is right
Why ?
To get the negative of a value use
a negated.
Greetz Rob
-----Oorspronkelijk bericht----- Van: beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] 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 Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
El 5/10/07 2:22 PM, "Rob Van Pamel" rob.vanpamel@telenet.be 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.
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:herbertkoenig@gmx.net
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: beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] 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" rob.vanpamel@telenet.be 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 Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
El 5/10/07 2:43 PM, "Rob Van Pamel" rob.vanpamel@telenet.be escribió:
You don't have an object where you send your message to.
a := - 15
Where you send the message ?
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: beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] 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" rob.vanpamel@telenet.be escribió:
You don't have an object where you send your message to.
a := - 15
Where you send the message ?
_______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
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" rob.vanpamel@telenet.be escribió:
You don't have an object where you send your message to.
a := - 15
Where you send the message ?
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
El 5/10/07 3:18 PM, "Mathieu Suen" mathk.sue@gmail.com 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
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:herbertkoenig@gmx.net
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.
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:herbertkoenig@gmx.net
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.
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@lists.squeakfoundation.org