Counting from zero

Laurence Rozier laurence.rozier at gmail.com
Tue May 2 12:44:50 UTC 2006


On 5/1/06, Nagy Attila <attis at gizi.dote.hu> wrote:
>
> Now I know what the title  William Gibson's novel 'Count Zero' refers to.
> ;)


Heh -  well

I find Laurence's solution very elegant.


Thanks but I think you're referring to Jecel's solution which I seconded for
exactly because of what Ralph suggests - "program at a high level". In a
case like Jecel's where hw *is* the high level his solution:

The current program I am writing in Squeak simulates hardware and 1
based arrays were a bit inconvenient, so the first thing I did was
define a ZArray class as a subclass of ArrayedCollection with

at: index
 ^ super at: index + 1

at: index put: obj
 ^ super at: index + 1 put: obj

do: block
  0 to: self size - 1 do:
        [ :index | block value: (self at: index) ]

and your countZero method are quite appropriate. Chances are, particularly
in the coming world of Spoon, this code wouldn't ever appear in an image
being used by someone new to the Smalltalk environment. Even if it did these
approaches don't interfere on any other uses of Array and wouldn't be
noticed by the overwhelming majority of programmers whose "high level" is
not hw. It's easy for the knowledgeable developer to use ZArray as needed.
To me this is the best of both worlds. I would say Wolfgang, there's no need
to impose one approach or another on all programmers or all situations if
you "program at a high level".

Cheers,

Laurence

I can even imagine adding a
> method to Integer:
>
> Integer>>countZero
>
> ^ self + 1
>
> Then you could have:
>
> someCollection at: 5 countZero
>
> Legible and simple, what do you say?
>
>                 Attis
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20060502/cde2375d/attachment.htm


More information about the Squeak-dev mailing list