About at: and basicAt difference

ducasse ducasse at iam.unibe.ch
Sun Jan 13 17:18:00 UTC 2002


Thanks lex for your time,

I should have said that I knew that.

My point was that the text following the primitives is different in
Object>>at: and Object>>basicAt: while they both call the same primitive.
 
> It's a convention that methods named #basicFoo are never overriden;
> thus, you can access low-level functionality on any object by using the
> #basicFoo version of a method.  Usually you want to use #foo instead of
> #basicFoo, so that the receiving object can decide for itself how to
> respond -- in fact this is at the heart of objects!  Nevertheless,
> sometimes you want to ask for the low-level functionality explicitly,
> instead of letting the object do something intelligent.  (Like when my
> undergrad college told us to install such and such a Windows DLL to
> access their network, even though it was a generic TCP/IP network that
> any computer can use.  If they'd just ask, instead of trying to get
> their hands on our computers....)   As one quick example, sometimes an
> implementation of #at: will find #basicAt: to be useful.
> 
> 
> It is interesting, in Squeak, to look at implementors-of basicAt:
> (there's only one!) and at: (lots!), and then to look at senders-of each
> of these messages, to see how the methods are used.
> 
> 
> -Lex
> 
> 
> 
>> Which one is in sync with the primitive 60
>> 
>> Object>>at: index
>> "Primitive. Assumes receiver is indexable. Answer the value of an
>> indexable element in the receiver. Fail if the argument index is not an
>> Integer or is out of bounds. Essential. See Object documentation
>> whatIsAPrimitive."
>> 
>> <primitive: 60>
>> index isInteger ifTrue:
>> [self class isVariable
>> ifTrue: [self errorSubscriptBounds: index]
>> ifFalse: [self error: (self class name) , 's are not
>> indexable']].
>> index isNumber
>> ifTrue: [^self at: index asInteger]
>> ifFalse: [self errorNonIntegerIndex]
>> 
>> 
>> Object>>basicAt: index
>> "Primitive. Assumes receiver is indexable. Answer the value of an
>> indexable element in the receiver. Fail if the argument index is not an
>> Integer or is out of bounds. Essential. Do not override in a subclass.
>> See 
>> Object documentation whatIsAPrimitive."
>> 
>> <primitive: 60>
>> index isInteger ifTrue: [self errorSubscriptBounds: index].
>> index isNumber
>> ifTrue: [^self basicAt: index asInteger]
>> ifFalse: [self errorNonIntegerIndex]
> 
> 





More information about the Squeak-dev mailing list