[squeak-dev] The Trunk: Kernel-nice.402.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Feb 16 09:51:59 UTC 2010


2010/2/16 Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
> 2010/2/16 Michael Haupt <mhaupt at gmail.com>:
>> Hi,
>>
>> On Tue, Feb 16, 2010 at 10:08 AM,  <commits at source.squeak.org> wrote:
>>> +       "Answer a new Integer that has the bit of rank anInteger set to value.
>>> +       The bit value should be 0 or 1, otherwise raise an Error.
>>> +       The bits are indexed starting at 1 for the least significant bit.
>>> +       For negative integers, operate on 2-complement representation."
>>
>> hm. I understand that Smalltalk's idiomatic way of using 1-based
>> indexing is applied here, but the indices into bits of integers
>> correlate fairly strong with the powers of two they represent. I'd
>> argue that using 0 for the LSB is more appropriate with regard to the
>> domain being modelled here.
>>
>> Also, I'd suggest to raise the error early on, instead of at the end
>> of the entire method.
>>
>> Best,
>>
>> Michael
>>
>>
>
> Hi Michael,
>
> I understand your argument, but 1-based is the ANSI standard...
>
> I did not want to test pre-conditions, because most time, users will
> provide a 0 or 1 value and thus we will just waste time testing for
> nothing.
> But this could make sense to use precondition with another implementation:
>
>    (#(0 1) includes: value) ifFalse: [self error: '...'].
>    ^(self bitOr: (1 bitShift: anInteger - 1)) - (value bitShift: anInteger - 1)
>

Stupid me, it's more like
^(self bitOr: (1 bitShift: anInteger - 1)) - ((1-value) bitShift: anInteger - 1)

> Nicolas
>



More information about the Squeak-dev mailing list