Retrieving class type
Torsten Anders
torstenanders at gmx.de
Sun Apr 8 18:14:38 CEST 2007
On 08.04.2007, at 13:29, Torsten Anders wrote:
> BTW: has anyone an idea whether/how it is possible to access the
> default init method of a class
That is for the class
class Example meth init(foo:Foo<=bar) skip end end
some procedure/method given Example or Example instance returning
init(foo:bar)
Best,
Torsten
> On 08.04.2007, at 09:17, Torsten Anders wrote:
>> Dear Chris,
>>
>> I recently found some way in the sources of the Inspector using some
>> seemingly undocumented functor 'x-oz://boot/Object'. There are also
>> ways to get all attributes, or methods of a class (see class
>> Reflection below).
>>
>> BTW: This class makes use of a function Boot_Name.newUnique, which
>> allows to "recreate" a name given an atom. I find it very handy to
>> have this for the reflection class below. But does this procedure
>> not impair the security intended to provide with names?
>>
>> Best,
>> Torsten
>>
>> %%%%%%%%%%%%%%%%%
>> %%
>> %% Retrieving class type
>> %%
>>
>> [Boot_Object] = {Module.link ['x-oz://boot/Object']}
>> class Example meth init() skip end end
>> X = {New Example init()}
>>
>> {Boot_Object.getClass X}
>>
>> %%%%%%%%%%%%%%%%%
>> %%
>> %% Reflection class
>> %%
>>
>> [Boot_Object Boot_Name] = {Module.link ['x-oz://boot/Object'
>> 'x-oz://boot/Name']}
>>
>> /** %% [abstract class] Defines reflection capabilities for
>> objects. Please note: this class uses undocumented Oz features, which
>> are possibly not intended for end users ;-)
>> %% */
>> class Reflection
>> meth getClass($)
>> {Boot_Object.getClass self}
>> end
>>
>> /** %% Returns the print name of the class of self as specified
>> in its definition. The name is an atom derived from a variable and
>> thus starting with a capital letter, e.g., 'ScoreObject'.
>> %% */
>> meth getClassName($)
>> {self getClass($)}.{Boot_Name.newUnique 'ooPrintName'}
>> end
>>
>> /** %% Returns a list of all attributes (atoms) defined for
>> self.
>> %% */
>> meth getAttrNames($)
>> {Arity {self getClass($)}.{Boot_Name.newUnique 'ooAttr'}}
>> end
>> /** %% Alias for getAttrNames.
>> %% */
>> meth getAttributes($) {self getAttrNames($)} end
>> /** %% Returns a record where the features are the attributes
>> defined for self and the values are the classes which define these
>> attributes.
>> %% */
>> meth getAttrSources($)
>> {Dictionary.toRecord {self getClassName($)}
>> {self getClass($)}.{Boot_Name.newUnique 'ooAttrSrc'}}
>> end
>> /** %% Returns a list of all features (atoms) defined for self.
>> %% */
>> meth getFeatNames($)
>> {Arity {self getClass($)}.{Boot_Name.newUnique 'ooFeat'}}
>> end
>> /** %% Alias for getFeatNames.
>> %% */
>> meth getFeatures($) {self getFeatNames($)} end
>> /** %% Returns a record where the features are the features
>> defined for self and the values are the classes which define these
>> features.
>> %% */
>> meth getFeatSources($)
>> {Dictionary.toRecord {self getClassName($)}
>> {self getClass($)}.{Boot_Name.newUnique 'ooFeatSrc'}}
>> end
>> /** %% Returns a list of all methods (atoms) defined for self.
>> %% */
>> meth getMethNames($)
>> {Dictionary.keys {self getClass($)}.{Boot_Name.newUnique 'ooMeth'}}
>> end
>> /** %% Alias for getMethNames.
>> %% */
>> meth getMethods($) {self getMethNames($)} end
>> /* %% [TODO] Get the default arguments of the initialisation
>> method...
>> %% */
>> % meth getInitArgs($)
>> % end
>> /** %% Returns a record where the features are the methods
>> defined for self and the values are the classes which define these
>> methods.
>> %% */
>> meth getMethSources($)
>> {Dictionary.toRecord {self getClassName($)}
>> {self getClass($)}.{Boot_Name.newUnique 'ooMethSrc'}}
>> end
>>
>> /** %% Returns the value at attribute A.
>> %% */
>> meth getAttr($ A) @A end
>> /** %% Returns the value at feature F.
>> %% */
>> meth getFeat($ F) self.F end
>>
>> end
>>
>>
>>
>> On 08.04.2007, at 05:50, Chris Rathman wrote:
>>> Is there a way to get the class type of a variable? For example, if
>>> I have a class like:
>>>
>>> class Example meth init() skip end end
>>>
>>> X = {New Example init()}
>>>
>>> is there a method along the lines of:
>>>
>>> % {Browse {X.getType()}}
>>>
>>> Thanks,
>>> Chris Rathman
>>>
>>> _____________________________________________________________________
>>> ____________
>>> mozart-users mailing list
>>> mozart-users at mozart-oz.org
>>> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>>>
>>>
>> --
>> Torsten Anders
>> Sonic Arts Research Centre • Queen's University Belfast
>> Frankstr. 49 • D-50996 Köln
>> Tel: +49-221-3980750
>> http://strasheela.sourceforge.net
>> http://www.torsten-anders.de
>>
>> ______________________________________________________________________
>> ___________
>> mozart-users mailing list
>> mozart-users at mozart-oz.org
>> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>>
>>
> --
> Torsten Anders
> Sonic Arts Research Centre • Queen's University Belfast
> Frankstr. 49 • D-50996 Köln
> Tel: +49-221-3980750
> http://strasheela.sourceforge.net
> http://www.torsten-anders.de
>
> _______________________________________________________________________
> __________
> mozart-users mailing list
> mozart-users at mozart-oz.org
> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>
>
--
Torsten Anders
Sonic Arts Research Centre • Queen's University Belfast
Frankstr. 49 • D-50996 Köln
Tel: +49-221-3980750
http://strasheela.sourceforge.net
http://www.torsten-anders.de
More information about the mozart-users
mailing list