Skip to content
Tcl Source Code History Of Ticket 217782
Login

History Of Ticket 217782

Artifacts Associated With Ticket 217782

  1. Ticket change [a6eeb13f71] (rid 98693) by nobody on 2000-10-26 00:43:34:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 727 Bug
      Version: 8.0.3
      SubmitDate: '1998-10-13'
      LastModified: '1999-08-13'
      Severity: SER
      Status: Closed
      Submitter: admin
      ChangedBy: hobbs
      RelatedBugIDs: 1669
      OS: All
      OSVersion: NA
      Machine: NA
      FixedDate: '2000-10-25'
      FixedInVersion: NA
      ClosedDate: '1999-08-13'
      
      
      "Jeffrey P. Talberg" wrote:
      > 
      > I was trying to create a simple tcl example that I can use for teaching
      > a course illustrating the difference between "" and {} grouping by using
      > the for command .
      [snip]
      > #-----------------------------------------
      > # This is the one I had a question about
      > #-----------------------------------------
      > for {set i 0} {$i < 10} {incr i} "puts $i"
      > 
      > Why does the last version still print the numbers 0-9?  I expected it to
      > print 0 10 times.  I thought the statement "puts $i" would become "puts
      > 0" when the for command underwent grouping and substitution prior to
      > command dispatch.
      
      You are correct, that's what it should do.
      
      > 
      > I was intrigued by these results, can anyone explain why tcl behaves
      > this way?
      
      That sure looks like a bug to me. Probably our friend the byte compiler
      doing some "optimizations" for us. 
      
      This has prompted me, finally, to reinstall tcl 7.6. It seems like there
      are lots of little bugaboos popping up that seem to be related to the
      byte compiler. Sure enough, running this example with 7.6 gives the
      expected results:
      
          % for {set i 0} {$i < 10} {incr i} "puts $i"
          can't read "i": no such variable
          % set i 0
          0
          % for {set i 0} {$i < 10} {incr i} "puts $i"
          0
          0
          0
          ...
      
      FWIW, I can duplicate the behavior you report with both 8.0.3 and 8.1a2
      and protclsh. Interestingly,  not only does the loop perform wrong, but
      the interpreter doesn't seem to care that $i isn't defined during the
      parsing phase. It looks like the byte compiler is just assuming the body
      shouldn't go through substitution regardless of the quoting (shame on
      it!). 
      
      As proof, modifying the code to be this:
      
          for {set i 0} {$i < 10} {incr i} [list puts $i]
      
      ... gives the same (broken) results. Interestingly, this only seems to
      happen if the variable in the print statement is the same as the loop
      variable. For example, if I change the command to be "puts $z" I get the
      expected error message "can't read "z": no such variable". 
      
      
      This still exists in 8.2b3.  See related 1669 for detailed evaluation. 
      -- 08/13/1999 hobbs
      
    4. foundin initialized to: "obsolete: 8.0.3"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "10. Objects"
    10. title initialized to:
      for loop with body "puts $i" does not compile correctly
      
    11. type initialized to: "Bug"
  2. Ticket change [9de99dc7cd] (rid 96388) by welch on 2000-10-26 07:49:17:

    1. closedate changed to: "2000-10-26T00:49:17"
    2. closer changed to: "welch"
    3. priority changed to: "1 Zero"
    4. resolution changed to: "Duplicate"
    5. status changed to: "Closed"
  3. Ticket change [68093c7a46] (rid 102998) by msofer on 2001-08-22 22:18:34:

    1. closedate changed to: "2001-08-22T15:18:34"
    2. closer changed to: "msofer"
    3. icomment:
      Logged In: YES 
      user_id=148712
      
      This behaviour is generalized in bug report #219166
      
      
    4. login: "msofer"
    5. mimetype: "text/plain"
    6. title changed to:
      for loop with body "puts $i" does not compile correctly
      
    7. username: "msofer"