Index: doc/Object.man =================================================================== diff -u -r84277b252f25481e4c5966f35729869a1d337a83 -r0ca02a312689097d793de942440e7fbecfebae72 --- doc/Object.man (.../Object.man) (revision 84277b252f25481e4c5966f35729869a1d337a83) +++ doc/Object.man (.../Object.man) (revision 0ca02a312689097d793de942440e7fbecfebae72) @@ -447,6 +447,21 @@ returned class will be different from the [cmd nx::Class] from which [arg obj] was originally instantiated using [method create] or [method new]. + +[call [arg obj] [method {info consts}] [opt [arg pattern]]] + +Returns a list of unmodifiable Tcl variable names created and defined +for the scope of [arg obj], i.e., object variables. The command is +very similar to the [method {info vars}] method, +but returns variables defined with the Tcl command [cmd const] only. +Like for [method {info vars}] rhe result list +can be filtered via the [arg pattern] argument. The [arg pattern] +string can contain special string matching characters +(see [cmd "string match"]). Since the Tcl command [cmd const] was introduced via TIP 677 +(June 23) to Tcl9, the command returns for earlier versions of Tcl the +empty list. + + [call [arg obj] [method "info has"] [opt "[method mixin] | [method namespace] | [method type]"] [opt "[arg arg] ..."]] [list_begin definitions] @@ -610,11 +625,14 @@ [call [arg obj] [method {info vars}] [opt [arg pattern]]] -Yields a list of Tcl variable names created and defined for the scope of -[arg obj], i.e., object variables. The list can be limited to object variables whose names -match [arg pattern]. The [arg pattern] string can contain special -matching characters (see [cmd "string match"]). +Returns a list of Tcl variable names created and defined for the scope +of [arg obj], i.e., object variables. The result list can be filtered +via the [arg pattern] argument. The [arg pattern] string can contain +special string matching characters (see [cmd "string match"]). + + + [list_end] [comment { Index: library/nx/nx.tcl =================================================================== diff -u -r3dcb0fb1b41f33a5b163ae81b96e6a20e75c9d81 -r0ca02a312689097d793de942440e7fbecfebae72 --- library/nx/nx.tcl (.../nx.tcl) (revision 3dcb0fb1b41f33a5b163ae81b96e6a20e75c9d81) +++ library/nx/nx.tcl (.../nx.tcl) (revision 0ca02a312689097d793de942440e7fbecfebae72) @@ -802,6 +802,16 @@ :alias "info parent" ::nsf::methods::object::info::parent :alias "info precedence" ::nsf::methods::object::info::precedence :alias "info vars" ::nsf::methods::object::info::vars + if {$::tcl_version > 8} { + :method "info consts" {{pattern ""}} { + lmap v [:info vars {*}$pattern] { + if {![::info constant :$v]} continue + set v + } + } + } else { + :method "info consts" {{pattern ""}} { return {} } + } :method "info variable definition" {handle:object,type=::nx::VariableSlot} { return [$handle definition] } Index: tests/class-method.test =================================================================== diff -u -r40b842e5b218cc6144506ff4689671b780c4e8c5 -r0ca02a312689097d793de942440e7fbecfebae72 --- tests/class-method.test (.../class-method.test) (revision 40b842e5b218cc6144506ff4689671b780c4e8c5) +++ tests/class-method.test (.../class-method.test) (revision 0ca02a312689097d793de942440e7fbecfebae72) @@ -20,7 +20,7 @@ ? {lsort [::C info object methods]} "f" ? {lsort [::C info]} \ - "valid submethods of ::C info: baseclass children class filters has heritage info instances lookup method methods mixinof mixins name object parent precedence slots subclasses superclasses variable variables vars" + "valid submethods of ::C info: baseclass children class consts filters has heritage info instances lookup method methods mixinof mixins name object parent precedence slots subclasses superclasses variable variables vars" } # @@ -79,7 +79,7 @@ ? {lsort [::C info object methods]} "a f foo fwd p v2" ? {lsort [::C info]} \ - "valid submethods of ::C info: baseclass children class filters has heritage info instances lookup method methods mixinof mixins name object parent precedence slots subclasses superclasses variable variables vars" + "valid submethods of ::C info: baseclass children class consts filters has heritage info instances lookup method methods mixinof mixins name object parent precedence slots subclasses superclasses variable variables vars" } # Index: tests/method-parameter.test =================================================================== diff -u -r9e281d5110f397a9e9b8317325d0675f1793246d -r0ca02a312689097d793de942440e7fbecfebae72 --- tests/method-parameter.test (.../method-parameter.test) (revision 9e281d5110f397a9e9b8317325d0675f1793246d) +++ tests/method-parameter.test (.../method-parameter.test) (revision 0ca02a312689097d793de942440e7fbecfebae72) @@ -111,9 +111,9 @@ nx::Class create C if {[::nsf::pkgconfig get development]} { - set info {info baseclass, info children, info class, info filters, info has mixin, info has namespace, info has type, info heritage, info info, info instances, info lookup filter, info lookup filters, info lookup method, info lookup methods, info lookup mixins, info lookup parameters, info lookup slots, info lookup syntax, info lookup variables, info method args, info method body, info method callprotection, info method debug, info method definition, info method definitionhandle, info method deprecated, info method disassemble, info method exists, info method handle, info method origin, info method parameters, info method registrationhandle, info method returns, info method submethods, info method syntax, info method type, info methods, info mixinof, info mixins, info name, info object filters, info object method args, info object method body, info object method callprotection, info object method debug, info object method definition, info object method definitionhandle, info object method deprecated, info object method disassemble, info object method exists, info object method handle, info object method origin, info object method parameters, info object method registrationhandle, info object method returns, info object method submethods, info object method syntax, info object method type, info object methods, info object mixins, info object slots, info object variables, info parent, info precedence, info slots, info subclasses, info superclasses, info variable definition, info variable name, info variable parameter, info variables, info vars} + set info {info baseclass, info children, info class, info consts, info filters, info has mixin, info has namespace, info has type, info heritage, info info, info instances, info lookup filter, info lookup filters, info lookup method, info lookup methods, info lookup mixins, info lookup parameters, info lookup slots, info lookup syntax, info lookup variables, info method args, info method body, info method callprotection, info method debug, info method definition, info method definitionhandle, info method deprecated, info method disassemble, info method exists, info method handle, info method origin, info method parameters, info method registrationhandle, info method returns, info method submethods, info method syntax, info method type, info methods, info mixinof, info mixins, info name, info object filters, info object method args, info object method body, info object method callprotection, info object method debug, info object method definition, info object method definitionhandle, info object method deprecated, info object method disassemble, info object method exists, info object method handle, info object method origin, info object method parameters, info object method registrationhandle, info object method returns, info object method submethods, info object method syntax, info object method type, info object methods, info object mixins, info object slots, info object variables, info parent, info precedence, info slots, info subclasses, info superclasses, info variable definition, info variable name, info variable parameter, info variables, info vars} } else { - set info {info baseclass, info children, info class, info filters, info has mixin, info has namespace, info has type, info heritage, info info, info instances, info lookup filter, info lookup filters, info lookup method, info lookup methods, info lookup mixins, info lookup parameters, info lookup slots, info lookup syntax, info lookup variables, info method args, info method body, info method callprotection, info method debug, info method definition, info method definitionhandle, info method deprecated, info method exists, info method handle, info method origin, info method parameters, info method registrationhandle, info method returns, info method submethods, info method syntax, info method type, info methods, info mixinof, info mixins, info name, info object filters, info object method args, info object method body, info object method callprotection, info object method debug, info object method definition, info object method definitionhandle, info object method deprecated, info object method exists, info object method handle, info object method origin, info object method parameters, info object method registrationhandle, info object method returns, info object method submethods, info object method syntax, info object method type, info object methods, info object mixins, info object slots, info object variables, info parent, info precedence, info slots, info subclasses, info superclasses, info variable definition, info variable name, info variable parameter, info variables, info vars} + set info {info baseclass, info children, info class, info consts, info filters, info has mixin, info has namespace, info has type, info heritage, info info, info instances, info lookup filter, info lookup filters, info lookup method, info lookup methods, info lookup mixins, info lookup parameters, info lookup slots, info lookup syntax, info lookup variables, info method args, info method body, info method callprotection, info method debug, info method definition, info method definitionhandle, info method deprecated, info method exists, info method handle, info method origin, info method parameters, info method registrationhandle, info method returns, info method submethods, info method syntax, info method type, info methods, info mixinof, info mixins, info name, info object filters, info object method args, info object method body, info object method callprotection, info object method debug, info object method definition, info object method definitionhandle, info object method deprecated, info object method exists, info object method handle, info object method origin, info object method parameters, info object method registrationhandle, info object method returns, info object method submethods, info object method syntax, info object method type, info object methods, info object mixins, info object slots, info object variables, info parent, info precedence, info slots, info subclasses, info superclasses, info variable definition, info variable name, info variable parameter, info variables, info vars} } Index: tests/plain-object-method.test =================================================================== diff -u -r40b842e5b218cc6144506ff4689671b780c4e8c5 -r0ca02a312689097d793de942440e7fbecfebae72 --- tests/plain-object-method.test (.../plain-object-method.test) (revision 40b842e5b218cc6144506ff4689671b780c4e8c5) +++ tests/plain-object-method.test (.../plain-object-method.test) (revision 0ca02a312689097d793de942440e7fbecfebae72) @@ -14,7 +14,7 @@ ? {o filters set f} "::o: unable to dispatch method 'filters'" ? {lsort [o info object methods]} "f" - ? {lsort [o info]} "valid submethods of ::o info: baseclass children class has info lookup name object parent precedence variable vars" + ? {lsort [o info]} "valid submethods of ::o info: baseclass children class consts has info lookup name object parent precedence variable vars" } # @@ -63,7 +63,7 @@ ? {o info filters} "" ? {lsort [o info object methods]} "a f foo fwd p v2" - ? {lsort [o info]} "valid submethods of ::o info: baseclass children class filters has info lookup method methods mixins name object parent precedence slots variable variables vars" + ? {lsort [o info]} "valid submethods of ::o info: baseclass children class consts filters has info lookup method methods mixins name object parent precedence slots variable variables vars" } # Index: tests/submethods.test =================================================================== diff -u -r43373d98ca07d446abec8f8f62af7c4df56207a3 -r0ca02a312689097d793de942440e7fbecfebae72 --- tests/submethods.test (.../submethods.test) (revision 43373d98ca07d446abec8f8f62af7c4df56207a3) +++ tests/submethods.test (.../submethods.test) (revision 0ca02a312689097d793de942440e7fbecfebae72) @@ -243,7 +243,7 @@ # defaultcmd has to return also subcmds of other shadowed ensembles ? {lsort [o1 info has]} "valid submethods of ::o1 info has: mixin namespace something type" ? {lsort [o1 info]} \ - "valid submethods of ::o1 info: baseclass children class has info lookup name object parent precedence variable vars" + "valid submethods of ::o1 info: baseclass children class consts has info lookup name object parent precedence variable vars" # returning methodpath in ensemble ? {o1 info has something path} "info has something path" Index: tests/var-access.test =================================================================== diff -u -r8e2e356e9bcef39f43dfe3690b82d9586c7adc72 -r0ca02a312689097d793de942440e7fbecfebae72 --- tests/var-access.test (.../var-access.test) (revision 8e2e356e9bcef39f43dfe3690b82d9586c7adc72) +++ tests/var-access.test (.../var-access.test) (revision 0ca02a312689097d793de942440e7fbecfebae72) @@ -8,22 +8,22 @@ namespace eval ::nx::var1 { namespace ensemble create -map { - exists ::nsf::var::exists - import ::nsf::var::import + exists ::nsf::var::exists + import ::nsf::var::import set ::nsf::var::set } } ::nx::Object create ::nx::var2 { - :object alias exists ::nsf::var::exists + :object alias exists ::nsf::var::exists :object alias import ::nsf::var::import :object alias set ::nsf::var::set } nx::test case set+array { nx::Object create o1 - + # first set a scalar variable ? {nsf::var::set o1 x 100} "100" ? {nsf::var::set o1 x} "100" @@ -39,7 +39,7 @@ # "x" is a variable, but not an array ? {nsf::var::exists o1 x} 1 ? {nsf::var::exists -array o1 x} 0 - + # "a" is a variable and an array ? {nsf::var::exists -array o1 a} 1 ? {nsf::var::exists o1 a} 1 @@ -90,7 +90,7 @@ incr x } } - + ? {::nsf::var::set o x} 1 ? {::nsf::var::exists o x} 1 ? {::nsf::var::exists o y} 0 @@ -118,7 +118,50 @@ ? {::nsf::var::set o x} 40005 } +# +# "const" was introduced into Tcl9 via TIP 677 (June 23) +# +if {[package vsatisfies [package req Tcl] 9.0-]} { + nx::test configure -count 10000 + nx::test case consts { + nx::Object create o { + # + # Create a "const" instance variable + # + const :x 1 + # + # Create a classical (modifiable) instance variable + # + set :y 1 + const :x1 11 + # + # Access a "const" value as an instance variable + # from a method. + # + :object method access-const {} {return ${:x}} + # + # Try to modify a "const" value in a method + # + :object method modify-const {} {set :x 2} + + # + # Test "info constant" in the object scope + # + :object method info-constant {} {list [::info constant :x] [::info constant :y]} + } + + ? {o access-const} 1 + ? {o modify-const} {can't set ":x": variable is a constant} + ? {o info-constant} {1 0} + ? {lsort [o info vars]} {x x1 y} + ? {lsort [o info vars x*]} {x x1} + ? {lsort [o info consts]} {x x1} + ? {lsort [o info consts x*]} {x x1} + ? {lsort [o info consts x1]} {x1} + } +} + # # Local variables: # mode: tcl