No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] 'assign' method of properties not called on object initialization
From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Thu, 26 Jan 2012 13:54:46 +0100
Dear Arthur,
this is a known problem area, already on our todo list.
What you are defining is an user-defined, slot-specific
parameter type.
In nx, object parameters are closer to the general parameter
handling (e.g. method parameters) than to accessors. The
parameters provide a rich set of configuration options
(value checkers, multiplicity, requiredness, ...). NX comes
with several built-in checkers/converters, which can be
extended with user-defined (scripted) checkers (see [1]).
For value checkers, a developer can decide, for which kind
of parameter a checker should be applicable. When a
value-checker is defined on the class nx::Slot, then this
checker can be used for method parameters in the same way as
for object parameters (see [2]).
[1]
http://next-scripting.org/docs/2.0b2/doc/nx/tutorial/index1#_value_constraints
[2]
http://next-scripting.org/docs/2.0b2/doc/nx/tutorial/index1#_slot_classes_and_slot_objects
Your example can be defined with a scripted checker as shown
below.
======================================================
nx::Class create Foo {
:property bar {
:type "bar"
:method type=bar {name value} {
puts stderr "assign called for $name $value"
}
}
}
set foo [Foo new]
$foo bar "test"
Foo new -bar "test"
======================================================
The checker is called here - as expected - twice.
In the more general case below, the converter is defined on
nx::Slot, therefore applicable for every parameter (e.g. for
property "bar" and for the method "abrakadabra").
======================================================
nx::Slot public method type=baz {name value} {
puts stderr "assign called for $name $value"
}
nx::Class create Baz {
:property bar:baz
:public method abrakadabra {x:int y:baz,1..n} { return $x-$y }
}
set baz [Baz new]
$baz bar "test"
$baz abrakadabra 1 {a b c}
Baz new -bar "test"
======================================================
Since y of abrakadabra has defined the multiplicity 1..n,
the checker is called for every single value (in the snipped
above 5 times).
The new parameters are more powerful and general than the
xotcl-style "assign" method; so i tend to believe the latter
is obsolete. Some cleanup is here still necessary.
-gustaf neumann
On 26.01.12 12:06, Arthur Schreiber wrote:
> Hi everyone,
>
> When assigning an object's property using object parameters, the assign
> method of that property does not get called. Is that a bug or intended
> behaviour?
>
> See the following code:
>
> package require nx
>
> nx::Class create Foo {
> :property bar {
> :public method assign { object property value } {
> puts "assign called for: $object $property $value"
> }
> }
> }
>
> set foo [Foo new]
> $foo bar "test"; # assign method of the bar property is called
>
> Foo new -bar "test"; # assign method of the bar property is _not_ called
>
> Kind regards,
> Arthur
> _______________________________________________
> Xotcl mailing list
> Xotcl_at_alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
Date: Thu, 26 Jan 2012 13:54:46 +0100
Dear Arthur,
this is a known problem area, already on our todo list.
What you are defining is an user-defined, slot-specific
parameter type.
In nx, object parameters are closer to the general parameter
handling (e.g. method parameters) than to accessors. The
parameters provide a rich set of configuration options
(value checkers, multiplicity, requiredness, ...). NX comes
with several built-in checkers/converters, which can be
extended with user-defined (scripted) checkers (see [1]).
For value checkers, a developer can decide, for which kind
of parameter a checker should be applicable. When a
value-checker is defined on the class nx::Slot, then this
checker can be used for method parameters in the same way as
for object parameters (see [2]).
[1]
http://next-scripting.org/docs/2.0b2/doc/nx/tutorial/index1#_value_constraints
[2]
http://next-scripting.org/docs/2.0b2/doc/nx/tutorial/index1#_slot_classes_and_slot_objects
Your example can be defined with a scripted checker as shown
below.
======================================================
nx::Class create Foo {
:property bar {
:type "bar"
:method type=bar {name value} {
puts stderr "assign called for $name $value"
}
}
}
set foo [Foo new]
$foo bar "test"
Foo new -bar "test"
======================================================
The checker is called here - as expected - twice.
In the more general case below, the converter is defined on
nx::Slot, therefore applicable for every parameter (e.g. for
property "bar" and for the method "abrakadabra").
======================================================
nx::Slot public method type=baz {name value} {
puts stderr "assign called for $name $value"
}
nx::Class create Baz {
:property bar:baz
:public method abrakadabra {x:int y:baz,1..n} { return $x-$y }
}
set baz [Baz new]
$baz bar "test"
$baz abrakadabra 1 {a b c}
Baz new -bar "test"
======================================================
Since y of abrakadabra has defined the multiplicity 1..n,
the checker is called for every single value (in the snipped
above 5 times).
The new parameters are more powerful and general than the
xotcl-style "assign" method; so i tend to believe the latter
is obsolete. Some cleanup is here still necessary.
-gustaf neumann
On 26.01.12 12:06, Arthur Schreiber wrote:
> Hi everyone,
>
> When assigning an object's property using object parameters, the assign
> method of that property does not get called. Is that a bug or intended
> behaviour?
>
> See the following code:
>
> package require nx
>
> nx::Class create Foo {
> :property bar {
> :public method assign { object property value } {
> puts "assign called for: $object $property $value"
> }
> }
> }
>
> set foo [Foo new]
> $foo bar "test"; # assign method of the bar property is called
>
> Foo new -bar "test"; # assign method of the bar property is _not_ called
>
> Kind regards,
> Arthur
> _______________________________________________
> Xotcl mailing list
> Xotcl_at_alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl