Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-04-16
23:48 • Ticket [218036ffff] MSWindows: array anymore fails as while condition status... artifact: e455cd9a6f user: dgp
2000-10-26
08:13 • Closed ticket [218036ffff]. artifact: b33be0a141 user: welch
00:52 • New ticket [218036ffff]. artifact: 2f2349770d user: nobody

MSWindows: array anymore fails as while condition

Closed / Fixed218036ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:52:25
OriginalBugID: 1341 Bug
Version: 8.0.4
SubmitDate: '1999-03-02'
LastModified: '1999-08-07'
Severity: MED
Status: Closed
Submitter: pat
ChangedBy: hobbs
OS: Windows 98
Machine: X86
FixedDate: '2000-10-25'
ClosedDate: '1999-08-07'


Name:

Richard Cochran



ReproducibleScript:

cmdline: tclsh80 test.tcl



file test.tcl:

#-----------------------



set patterns(a) 1

set patterns(b) 2

set patterns(c) 3

set patterns(d) 4

set patterns(e) 5

set patterns(f) 6



parray patterns

puts ""



set s [array startsearch patterns]

while 1 {

    set code [array anymore patterns $s] 

    puts "anymore? $code"

    if 0==$code break

    set tmp [array nextelement patterns $s]

    puts "the next element is: $tmp"

    puts "element,patterns(element) = $tmp, $patterns($tmp)"

}

array donesearch patterns $s

puts ""



set s [array startsearch patterns]

while [array anymore patterns $s] {

    set tmp [array nextelement patterns $s]

    puts "the next element is: $tmp"

    puts "element,patterns(element) = $tmp, $patterns($tmp)"

}











ObservedBehavior:

output from running test.tcl on MS Windows98:



patterns(a) = 1

patterns(b) = 2

patterns(c) = 3

patterns(d) = 4

patterns(e) = 5

patterns(f) = 6



anymore? 1

the next element is: d

element,patterns(element) = d, 4

anymore? 1

the next element is: e

element,patterns(element) = e, 5

anymore? 1

the next element is: a

element,patterns(element) = a, 1

anymore? 1

the next element is: f

element,patterns(element) = f, 6

anymore? 1

the next element is: b

element,patterns(element) = b, 2

anymore? 1

the next element is: c

element,patterns(element) = c, 3

anymore? 0



the next element is: d

element,patterns(element) = d, 4

the next element is: e

element,patterns(element) = e, 5

the next element is: a

element,patterns(element) = a, 1

the next element is: f

element,patterns(element) = f, 6

the next element is: b

element,patterns(element) = b, 2

the next element is: c

element,patterns(element) = c, 3

the next element is:

can't read "patterns()": no such element in array

    while executing

"puts "element,patterns(element) = $tmp, $patterns($tmp)""

    ("while" body line 4)

    invoked from within

"while [array anymore patterns $s] {

    set tmp [array nextelement patterns $s]

    puts "the next element is: $tmp"

    puts "element,patterns(elemen..."

    (file "test.tcl" line 24)

















DesiredBehavior:

The output running test.tcl on Linux 

(what I expect to see):



patterns(a) = 1

patterns(b) = 2

patterns(c) = 3

patterns(d) = 4

patterns(e) = 5

patterns(f) = 6



anymore? 1

the next element is: d

element,patterns(element) = d, 4

anymore? 1

the next element is: e

element,patterns(element) = e, 5

anymore? 1

the next element is: a

element,patterns(element) = a, 1

anymore? 1

the next element is: f

element,patterns(element) = f, 6

anymore? 1

the next element is: b

element,patterns(element) = b, 2

anymore? 1

the next element is: c

element,patterns(element) = c, 3

anymore? 0



the next element is: d

element,patterns(element) = d, 4

the next element is: e

element,patterns(element) = e, 5

the next element is: a

element,patterns(element) = a, 1

the next element is: f

element,patterns(element) = f, 6

the next element is: b

element,patterns(element) = b, 2

the next element is: c

element,patterns(element) = c, 3













I can't understand why this simple script doesn't produce the

same output on Windows as on Linux. If its not a bug, then it is a

very stange anomoly.



The windows behavior is correct, and the behavior on Linux is

suspect (check version numbers).  The problem is that in the

while loop, the condition is not {}ed, so it is evaluated only

the first time to 1, and will thus always loop until your error.

If you do:

    while {[array anymore patterns $s]} { ...

instead, you will get the expected behavior.

 

-- 08/07/1999 hobbs
welch Closed ticket [218036ffff]. [History diff]2000-10-26 08:13:43
dgp Ticket [218036ffff]: 3 changes [History diff]2001-04-16 23:48:48
Log in (anonymous is fine) to add a comment.