[BUG]UndefinedObject(Object)>>error:

Avi Bryant avi at beta4.com
Tue Oct 14 08:46:19 UTC 2003


Arjen van Elteren wrote:

>PS I was suprised that you could shadow globals in class vars in smalltalk
>(Peter showed me this a couple of weeks ago) but it is a very powerful
>function! Now I can use a class as it's own namespace (and define my own
>ordered collection if I want, and this is portable (unlike VW namespaces
>or squeak environments or STX namespaces).
>
This inspired me to hack out the attached Namespace class.  This is pure 
silliness, and I don't propose that anyone actually use it, but here's 
what it does:

Namespace subclass: #Foo
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Namespace-Test'.

Object subclass: #FooBar
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: 'Foo '
    category: 'Namespace-Test'.

Object subclass: #FooBaz
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: 'Foo '
    category: 'Namespace-Test'.

FooBaz compile: 'bar ^ Bar'.

FooBaz new bar == FooBar.  "true"

That is, it lets you used prefixed class names without the prefix, by 
including an appropiately named Namespace subclass as a poolDict.

With a suitable implementation of Namespace, this technique is probably 
even fairly portable...
-------------- next part --------------
'From Squeak3.6gamma of ''11 September 2003'' [latest update: #5421] on 14 October 2003 at 1:39:40 am'!
Object subclass: #Namespace
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'System-Pools'!

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Namespace class
	instanceVariableNames: ''!

!Namespace class methodsFor: 'as yet unclassified' stamp: 'avi 10/14/2003 01:34'!
bindingOf: aString
	^ (Smalltalk bindingOf: (self prefix, aString) asSymbol) ifNil: [super bindingOf: aString] ! !

!Namespace class methodsFor: 'as yet unclassified' stamp: 'avi 10/14/2003 01:37'!
bindingsDo: aBlock
	^ Smalltalk bindingsDo:
		[:assoc |
		(assoc key beginsWith: self prefix) ifTrue:
			[aBlock value: (assoc key allButFirst: self prefix size) -> assoc value].
		aBlock value: assoc]! !

!Namespace class methodsFor: 'as yet unclassified' stamp: 'avi 10/14/2003 01:35'!
includesKey: aName
	^(self bindingOf: aName) notNil! !

!Namespace class methodsFor: 'as yet unclassified' stamp: 'avi 10/14/2003 01:37'!
keysDo: aBlock
	^ Smalltalk keysDo:
		[:ea |
		(ea beginsWith: self prefix) ifTrue:
			[aBlock value: (ea allButFirst: self prefix size)].
		aBlock value: ea]! !

!Namespace class methodsFor: 'as yet unclassified' stamp: 'avi 10/14/2003 01:33'!
prefix
	^ self name! !


More information about the Squeak-dev mailing list