No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] nx question
From: Stefan Sobernig <stefan.sobernig_at_wu.ac.at>
Date: Wed, 28 Mar 2012 18:08:43 +0200
René,
> A property can be set at creation time with
> <class> create<object> -property value
> and later get with
> <object> property
> and set with
> <object> property value
>
> What was the reason not to use -property
> as method name of the accessor function?
A straight forward (though not exhaustive) answer is that the dash
prefix ("-") is being used for non-positional parameters in the NX
concrete syntax (object and method parameters). While this is not a
barrier to using the dash as a general prefix to getter/setter names (or
method names in general), it might produce some distortion.
More importantly, yet less visible, dashed arguments to object
dispatches (i.e., Tcl commands representing NX objects) do carry meaning
which might lead to conflicts: A point in case are the special-purpose
"-system" and "-local" arguments which can be used in self-dispatches,
for example:
package req nx::test
Object create o {
# ! gives a warning !
:public method -local args {
return 1
}
:private method bar args {
return 0
}
:public method foo {} {
# ! subtle differences !
return [:-local bar]-[: -local bar]
}
}
? {o foo} 1-0
This example will give you a warning (NX checks for dash-prefixed names
at critical places) and demonstrates one of the subtle differences one
runs into when using "-" beyond what is backed into NX (for good
reasons, though).
Along these lines, NX won't allow the following custom-made fix of yours:
Object create o {
:property {-local 1}
}
-> invalid setter name "-local" (must not start with a dash or colon)
To summarise: While not carved in stone, the "-" (as the colon ":") has
some preserved, internal meaning at some places in NX, in particular for
argument processing.
> The -property notation seems IMO better
> and does not interfere with normal method
> names of an object.
The issue of using dashed or undashed names, however, does not really
address your concern of bloating an object's method interface.
There is a slightly more flexible API available to you for fine-tuning
properties: You may specify properties with/without auto-generated
setter/getter methods AND/OR with/without object parameters (to use a
-<propertyName> in new or create calls), i.e., the use of "variable" and
its "-config" and "-accessor" flags:
Class create C {
:variable x 1
:public method X {} {
return [incr :x -1]
}
:variable -config y
:variable -config -accessor z; # "somewhat" equivalent to ":property z"
}
? {[C create ::c] X} 0; # "C new -x" (object parameter) not available!
? {[C create ::c] info lookup methods x} ""; # "[C new] x"
(accessor/mutator method) not available!
? {[C create ::c -y 2] y} "::c: unable to dispatch method 'y'"; # object
parameter available, accessor method missing
? {[C create ::c -z 3] z} 3; # both in place!
> It is like the option
> notation in tk.
Indeed :)
Right now, there is no ready-made, builtin interface resembling Tk's
options (or fconfigure) in NX. However, it could be easily scripted if
needed.
Let me know if I can provide you further assistance, in whatever direction.
cheers
//stefan
>
>
> Regards,
> rene
> _______________________________________________
> Xotcl mailing list
> Xotcl_at_alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
>
Date: Wed, 28 Mar 2012 18:08:43 +0200
René,
> A property can be set at creation time with
> <class> create<object> -property value
> and later get with
> <object> property
> and set with
> <object> property value
>
> What was the reason not to use -property
> as method name of the accessor function?
A straight forward (though not exhaustive) answer is that the dash
prefix ("-") is being used for non-positional parameters in the NX
concrete syntax (object and method parameters). While this is not a
barrier to using the dash as a general prefix to getter/setter names (or
method names in general), it might produce some distortion.
More importantly, yet less visible, dashed arguments to object
dispatches (i.e., Tcl commands representing NX objects) do carry meaning
which might lead to conflicts: A point in case are the special-purpose
"-system" and "-local" arguments which can be used in self-dispatches,
for example:
package req nx::test
Object create o {
# ! gives a warning !
:public method -local args {
return 1
}
:private method bar args {
return 0
}
:public method foo {} {
# ! subtle differences !
return [:-local bar]-[: -local bar]
}
}
? {o foo} 1-0
This example will give you a warning (NX checks for dash-prefixed names
at critical places) and demonstrates one of the subtle differences one
runs into when using "-" beyond what is backed into NX (for good
reasons, though).
Along these lines, NX won't allow the following custom-made fix of yours:
Object create o {
:property {-local 1}
}
-> invalid setter name "-local" (must not start with a dash or colon)
To summarise: While not carved in stone, the "-" (as the colon ":") has
some preserved, internal meaning at some places in NX, in particular for
argument processing.
> The -property notation seems IMO better
> and does not interfere with normal method
> names of an object.
The issue of using dashed or undashed names, however, does not really
address your concern of bloating an object's method interface.
There is a slightly more flexible API available to you for fine-tuning
properties: You may specify properties with/without auto-generated
setter/getter methods AND/OR with/without object parameters (to use a
-<propertyName> in new or create calls), i.e., the use of "variable" and
its "-config" and "-accessor" flags:
Class create C {
:variable x 1
:public method X {} {
return [incr :x -1]
}
:variable -config y
:variable -config -accessor z; # "somewhat" equivalent to ":property z"
}
? {[C create ::c] X} 0; # "C new -x" (object parameter) not available!
? {[C create ::c] info lookup methods x} ""; # "[C new] x"
(accessor/mutator method) not available!
? {[C create ::c -y 2] y} "::c: unable to dispatch method 'y'"; # object
parameter available, accessor method missing
? {[C create ::c -z 3] z} 3; # both in place!
> It is like the option
> notation in tk.
Indeed :)
Right now, there is no ready-made, builtin interface resembling Tk's
options (or fconfigure) in NX. However, it could be easily scripted if
needed.
Let me know if I can provide you further assistance, in whatever direction.
cheers
//stefan
>
>
> Regards,
> rene
> _______________________________________________
> Xotcl mailing list
> Xotcl_at_alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
>
-- Institute for Information Systems and New Media Vienna University of Economics and Business Augasse 2-6, A-1090 Vienna `- http://nm.wu.ac.at/en/sobernig `- stefan.sobernig_at_wu.ac.at `- ss_at_thinkersfoot.net `- +43-1-31336-4878 [phone] `- +43-1-31336-746 [fax]