Hi,
I am currently trying to get a program running on Amber Smalltalk which involves doing calculations with Number objects. To add the missing functionality to the Number class I am using the "*MyPackage" protocol. So far I have succeeded in adding methods such as bitAnd:, bitOr: and so on. However, implementing the shift operators produced an interesting result. The implementations are the following: << aNumber <return Number(self) << aNumber> >> aNumber <return Number(self) >> aNumber> and the following happens when evaluating them: 4 << 1 -> 8 4 >> 1 -> true Any ideas on what could possibly go wrong with the >> implementation? Best regards, Manfred Kröhnert |
M K wrote: > Hi, > > I am currently trying to get a program running on Amber Smalltalk > which involves doing calculations with Number objects. > > To add the missing functionality to the Number class I am using the > "*MyPackage" protocol. > So far I have succeeded in adding methods such as bitAnd:, bitOr: and so on. > > However, implementing the shift operators produced an interesting result. > The implementations are the following: > > << aNumber > <return Number(self)<< aNumber> > >>> aNumber > <return Number(self)>> aNumber> > > and the following happens when evaluating them: > > 4<< 1 > -> 8 > > 4>> 1 > -> true It seems like premature ending of < ... > pragma. If it is interpreted as '(<return Number(self)>) > aNumber' than it can return true (I just don't know who swallowed the last '>'. Just the hypothesis. > Any ideas on what could possibly go wrong with the>> implementation? > > Best regards, > > Manfred Kröhnert Herby |
In reply to this post by Manfred Kröhnert
Hi!
Inside verbatim javascript, the ">" character is escaped, exactly like the "!" in the chunk format. So, if you write "Number(self) >> aNumber" it will be compiled as Number(self) > aNumber". Cheers, Nico On Apr 21, 2012, at 7:31 PM, M K wrote:
-- Nicolas Petton
http://www.nicolas-petton.fr |
Hi Nico,
> Inside verbatim javascript, the ">" character is escaped, exactly like the > "!" in the chunk format. > So, if you write "Number(self) >> aNumber" it will be compiled as > Number(self) > aNumber". thanks for the explanation. Any ideas on how to write this line so that it actually evaluates the shift operator as left shift and not as comparison? Best, Manfred |
Yes, you can do:
<Number(self) >>>> aNumber> Cheers, Nico On Apr 22, 2012, at 3:45 PM, Manfred Kröhnert wrote:
-- Nicolas Petton
http://www.nicolas-petton.fr |
Hmm,
I tried <return Number(self) >>>> aNumber> but the line 4 >> 1 still evaluates to true instead of 2. Best, Manfred On Sun, Apr 22, 2012 at 4:14 PM, Nicolas Petton <[hidden email]> wrote: > Yes, you can do: > > <Number(self) >>>> aNumber> > > Cheers, > Nico > > On Apr 22, 2012, at 3:45 PM, Manfred Kröhnert wrote: > > Hi Nico, > > Inside verbatim javascript, the ">" character is escaped, exactly like the > > "!" in the chunk format. > > So, if you write "Number(self) >> aNumber" it will be compiled as > > Number(self) > aNumber". > > > thanks for the explanation. > Any ideas on how to write this line so that it actually evaluates the > shift operator as left shift and not as comparison? > > Best, > > Manfred > > > -- > Nicolas Petton > http://www.nicolas-petton.fr > |
Free forum by Nabble | Edit this page |