Tcl Library Source Code

View Ticket
Login
Ticket UUID: 01afa9345d4f1f09330edf57cf53971f3d92acf3
Title: textutil::expander expand - cget within an expand
Type: Bug Version: 1.3.1
Submitter: anonymous Created on: 2013-10-18 03:31:00
Subsystem: textutil :: expander Assigned To: akupries
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2013-12-06 22:26:43
Resolution: Invalid Closed By: nobody
    Closed on:
Description:
This may be as intended but it appears that running cget inside of an expand call throws an error.

testcase:

::textutil::expander exp
exp cset BAR FOO
exp expand {[exp cget BAR]} --> throws error

but 
::textutil::expander exp2
exp2 cset BAR2 FOO2
exp expand {[exp2 cget BAR2]} --> yields FOO2

This seems like a bug but perhaps I'm missing something.  

Really like the expander package. Thank you.
User Comments: aku added on 2013-12-06 22:26:43:
Note added in revision [e53cad73ec].
Committed.
Pushed.

aku added on 2013-12-06 22:16:49:
The behaviour is actually ok.

expanderName cset varname value
    Sets variable varname to value in the __current__ context.

And the 'expand' method does a 'cpush expand' as the first action, i.e. it creates a __new context__ which has no variables. The BAR variable is in the context outside of this new one, and thus not accessible. Something like

  exp expand {[exp cset BAR FOO][exp cget BAR]}

Should work, as it creates the BAR variable in the expand context before accessing it from the same context.

With the second example a separate expander is accessed with its own stack of contexts, which is not influenced by the 'exp expand ...' operation.

I will make a note in the expander documentation about 'expand' pushing a new context.

aku added on 2013-10-29 06:24:17:
In the second example we have two different expander instances.
In the first we have only one instance.

It might be a scope issue, i.e. the instance not available in the scope where text substitution happens. Not sure if [cget BAR] would work, i.e. the instance implicit in the context.

Will try to convert the example into a test case and then debug.