prederror, conditionals



On 9/24/09, ?iga Lenar?i? <ziga.lenarcic at gmail.com> wrote:

> I think Maxima's 'if' is wrong - in a sense, if should evaluate ONLY
> when the result of the test is known.

I'm not convinced. "if" in Maxima is truly a conditional expression
(emphasis on "expression") for which typical expression operations
are possible. In particular partial evaluation and simplification is
applied to conditional expressions when the condition evaluates
to something other than true or false. (Note that only atoms are
evaluated; functions are not called.) It's very much in the same
spirit as partial evaluation for arithmetic expressions: try to get
as far as you can on what information is available.

Incidentally, the current evaluation policy for "if" branches
(evaluate atoms and simplify when test is not true and not false)
was in place before I came on the scene.

It is unfortunate that simplification can have a side effect
(e.g. 1/0 and log(0) trigger errors) so e.g. if foo then 1/0 =>
error when foo evaluates to itself. That's a wart in simplification,
not a problem in conditional expressions.

> I find lisp's if very nice precisely because it's written as a
> function - though 'if' is no ordinary function, except in Maxima,
> where in simplifies 'then' and 'else'. Usually in real programming
> languages, 'if' guarantees that only one of the two ('then', 'else')
> will be looked at.

So-called "real" programming languages are mostly missing
Maxima's emphasis on expressions.
In those languages, the behavior of "if" is constrained because
they simply cannot do anything useful when the test condition
evaluates to something other than true or false.

best

Robert Dodier