No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] parameters vs slots and use of "-initcmd"
From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Wed, 04 Jul 2007 20:32:40 +0200
Thank you Atur for your introduction.
However, i have to add something at certain points:
Artur Trzewik schrieb:
> In early version of XOTcl perameter are just a clever shortcut for method
> Definition
> Class A -paramter a
>
> has leaded to method
>
> # setter and getter in one method
> # something like this
> A instproc a {args} {
> if {[llength $args]==0} {
> my set a
> } else {
> my set a [lindex $args 0]
> }
> }
this is only partially correct, since also in old xotcl versions
"parameters" were an abstraction to provide an accessor function
and to provide default values.
>
> It was pure XOTcl and also visible per info instbody.
> Now parameters are C-coded and probably faster.
the c-code provides an accessor function similar to the instproc
above (yes, it is about 7 times faster in C). The C-implemented
accessor function can be registered via "parametercmd"
(or "instparametercmd")
The accessor function above can be replaced by
A instparametercmd a
and can be used via
A create a1 -a 200
puts [a1 a]
The "parametercmd" (without "inst") is used similar to a proc,
it registers an accessor function for a single object.
Note, that slots are much more powerful than these kind of
parameters, since they are an abstraction
for providing much richter meta-data for attributes and can be used
for required/non-required attributes, type checking, multi-valued
attributes, database attributes, html information (labels, etc), providing
meta-data for remoting (e.g. soap calls), and many more.
> Parameters are only syntactic sugar but you do not need to use it.
In XOTcl version since 1.5.0, parameters are syntactic suguar
for simplified access to slots. In prior versions, they were only
syntactic sugar for providing default values and accessor functions.
Strictly speaking, an application programmer does not have
to use parameter in the application program, therefore Artur is right.
While the application program does not have to *define* slots,
it is hard to do something useful in xotcl without *using* slots
since methods like "superclass", "class", "mixin" etc.
are implemented as slots.
-gustaf neumann
Date: Wed, 04 Jul 2007 20:32:40 +0200
Thank you Atur for your introduction.
However, i have to add something at certain points:
Artur Trzewik schrieb:
> In early version of XOTcl perameter are just a clever shortcut for method
> Definition
> Class A -paramter a
>
> has leaded to method
>
> # setter and getter in one method
> # something like this
> A instproc a {args} {
> if {[llength $args]==0} {
> my set a
> } else {
> my set a [lindex $args 0]
> }
> }
this is only partially correct, since also in old xotcl versions
"parameters" were an abstraction to provide an accessor function
and to provide default values.
>
> It was pure XOTcl and also visible per info instbody.
> Now parameters are C-coded and probably faster.
the c-code provides an accessor function similar to the instproc
above (yes, it is about 7 times faster in C). The C-implemented
accessor function can be registered via "parametercmd"
(or "instparametercmd")
The accessor function above can be replaced by
A instparametercmd a
and can be used via
A create a1 -a 200
puts [a1 a]
The "parametercmd" (without "inst") is used similar to a proc,
it registers an accessor function for a single object.
Note, that slots are much more powerful than these kind of
parameters, since they are an abstraction
for providing much richter meta-data for attributes and can be used
for required/non-required attributes, type checking, multi-valued
attributes, database attributes, html information (labels, etc), providing
meta-data for remoting (e.g. soap calls), and many more.
> Parameters are only syntactic sugar but you do not need to use it.
In XOTcl version since 1.5.0, parameters are syntactic suguar
for simplified access to slots. In prior versions, they were only
syntactic sugar for providing default values and accessor functions.
Strictly speaking, an application programmer does not have
to use parameter in the application program, therefore Artur is right.
While the application program does not have to *define* slots,
it is hard to do something useful in xotcl without *using* slots
since methods like "superclass", "class", "mixin" etc.
are implemented as slots.
-gustaf neumann