[Xotcl] parameters vs slots and use of "-initcmd"

Nico L'INSALATA (UniPI) nicola.linsalata at iet.unipi.it
Tue Jul 3 16:48:44 CEST 2007

Hi everybody,
my name is Nico and I'm new to XOTcl.

After spending few weeks in understanding the basic concepts of the
language, I decided to use it to model one component of the software I'm
developing as part of my PhD project (basically, configuration of
complex digital hardware macrocells). I've been attracted by XOTcl due
to its "aspect oriented" features which are today very common in the
hardware design industry.

I need some clarifications regarding the use of Class parameters and
Class slots (I will refer to v.1.5.2 of the XOTcl tutorial).
Parameters are used throughout the introduction of the tutorial to model
Class attributes, then slots are introduced in a later section. Are
slots and parameters actually the same thing? Is there some reason to
prefer one over the other?

Anyway, I've started using slots and I got lost using the -initcmd feature.
This is a "simplified" version of the code that "doesn't work"  (i.e.
I'm not able to make it work :-) )

Class my_class \
-slots {
    Attribute one -type integer -default { 0 }
    Attribute two -type integer -default { 0 }
   Attribute three -type integer -initcmd {
       if { [my one] > [my two]} {
       set _ 100
      } else {
       set _ 101010

The code doesn't work (of course!!) since [self] within initcmd has
value "::my_class::slot::three". So, the question is: how do I refer to
other attributes of the same class from within -initcmd { }?

And secondarily, is it possible to associate -initcmd with an instproc
of the class in which the attribute is being defined? e.g. an instproc
of Class my_class

Note that, to ensure things work properly, when instances of my_class
are created both attributes "one" and "two" are initialized, while
attribute "three" will also be refereed in a subsequent part of the
script. This behavior is bizarre and potentially unsafe, but is dictated
by another software components  over which I have no control.

Thank you very much for your attention!


More information about the Xotcl mailing list