Artifacts Associated With Ticket 217782
Ticket change [a6eeb13f71] (rid 98693) by nobody on 2000-10-26 00:43:34:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- 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 - foundin initialized to: "obsolete: 8.0.3"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "10. Objects"
- title initialized to:
for loop with body "puts $i" does not compile correctly
- type initialized to: "Bug"
Ticket change [9de99dc7cd] (rid 96388) by welch on 2000-10-26 07:49:17:
- closedate changed to: "2000-10-26T00:49:17"
- closer changed to: "welch"
- priority changed to: "1 Zero"
- resolution changed to: "Duplicate"
- status changed to: "Closed"
Ticket change [68093c7a46] (rid 102998) by msofer on 2001-08-22 22:18:34:
- closedate changed to: "2001-08-22T15:18:34"
- closer changed to: "msofer"
- icomment:
Logged In: YES user_id=148712 This behaviour is generalized in bug report #219166
- login: "msofer"
- mimetype: "text/plain"
- title changed to:
for loop with body "puts $i" does not compile correctly
- username: "msofer"