Itcl - the [incr Tcl] extension

View Ticket
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.
Ticket UUID: 050ac21f736d16ba51c1eb4de5ab3f3ce0982c84
Title: info variable introspection gap
Status: Open Type: Code_Defect
Severity: Critical Priority: Immediate
Subsystem: Resolution: Open
Last Modified: 2019-02-04 15:22:45
Version Found In:
User Comments:
dgp added on 2016-02-18 16:56:47:
> What is the [info variable] method failing to do?

It provides no access to the value of the variable.  The [info variable $var -value] only works for scalars.

% package require Itcl 3
3.4
% itcl::class C {
variable a
variable b
constructor {} {
    array set a {1 2}
    set b scalar
}
}
% C c
c
% c info variable
::C::this ::C::a ::C::b
% c info variable a -type
variable
% c info variable b -type
variable
% c info variable b -value
scalar
% c info variable a -value
<undefined>
% c info variable a(1) -value
"a(1)" isn't a variable in class "::C"

griffin added on 2016-02-18 17:03:00:
The other piece that's missing is way to compute that it is an array, a la [array exists $varName]

schmitzu added on 2018-05-09 09:59:43:
On clt I suggested a "-scope" option for "info variable" command
to gain acces to the variable. I've implemented it in itclInfo.c
and it works for me. I can supply a patch if desired. But, it's
far from beeing perfect. An expert has to review it, before it
can go into the code base.

dgp added on 2018-05-09 16:45:51:
Feel free to attach a patch here.

If you prefer to push onto a fossil branch, we can set you up
with the access to do that.

schmitzu added on 2018-05-15 11:47:04:
I've attached a patch for adding the -scope option to info variable.
The code ist copied from Itcl_ScopeCmd() and slightly modified
to work in the info environment. As written before, it's not perfect
and should only demonstrate a path to fix this ticket.
With this patch it isn't possible to get the scope of
single array variables, only the name of the whole array works.
Also I've done very few tests. If this is the way to go,
I'm willing to put more work in this solution.

I attach a little test script infoVariableScopeUsage.tcl which
demonstrates the usage of -scope option.

The output of my patched version of Itcl4.1.1:

Itcl=4.1.1
_baseV1    scope = ::itcl::internal::variables::oo::Obj15::Base::_baseV1
_baseArray scope = ::itcl::internal::variables::oo::Obj15::Base::_baseArray
_baseArray get   = two 2 one 1

dgp added on 2018-05-15 13:00:26:
Created a new branch bug-050ac21f72 out of the contributed patch
for later review.

Appears the branch doesn't build as is, but gives a good starting
point.

schmitzu added on 2018-05-16 13:40:59:
Sorry, the patch contained a little typo.
I've uploaded a new patch which hopefully
will work now.
Again, sorry for the inconvenience!

schmitzu added on 2018-10-16 14:12:04:
Don,

just saw that you are preparing a new release. Is there
any chance to get the proposed patch into this release?
Can I be of any help?
Thanks in advance.

dgp added on 2018-11-01 15:18:10:
The prod of a comment here helps, thanks.

I took the repaired patch and made a new bugfix branch.
Can confirm that it builds. Only testing issues are those
caused by expected changes in error messages.

Since this is a new feature and not just a bug fix, I'll
ask for some other opinions on it. Given that, it won't
go into the 4.1.2 release, but with positive opinions could
go into the next 4.2 release. We don't need a full TIP system
to develop Itcl, I don't think, but wise comments from multiple
users would help me have confidence the feature is sensible.

griffin added on 2018-11-01 15:49:23:
I am satisfied with this approach.  Access to the scope'd variable will allow all Tcl based introspection which is the point of the ticket, I believe.

dgp added on 2018-11-01 16:15:00:
Thanks for the positive review.
Updated tests and documentation would be the next steps then.

schmitzu added on 2019-02-04 15:22:45:
I've adjusted the tests and added some new ones.
Also I tried to adjust the documentation.
Should I upload the files here?

Attachments: