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

Igor Stasenko siguctua at gmail.com
Sun Aug 10 12:37:20 UTC 2008


2008/8/10 stephane ducasse <stephane.ducasse at free.fr>:
> Eliot
>
> It would be great if we could have such nice primitive. Do you plan to add
> it in COG. I hope so.
>
This would require a little changes i think.

All allocations end up with a method:

allocate: byteSize headerSize: hdrSize h1: baseHeader h2: classOop h3:
extendedSize doFill: doFill with: fillWord

as you see, there is already a #doFill:with: in the tail, so it would
need simply to accept an extra argument higher in the chain of
invocations which serving to allocate object(s).

> Stef
>
> On Aug 9, 2008, at 9:15 PM, Eliot Miranda wrote:
>
>>
>>
>> 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...
>>  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
>>
>>
>>
>>
>>
>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list