[Xotcl] Default-value substitution using substdefault
Gustaf Neumann
neumann at wu.ac.at
Sat Aug 13 11:09:09 CEST 2022
Dear Maxim,
here the code for the old and new example with expected output.
-g
Original example:
============================================================
nx::Class create dzs {
:property {srv:substdefault {[ns_info server]}}
}
dzs create o1
nx::Class create dz -superclass dzs
dz create o2
lappend _ [o1 cget -srv] [o2 cget -srv]
# returns a list containing the name of the current server twice
============================================================
New example
============================================================
nx::Class create D
nx::Class create FOO {
:property {d:object,type=::D,substdefault {[::D new]}}
:create o3
}
set o [o3 cget -d]
$o info class
# returns ::D
============================================================
On 12.08.22 20:40, Maksym Zinchenko wrote:
> Dear Gustaf, sorry I've tried to remove the comma but it breaks the
> code completely.
> And I can't see minimal example also. I based my code on an example in
> the next-scripting tutorial (3.7.6. Defaults substitution):
>
> :property {d:object,type=::D,substdefault {[::Dnew]}}
>
>
>
> On Fri, Aug 12, 2022 at 4:00 PM Gustaf Neumann <neumann at wu.ac.at> wrote:
>
> Dear Maxsym,
>
> the comma after the variable name "srv" was not correct.
> We should provide an error message for that....
>
> See below for a minimal example showing the correct behavior.
>
> all the best
>
> -gustaf
>
> On 12.08.22 16:25, Maksym Zinchenko wrote:
> > Hello, I'm having trouble to define "srv" property in my
> superclass with
> > default value from Naviserver command, may be Im doing smth
> wrong, would be
> > so kind to help:
> >
> > nx::Class create dz_superclass {
> >> :property identifier
> >> :property {srv,substdefault=0b111: {[ns_info server]}}
> >> :method init {} {
> >> set :uuid ""
> >> if {[[current object] info vars identifier] eq ""} {
> >> set :identifier ""
> >> } else {
> >> if {[is_uuid ${:identifier}] == 1} {
> >> set :uuid ${:identifier}
> >> }
> >> }
> >> }
> >> }
> > nx::Class create dz_class -superclass dz_superclass {
> >> :method init {} {
> >> if {${:identifier} ne ""} {
> >> set :obj_data [dict getnull [select_all client *
> >> uuid_client=\'${:identifier}\'] 0]
> >> }
> >> }
> >> }
> >>
> > When I create object:
> >
> >> dz_class create o1 -identifier 67720c6d-d00f-479b-85cf-4edaa5a9cb1a
> >>
> > o1 cget -srv
> > Im getting literal "[ns_info server]" instead of my virtual
> server name
> >
> >
> >> [ns_info server]
> >>
> > Thank you
>
More information about the Xotcl
mailing list