[squeak-dev] Re: Letting Set contain nils?

Eliot Miranda eliot.miranda at gmail.com
Sat Aug 9 19:15:32 UTC 2008


On Sat, Aug 9, 2008 at 10:25 AM, tim Rowledge <tim at rowledge.org> wrote:

> When Sets are created the array holding the values is of course filled with
> nils by the VM. Using any other object to signify 'this slot is empty' would
> of course cost time to iterate over the array and fill each slot. Then for
> every grow it would cost more time to fill the new slots with this other
> distinguished value.


No it _would not_.  With a primitive that took the argument to fill with it
would take no extra time.  e.g.

Behavior methods for instance creation
basicNew: sizeRequested withAll: defaultValue
"Primitive. Answer an instance of this class with the number of indexable
variables specified by the argument, sizeRequested, initialized with
defaultValue.
Fail if this class is not indexable or if the argument is not a positive
Integer, or if
there is not enough memory available. Essential. See Object documentation
whatIsAPrimitive."

<primitive: NNN>
self isVariable ifFalse:
[self error: self printString, ' cannot have variable sized instances'].
(sizeRequested isInteger and: [sizeRequested >= 0]) ifTrue:
["arg okay; space must be low."
OutOfMemory signal.
^ self basicNew: sizeRequested withAll: defaultValue "retry if user
proceeds"].
self primitiveFailed

new: sizeRequested withAll: defaultValue
"Answer an initialized instance of this class with the number of indexable
 variables specified by the argument, sizeRequested, and all indexable slots
filled with defaultValue."

^ (self basicNew: sizeRequested withAll: defaultValue) initialize

Set methods for private
init: n
"Initialize array to an array size of n"
array := Array new: n withAll: self.
tally := 0

and delete ArrayedCollection class>>new:withAll:


Throughout these conversations I'm reminded of the song Little
Boxes<http://en.wikipedia.org/wiki/Little_Boxes>...
 It would be nice to think outside of them occasionally...

If you really, really, need a form of Set that can include nil as a useful
> object (for want of a better word) then make a new SetWithNils class or
> similar.


Indeed.  But before the standards committee comes down on us hard can we not
discuss the concept first?  Or are you still venting over _ being replaced
with :=, or with:......with: being replaced with, gasp, horror, *curly
braces* argh!!!!  Ohhhh noooo, mister bill......


>
>
> tim
> --
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> Fractured Idiom:- AMICUS PURIAE - Platonic friend
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20080809/4a587b96/attachment.htm


More information about the Squeak-dev mailing list