Skip to content
Tcl Source Code History Of Ticket 1537233
Login

History Of Ticket 1537233

Artifacts Associated With Ticket 1537233

  1. Ticket change [b1afffd69a] (rid 98192) by ctasada on 2006-08-09 08:57:41:

    1. assignee initialized to: "dkf"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Hi again guys,
      
      I've seen a feature request that can be related
      (1106138) so probably it's a known "feature" of the
      switch command.
      
      Anyway I find it quite strange.
      
      Here is the script that shows the actual problem:
      # Create some variables and assign numbers to them
      set one 1
      set two 2
      set three 3
      set value 2
      
      switch -- $value {
      $one {puts 1}
      $two {puts 2}
      $three {puts 3}
      default {puts "$value is unknown"}
      }
      % 2 is unknown
      
      switch -- $value {
      1 {puts 1}
      2 {puts 2}
      3 {puts 3}
      default {puts "$value is unknown"}
      }
      % 2
      
      As you can see looks like is not doing the variable
      substitution. Googling a bit I found this solution:
      
      switch -- $value [list\
      $one {puts 1}\
      $two {puts 2}\
      $three {puts 3}\
      default {puts "$value is unknown"}\
      ]
      % 2
      
      Which works, but is quite dirty.
      
      Should be considered a bug?
      
    4. foundin initialized to: "obsolete: 8.5a4"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "ctasada"
    10. subsystem initialized to: "18. Commands M-Z"
    11. title initialized to: "Switch doesn't variable substitution"
    12. type initialized to: "Bug"
  2. Ticket change [885607f1fb] (rid 131852) by dkf on 2006-08-09 17:04:23:

    1. closedate changed to: "2006-08-09T10:04:23"
    2. closer changed to: "dkf"
    3. icomment:
      Logged In: YES 
      user_id=79902
      
      It's not a bug. It's just Tcl's standard quoting rules, and
      everything *has* to be this way for reasons that are rather
      deeply embedded in the language's basic philosophy.
      
      But for this case, the other form of input to the [switch]
      command is probably useful. You are aware that what you
      wrote could also be (wholly equivalently) written like this:
      
        switch -- $value \
           $one {puts 1} \
           $two {puts 2} \
           $three {puts 3} \
           default {puts "$value is unknown"}
      
      Hope this helps.
      
      
    4. login: "dkf"
    5. mimetype: "text/plain"
    6. resolution changed to: "Invalid"
    7. status changed to: "Closed"
    8. username: "dkf"
  3. Ticket change [949075b722] (rid 106007) by ctasada on 2006-08-09 17:18:29:

    1. icomment:
      Logged In: YES 
      user_id=340696
      
      Ok, I though you would say it ;)
      
      Anyway would be nice to have this kind of feature is Tcl ;)
      
      Thanks a lot.
      
      
    2. login: "ctasada"
    3. mimetype: "text/plain"
    4. username: "ctasada"