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

Notices and updates
Post Reply
Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

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

Post 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.

Lutz
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Thanks Kazimir, I agree, this will be changed. The behavior of min and max is already as in Scheme CL.

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post 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

Post Reply