vseloved / rutils

Radical Utilities for Common Lisp
Other
250 stars 37 forks source link

:= is too surprising compared to psetf #32

Closed mindamin closed 7 years ago

mindamin commented 7 years ago

With regards to the most recent commit,

https://github.com/vseloved/rutils/commit/f2d19146639a32a9ce404ac4af4bd5cc73ccdd87#diff-e9b8b78804398dc454c884ce19e57889

:= was changed from a simple alias of psetf to a buggy (depending on interpretation) re-implementation of psetf.

In this example,

(:= a b c d)

If we are to follow the other behaviour of psetf as closely as possible, then order of evaluation of the values must be sequential, b must be evaluated before d.

Furthermore, side effects in places should also occur before those in values. To use a different example,

(let ((i 0)) (:= (elt a (incf i)) (incf i)))

is now equivalent to (setf (elt a 2) 1) when it should be equivalent to (setf (elt a 1) 2).

I believe the intend for := should be to follow psetf and setf as closely as possible, so the above behaviour should be considered buggy. In that case, the best intro to generalised variables I've found is in On Lisp:

http://www.bookshelf.jp/texi/onlisp/onlisp_13.html#SEC89

vseloved commented 7 years ago

Thank you for noticing this bug. In fact, I've also spotted it already and developed a fix that, unfortunately, had not been pushed to the repository. Now, it's in there: https://github.com/vseloved/rutils/commit/a1117a6441fee0303f89781ebe07a95045233619

Can you review it and comment if you think there any problems still remain?

mindamin commented 7 years ago

Right, PSETF can take care of most of the setf expansion machinery, this was an easy fix. Seems to work now.