[Bese-devel] ParenScript arithmetic patch

Raymond Myers ray.myers at gmail.com
Tue Apr 3 17:29:08 UTC 2007


If this is the wrong channel or format for submitting this, let me know.

I have a minor patch that fixes the following incorrect (or at least
unexpected) behavior in ParenScript.

(js (- 1))  =>  "1;"
(js (incf x 5))   => an error
(js (decf x 5))   => an error

In all Lisp dialects that I am aware of, calling the minus operator
with a single argument produces the negation of that argument. (- x y)
yields "x - y" but (- x) is simply "-x". Without this behavior,  I
have to do things like this:

(js (setf y (- 0 x)))  => "y = 0 - x;"

As you are probably aware, the Common Lisp incf and decf functions
take an optional second argument specifying the size of the increment
or decrement[1]. I realize that the goal of ParenScript is not to
become fully ANSI compliant, but in this case the increased
compatibility wouldn't break anything.

[1] http://www.lisp.org/HyperSpec/Body/mac_incfcm_decf.html

The proposed new behavior is as follows:

(js (- 1))  =>  "-1;"
(js (incf x 5))   => "x += 5;"
(js (decf x 5))   => "x -= 5;"

(js (- x y))  =>  "x - y;"     (still)
(js (incf x))   =>  "++x;"  (still)
(js (decf x))   => "--x;"     (still)

Attached is the output of a "darcs diff".

Cheers,

-- Ray Myers
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minus-incf-decf-fix.diff
Type: text/x-patch
Size: 1396 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/bese-devel/attachments/20070403/96c075c1/attachment.bin>


More information about the bese-devel mailing list