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?
I think I understand what [:autoname ${:prefix}] is/does but what on earth is "[:]::[:autoname ${:prefix}]" ?
Jon
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. tests/method-require.test
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 invocation. See Listing 33 in http://www.next-scripting.org/docs/2.0b3/doc/nx/tutorial/index1#_method_reso... 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 object appended by "::" and an autonamed enity (using the variable "prefix" as a stem).
The method autoname is the same as http://media.wu.ac.at/doc/langRef-xotcl.html#Object-autoname
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 -gustaf