Re: atom() ambiguity
- Posted by "Graeme." <hmi at POWERUP.COM.AU> Jun 20, 1998
- 508 views
As I go to send this message, I see a couple of you have already said this, but here's my stab at it anyway. At 10:44 AM 6/19/98 -0400, Alan wrote: >Maybe if atom(line) then is a shorthand, but I don't think it is a good one >because it is ambiguous. "if atom(a) then" translates to "if atom(a)!=0 then" It works because of the way the if..then statement works. If..then accepts a numeric input and branches around (skips) the enclosed code if that input is zero. Numeric input? Yes. All comparisons are equated to a numeric result, 1 for true and 0 for false. The comparison (3=5) has a value of 0 as three obviously does not equal five. You can assign the result of a comparison to a variable; integer comp comp=(6=3) print(1,comp) The output is 0 (false) ----------------- integer comp comp=(5>3)+(6!=4)+(2<9) print(1,comp) The output is 3 (true+true+true) ----------------- integer comp comp=1/(2>5) The output is division by zero (false) error ----------------- sequence comp comp=({3,6,8,4}>6) print(1,comp) The output is {0,0,1,0} (false,false,true,false) ----------------- So, if you put "if atom(line)=1 then" in your program, the comparison (atom(line)=1) will be evaluated to a one or a zero and that value will be passed to the if..then statement. But, as you have a 1 or a 0 returned from the type check anyway, it hardly seems worth the effort. Graeme. ----------------------------------------------------