1. syntax error not flagged?

Maybe someone can explain the following, which contains a syntax error ...  if
compare(a,b)  then... , (should have been
equal(a,b) or compare(a,b) = 0) which is not flagged by the interpreter as an
error, and then results in the code
producing the wrong 'result'.

with trace
sequence a,b,c,result

a = "UP"
b = "DOWN"
c = "UP"

trace(1)

if compare(a,c)        then
   result = "right"
elsif compare(a,b)     then
   result = "wrong"
end if

puts(1,result&"\n")


Thanks,

Jim

new topic     » topic index » view message » categorize

2. Re: syntax error not flagged?

Jim wrote:

<snip>
> Maybe someone can explain the following, which contains a syntax error ...
if compare(a,b)  then... , (should have been
> equal(a,b) or compare(a,b) = 0) which is not flagged by the interpreter as
an error, and then results in the code
> producing the wrong 'result'.
</snip>

It isn't flagged because it isn't a syntax error.  Compare is a function
which takes two parameters and  returns -1 if a is less than b, 0 if a is
equal to b, and +1 if a is greater than b.  The if statement interprets 0 as
false and any non-zero atom as true.  The usage above is equivalant to

if compare(a,b)!=0 then . . .

or

if not equal(a,b) then . . .

The problem is, of course, that the programmer probably didn't mean that.
But the interpreter can't assume that an unlikely but legal syntax is an
error.  Perhaps a warning might be in order--but certainly not an error.

-- Mike Nelson

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu