Path: news.daimi.aau.dk!olevi From: olevi@daimi.aau.dk (Ole Villumsen) Newsgroups: comp.lang.beta Subject: Re: Something like computed names in BETA ? Date: 18 Nov 1994 11:31:18 GMT Organization: DAIMI, Computer Science Dept. at Aarhus University Lines: 79 Message-ID: <3ai3a6$mu0@belfort.daimi.aau.dk> References: <39tqrf$q5m@poseidon.uni-paderborn.de> NNTP-Posting-Host: angers.daimi.aau.dk Allow me to ask back: Why do you ask? Oliver Geisser asks 2 questions. In my mind, they are clearly interrelated: >Can you do something like this in BETA: > Reference.(ComputedName) >I don't think it works this way, but you might get the >idea want I want ! ... >Another question is: Can I determine at runtime which >methods an object understands ? Are you asking - because you need it, and if so, what for? - or just for the academic exercise or out of curiosity? - or ... ? It can generally be determined already at *compile-time* which methods an object understands. I have a hard time coming up with a good example of why you would want more; not that I doubt one could be found. For a simple solution (quite different from Erik and Soeren's), I might come up with: understandsComputedNames: (# bindings: @ ... ; (* private list of (name,pattern) where the name (type text) is the name of the method stored in the pattern variable *) execNamedMethod: (# n: ^text; method: ##object; enter n[] do (if n[] -> bindings.has then n[] -> bindings.lookup -> method##; &method; else messageNotUnderstoodException; if); #); namesIUnderstand: (# (* return a list of method names i 'bindings' *) #) messageNotUnderstoodException:< exception (# ... #); #); myClass: understandsComputedNames (# method1: ... ; method2: ... ; init:< (# do ('method1', method1##) -> bindings.insert; ('method2', method2##) -> bindings.insert; ('method2_alias', method2##) -> bindings.insert; inner; #); #); The above could be used like: (# myObj: @myClass; myMethodName: @text; do myObj.init; 'method1' -> myObj.execNamedMethod; ... myMethodName[] -> myObj.execNamedMethod; #); The above is of course limited in that - no provision for parameters to methods is given - attributes that are not methods cannot be accessed via computed names - it cannot be used with classes which are not subclasses of understandsComputedNames. Ole Ole Villumsen, Computer Science Department, Aarhus University, Denmark