Re: A bug in the interpreter

new topic     » goto parent     » topic index » view thread      » older message » newer message

Ed Davis wrote:
> 
> Daryl Border
> 
> >   It is not the responsibility of the interpreter to prevent
> >the programmer from using poorly formed expressions such as (4 <
> >n) < 8.
> 
> Some people might say that "4 < n < 8" is a poorly formed
> expression.  If you are coming from the C/Java world, you would
> say it is perfectly valid, but it does not mean "4 < n and n <
> 8", but rather the (4 < n) < 8.
> 
> >It is the responsibility of the interpreter to evaluate the
> >expressions according to the rules of mathmatics. My code
> >evaluates both expressions correctly. Euphoria currently does
> >not.
> 
> How does it correctly evaluate (4 < n) < 8?  Does it treat (4 <
> n) as a boolean, and then compare against that?

You are correct. (4 < n) < 8 is not a valid math expression. My code can't
evaluate it correctly because there is no valid way to evaluate it.
It would be nice if the interpreter could catch the error. But without a way
to distinguish between the integers 1 and 0  and the boolean values TRUE and
FALSE it can't. This problem already exists in euphoria, my code does not 
create it.

> 
> What about "4 < n < 8 < a < b"?  How should that be evaluated? Is
> it "4 < n and n < 8 and 8 < a and a < b?"  Should the interpreter
> allow that? How do your changes evaluate it?
> 
This is a valid math expression and your interpretation is correct. If my
code is bug free it will evaluate it correctly.

> Along the same lines, what about:  "4 = n = 8"?  It is also
> currently accepted, and apparently interpreted as:
> 
4 = n = 8 is a valid math expression and will be evaluated as 4 = n and n = 8.
It of course always evaluates to FALSE, but it is the programmer's
responsibility
to write useful code.

> (4 = n) = 8

Again (4 = n) = 8 is not a valid math expression because (4 = n) evaluates to
a boolean value.
> 
> The same way C would interpret it (well, replace the '=' with
> '==').
> 
> Without understanding all the possible ramifications, I'm not
> sure changing the current semantics is a good idea.

The problems you're concerned about already exist. Until a means to distinguish
between integers and boolean values is implimented, they will continue to exist.
In the mean time we will have to rely on the programmer's knowledge of math for
correct math expressions.
Daryl Border

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu