Page 1 of 1

(and), (or), (+), (*) ...

Posted: Thu Jun 11, 2009 12:26 pm
by Kazimir Majorinc
In Newlisp

Code: Select all

> (and)
nil
> (or)
nil
> (+)

ERR: missing argument in function +
> (*)

ERR: missing argument in function *
>
In Common Lisp:

Code: Select all

[1]> (or)
NIL
[2]> (and)
T
[3]> (+)
0
[4]> (*)
1
IN Scheme:

Code: Select all

> (or)
#f
> (and)
#t
> (+)
0
> (*)
1
> 
Can I suggest change of the behaviour in Newlisp, this time I think CL and Scheme got it right, ie. result of the operation on zero arguments is neutral element for given operation. It is the most critical for and, because unilke + and *, it returns some result, but not expected one. One example from practice:

(and x1 x2 true x3 ...) = (and x1 x2 x3 ...)

Simplification of and - formula by deletion of true is typical syntactical transformation of logical formula. However, in Newlisp, the last deletition cannot be done because

(and true) =/= (and)

other interesting cases are max and min, even begin can be understood as special case.

Posted: Thu Jun 11, 2009 3:19 pm
by Lutz
Thanks Kazimir, I agree, this will be changed. The behavior of min and max is already as in Scheme CL.

Posted: Thu Jun 11, 2009 4:49 pm
by Kazimir Majorinc
Lutz wrote:Thanks Kazimir, I agree, this will be changed. The behavior of min and max is already as in Scheme CL.
You can also use 1.#INF and -1.#INF as neutral elements for min and max respectively. It is not unusual:

http://documents.wolfram.com/mathematica/functions/Max
http://en.wikipedia.org/wiki/Max-plus_algebra