[Xotcl] Named objects

Gustaf Neumann neumann at wu.ac.at
Fri Aug 10 09:47:57 CEST 2012

On 10.08.12 03:39, Jonathan Kelly wrote:
> Hi,
> I'm trying to get my head into the "named object" space. I was looking
> at the container example for a way in and now I'm stuck (again).
> nx::Class create SimpleContainer {
>    :property {memberClass ::MyItem}
>    :property {prefix member}
>    # Require the method "autoname" for generating nice names
>    :require method autoname
>    # The method new is responsible for creating a child of the current
>    # container.
>    :public method new {args} {
>      set item [${:memberClass} create [:]::[:autoname ${:prefix}] {*}$args]
>    }
> }
> What does the ":require method autoname" do?
One can load the definition of single method via the 
"require method".
It is somewhat similar to traits, but brings in just a 
single method (might
be an alias, or a scripted defintion, etc.). See e.g. 

In this case, the predefined method "autoname" is registered 
as a method
of "SimpleContainer".

> I think I understand what [:autoname ${:prefix}] is/does but what on
> earth is "[:]::[:autoname ${:prefix}]" ?
The single colon ":"  is used to parameterize the method 
See Listing 33 in
When called without arguments, it returns the current object.

the line in question is unabbreviated

    "[self]::[[self] autoname ${:prefix}]"

and is after substitution a name consisting of the current 
appended by "::" and an autonamed enity (using the variable
"prefix" as a stem).

The method autoname is the same as

If one does not care about the names of the created subobjects,
one could use as well:

     SimpleContainer public method new {args} {
        ${:memberClass} new -childof [self] {*}$args

Hope this helps

More information about the Xotcl mailing list