KCP: Help with Vocabulary (Scott??)

Stephane Ducasse ducasse at iam.unibe.ch
Tue Apr 15 20:18:05 UTC 2003


Hi

I'm cleaning SystemDictionary and moving all the browse* methods from 
SystemDictionary to SystemNavigation (a new class).

Now I face the problem that vocabulary has the method 
newSystemVocabulary, and I could not find where/if the messages are 
activated. I imagine a perform somewhere but I could not find Smalltalk 
perform:....

I found the following Vocabulary class>>instanceWhoRespondsTo: aSelector
	"Find the most likely class that responds to aSelector.  Return an 
instance of it.  Look in vocabularies to match the selector."

This method seems to have a clever logic, so is the following 
assumption (that it will detect automatically that I moved the method 
from one class to another one) correct?

Stef

Vocabulary class>>instanceWhoRespondsTo: aSelector
	"Find the most likely class that responds to aSelector.  Return an 
instance of it.  Look in vocabularies to match the selector."

"Most eToy selectors are for Players"
	| mthRefs |
	((self vocabularyNamed: #eToy) includesSelector: aSelector) ifTrue: [
			aSelector == #+ ifFalse: [^ Player new costume: Morph new]].

	"Numbers are a problem"
	((self vocabularyNamed: #Number) includesSelector: aSelector) ifTrue: [
			^ 1].	"Is a Float any different?"

	#("String Point Time Date") do: [:nn |
		 ((self vocabularyNamed: nn) includesSelector: aSelector) ifTrue: [
			"Ask Scott how to get a prototypical instance"
			^ (Smalltalk at: nn) new]].

	mthRefs _ Smalltalk allImplementorsOf: aSelector.	"every one who 
implements the selector"
	mthRefs sortBlock: [:a :b |
		(Smalltalk at: a classSymbol) allSuperclasses size <
			(Smalltalk at: b classSymbol) allSuperclasses size].
	mthRefs size > 0 ifTrue: [^ (Smalltalk at: mthRefs first classSymbol) 
new].

	^ Error new




newSystemVocabulary
	"Answer a Vocabulary object representing significant requests one can 
make to the Smalltalk object"

	| aVocabulary |
	aVocabulary _ self new.

	aVocabulary vocabularyName: #System.
	aVocabulary documentation: 'Useful messages you might want to send to 
Smallalk'.
	aVocabulary initializeFromTable:  #(
(aboutThisSystem none () none (basic queries) 'put up a message 
describing the system' unused)
(saveAsNewVersion none () none (services) 'advance to the next 
available image-version number and save the image under that new name' 
unused znak)
(datedVersion none () String (queries) 'the version of the Squeak 
system')
(endianness none () String (queries) 'big or little - the byte-ordering 
of the hardware Squeak is currently running on')
(exitToDebugger none () none (dangerous) 'exits to the host debugger.  
Do not use this -- I guarantee you will be sorry.')
(bytesLeft none () Number (basic services) 'perform a garbage 
collection and answer the number of bytes of free space remaining in 
the system')
(browseAllCallsOn: none ((aSelector String)) none (#'queries') 'browse 
all calls on a selector')
(browseAllImplementorsOf: none ((aSelector String)) none (#'queries') 
'browse all implementors of a selector')

(allMethodsWithSourceString:matchCase: none ((aString String) 
(caseSensitive Boolean)) none (queries) 'browse all methods that have 
the given source string, making the search case-sensitive or not 
depending on the argument provided.')

(browseMethodsWithString:matchCase: none ((aString String) 
(caseSensitive Boolean)) none (queries) 'browse all methods that 
contain the given string in any string literal, making the search 
case-sensitive or not depending on the argument provided.')

(browseAllImplementorsOf:localTo: none ((aSelector String) (aClass 
Class)) none (#'queries') 'browse all implementors of a selector that 
are local to a class')

).
"(isKindOf: none 	((aClass Class)) Boolean (#'class membership') 
'answer whether the receiver''s superclass chain includes aClass')"
	^ aVocabulary

"Vocabulary initialize"
"Vocabulary addStandardVocabulary: Vocabulary newSystemVocabulary"

"Smalltalk basicInspect"
"Smalltalk beViewed"










More information about the Squeak-dev mailing list