Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Better coherence in traces

Open433252ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 23 years ago
Descriptionplain2001-06-14 21:44:52
The rule for when a read trace fires seem capricious:
consider

    trace variable x r {puts hello;#}

* [append x 1] does not fire (even if x is a pure list)
* [append x {}] does not fire 
* [append x] fires
* [lappend x 1] fires (even if x is a pure list)
* [lappend x] fires
msoferplain2001-06-15 05:00:22
Logged In: YES 
user_id=148712

Forgot one: [info exists x] does not really read the value,
but the read trace is fired ...
fbonnetplain2001-06-18 14:39:51
Logged In: YES 
user_id=93873

both append and lappend eventually return the value of the 
variable, so they should both fire a read event whatever 
the arguments
welchplain2001-06-21 11:02:48
Logged In: YES 
user_id=89720

The reason that "info exist" fires a read trace is so you
can
simulate variables that don't really exist, or that require
fabrication
on the fly.  In particular, this change was made to support
variables
shared among different Tcl interpreters running in different
threads.

I can't speak to the quirkiness of append vs. lappend,
except to
speculate that it is a performance optimization.
nobodyplain2001-06-23 00:01:11
Logged In: NO 

It wasn't the best design decision to allow traces on
non-existant variables, but here we are.  Most programmers
expect "info exists varName" to be non-invasive.  This
was changed and then changed back to the current behavior.

As far as traces firing or not firing on append or lappend
operations, it probably doesn't matter.

I can't think of a situation where I would want to put a
read trace on a variable I was appending to.  I might
put a write trace to make it read-only.  I might put a
read trace to simply supersede it's current value.  

   trace variable date r ResetDate

I'm guessing that's why nobody ever's complained about
the inconsistency before.
dkf Ticket [433252ffff]: 1 change [History diff]2003-06-26 17:34:20
dgp Ticket [433252ffff]: 1 change [History diff]2003-06-26 23:07:56
dkfplain2003-06-27 15:27:38
Logged In: YES 
user_id=79902

You might want a trace on a variable you append to if the
variable value was something that was somehow shared between
interpreters that communicate across, say, a network
connection.  Debugging is another obvious application.
Log in (anonymous is fine) to add a comment.