Tcl Source Code

Ticket Change Details
Login
Overview

Artifact ID: baad1c9101d3ec89114f0208cf841d6c0624bd07
Ticket: 5edbc4a9f40bd2cfce24e291fc57dea51b7f1a50
It's not possible to manipulate complex data structures inside procs
User & Date: ferrieux 2015-09-04 10:38:11
Changes

  1. closedate changed to: "2457269.94318294"
  2. closer changed to: "ferrieux"
  3. icomment:
    Extra references hide in some unconspicuous places:
    
       - on the stack when you pass the value as argument
       - on literals
       - on hidden stack levels in case of [interp alias]
       - etc.
    
    In your case, the one that's striking is the literal. Use [expr rand()] to generate a value that will not be stored as a literal.
    Then of course the var itself holds a reference. To nuke that one too, use the K-free-K idiom $x[unset x].
    
    Wrapping up:
    
    % proc f {} {set x [expr rand()];puts [tcl::unsupported::representation $x[unset x]]}
    % f
    value is a double with a refcount of 1, object pointer at 0x8fe4ec0, internal representation 0x1cfea9a0:0x3fef54d0, no string representation
    % namespace eval B {
    variable var_B [expr rand()]
    puts [tcl::unsupported::representation $var_B[unset var_B]]
    }
    value is a double with a refcount of 1, object pointer at 0x86e9910, internal representation 0xab242eb7:0x3fc2175b, no string representation
    
  4. login: "ferrieux"
  5. mimetype: "text/plain"