View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] Incorrect behavior?

From: Stefan Sobernig <stefan.sobernig_at_wu.ac.at>
Date: Wed, 29 Jun 2011 12:32:04 +0200

Victor,

> %Object create o
> ::o
> %o attribute {a oldvalue}
> ::o::a
> %o a
> oldvalue
> %o attribute {a newvalue}
> ::o::a
> %o a
> oldvalue

Incorrect behavior? Not quite, but probably behaviour not that
"accessible" at first sight :)

In line 5, by accessing a, the default value "oldvalue" is assigned to
am object variable a owned by ::o. In line 7, by providing a new default
value, you do not change the state of ::o (the value assignment of the
var a), rather you modify a property of the attribute slot a.

So, in line 9, given that an object variable a already exists, the slot
machinery does not (re-)assign the default value. You would have to
clear ::o's state first:

::o eval {unset :a}

and then do:

o attribute {a newvalue}
o a

Note that currently, for per-object attributes only, the unset *must*
happen before the re-definition of the attribute slot and its default.
There might be ways to relax this restriction at some point ...

//stefan