Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 25a7dc9f24ac60f3788aa357b53e6ce3b6e70d19
Ticket: 3599906fffffffffffffffffffffffffffffffff
dict command has side effects on foreach
User & Date: heinrichmartin on 2013-01-08 08:52:22
Changes

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    "dict keys" takes a dictionaryVALUE, but affects the variable's interpretation by foreach:
    
    expect:/tmp$ set tcl_version 
    8.5
    expect:/tmp$ set x {1 a 2 b 3 c 3 d 3 e} ;# store a list which also is a dictionary value
    1 a 2 b 3 c 3 d 3 e
    expect:/tmp$ foreach {key val} $x {puts "$key -> $val"} ;# print pairs of list elements correctly
    1 -> a
    2 -> b
    3 -> c
    3 -> d
    3 -> e
    expect:/tmp$ dict keys $x ;# the argument is passed by value, isn't it? (see dict or the dodekalogue)
    1 2 3
    expect:/tmp$ foreach {key val} $x {puts "$key -> $val"} ;# we had that very command, and x was not altered.
    1 -> a
    2 -> b
    3 -> e
    expect:/tmp$ set x ;# indeed, x was not altered
    1 a 2 b 3 c 3 d 3 e
    
    Obviously, variables are stored in best-guess-data-structures (lists, dictionaries, ...) whenever a corresponding command is used.
    This performance benefit must not affect consistency.
    
    Why does foreach treat dict-variables differently?
    This should not happen, we do have "dict for"!
    
  4. foundin changed to: "obsolete: 8.5.13"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "heinrichmartin"
  10. subsystem changed to: "15. Dict Object"
  11. title changed to: "dict command has side effects on foreach"
  12. type changed to: "Bug"