Old tcl programs don't work - equality operator in tcl 8.3 
Author Message
 Old tcl programs don't work - equality operator in tcl 8.3


mrao.cam.ac.uk would be appreciated.
I have used tcl for several years, and we recently upgraded from tcl8.0
to tcl 8.3.
I find that many programs which worked fine under 8.0 are now broken.
The main problem appears to be my use of "==" to do string comparison.
Example:

#!/bin/sh
# the next line restarts using wish \


set thestring "bingo"

if (($thestring=="bingo")||($thestring=="Bingo")) {
    puts "Bingo!"

Quote:
} else {
    puts "No Bingo"
}

If I use wish8.0 this works; with 8.3, it gives

Error in startup script: syntax error in expression "((bingo=="bingo"))"

Now, I assume my poor programming style is to blame for this problem,
rather than an error in tcl8.3.
I'd really appreciate advice on a simple fix [I have used the "=="
operator in this way hundreds of times in my programs!]


----------------------+   www: http://www.*-*-*.com/
Cavendish Laboratory, |   tel: 01223-339852  fax: 354599  home: 740511
Madingley Road,       |        international code: +44-1223
Cambridge CB3 0HE. UK.|



Sun, 19 Jan 2003 03:00:00 GMT  
 Old tcl programs don't work - equality operator in tcl 8.3

Quote:

> I find that many programs which worked fine under 8.0 are now broken.
> The main problem appears to be my use of "==" to do string comparison.
> Example:
> set thestring "bingo"
> if (($thestring=="bingo")||($thestring=="Bingo")) {
>    puts "Bingo!"
>} else {
>    puts "No Bingo"
>}
>If I use wish8.0 this works; with 8.3, it gives
>Error in startup script: syntax error in expression "((bingo=="bingo"))"
>Now, I assume my poor programming style is to blame for this problem,
>rather than an error in tcl8.3.
>I'd really appreciate advice on a simple fix [I have used the "=="
>operator in this way hundreds of times in my programs!]

I think it's rather a paren problem. Thew round parens you use look
C-ish, but have no meaning to Tcl. It is general practice to put the
first argument to [if] in curly braces, otherwise the quoting of
variables substituted to strings gets lost. This is not new in 8.3. I
tested our tclsh 8.0 (expr being the evaluator that if uses):
% set foo bar
bar
% expr $foo=="bar"
syntax error in expression "bar=="bar""
% expr {$foo=="bar"}
1
(Wonder why it worked with your 8.0!) So just say, like we all do
(mostly ;-)
 if {($thestring=="bingo")||($thestring=="Bingo")} {

Of course string matches with == are not recommended, one should better
use [string compare..] or [string equal..] or the brand-new "eq"
operator, but in safe cases I still prefer ==/!= between strings too.
--
Schoene Gruesse/best regards, Richard Suchenwirth - +49-7531-86 2703
RC DT2, Siemens Electrocom, Buecklestr. 1-5, D-78467 Konstanz,Germany
-------------- http://purl.org/thecliff/tcl/wiki//Richard*Suchenwirth
AL:The Analytical Engine worketh not! CB:What version dost thou have?



Sun, 19 Jan 2003 03:00:00 GMT  
 Old tcl programs don't work - equality operator in tcl 8.3

                        .
                        .
                        .
Quote:
>(Wonder why it worked with your 8.0!) So just say, like we all do
>(mostly ;-)
> if {($thestring=="bingo")||($thestring=="Bingo")} {

                        .
                        .
                        .
It's reasonably well-documented that 8.0 was "over-aggressive"
in its early implementation of byte-code compilation, and this
deceptive evaluation of
  if ($a == $b) ...
was one outcome.  Tcl programmers:  PLEASE do not let this sort
of dirt remain in your source.  It'll cause a lot of inconveni-
ence, even if you're convinced your users will always rely on
8.0.
--


Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



Sun, 19 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. what expect work with tcl/tk 8.3?

2. Stubs with Tcl 8.3 vs Tcl 8.4

3. CONST Tcl 8.3 vs Tcl 8.4

4. Looking for the Tcl Plugin that is based on Tcl 8.3

5. Tcl plugin and TCL 8.3

6. Socket programming extensions for Tcl/Tk 8.3

7. Tcl Developer Xchange don't work?

8. megawidges don't work after upgrade tcl/tk8.0 and itc3.0

9. shipping tcl/tk apps to users who don't have tcl/tk installed

10. Tcl scripts that exec other programs don't have trouble under Linux batch

11. python,tkinter,tcl/tk 8.3

12. Python 1.5.2 and Tcl/Tk 8.3

 

 
Powered by phpBB® Forum Software