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

Re: [Xotcl] Incorrect behavior?

From: Victor Mayevski <vitick_at_gmail.com>
Date: Wed, 29 Jun 2011 10:52:03 -0700

In my code I have objects that need some attributes only sometimes.
So, that was my attempt to reduce the code and not have to test for
the existence of that attribute but just re-create it. In this case, I
ended up just having that attribute permanently in all objects at all
times. It is not that I didn't have any other way of doing it, it is
just that I thought it would have been an elegant and short way of
doing it.


Here is another curious code that could be a bug, at least it doesn't
seem to behave as expected:

% Object create o
::o
% o attribute {a oldvalue}
::o::a
% o a
oldvalue
% o delete attribute a
% o a
::o: unable to dispatch method 'a'
% o attribute {a newvalue}
::o::a
% o a
oldvalue



Also, is it possible for "object delete attribute a" to not complain
if the attribute does not exist, may be via "-nocomplain" switch or
just by default?

Thanks,

Victor


On Wed, Jun 29, 2011 at 3:51 AM, Stefan Sobernig
<stefan.sobernig_at_wu.ac.at> wrote:
> Victor,
>
>>> %Object create o
>>> ::o
>>> %o attribute {a oldvalue}
>>> ::o::a
>>> %o a
>>> oldvalue
>>> %o attribute {a newvalue}
>>> ::o::a
>>> %o a
>>> oldvalue
>
> Forgot to ask: Why do you take this path (changing the default of the
> attribute slot) in the first place? If you want "a" to have the value
> "newvalue" assigned, why don't you simply say:
>
> o a newvalue
>
> //s
>
>
>