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

Started by Kazimir Majorinc, June 11, 2009, 05:26:51 AM

Previous topic - Next topic

Kazimir Majorinc

In Newlisp


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

ERR: missing argument in function +
> (*)

ERR: missing argument in function *
>


In Common Lisp:


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


IN Scheme:


> (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.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

Lutz

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

Kazimir Majorinc

#2
Quote from: "Lutz"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://documents.wolfram.com/mathematica/functions/Max

http://en.wikipedia.org/wiki/Max-plus_algebra">http://en.wikipedia.org/wiki/Max-plus_algebra
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.