Closed mck- closed 11 years ago
Your use of NREVERSE is undefined according to [1].
"The consequences are undefined if a macro function destructively modifies any part of its form argument."
[1] http://www.lispworks.com/documentation/HyperSpec/Body/03_ababb.htm
Thanks!!
Sent from my iPhone
On 2013-09-23, at 6:13 PM, Mark Cox notifications@github.com wrote:
Your use of NREVERSE is undefined according to [1].
"The consequences are undefined if a macro function destructively modifies any part of its form argument."
[1] http://www.lispworks.com/documentation/HyperSpec/Body/03_ababb.htm
— Reply to this email directly or view it on GitHub.
While the use of NREVERSE in a macro is problematic, I think there is also an issue with destructively modifying the literal ALIST. I don't have time tonight to work out an example, but I've run into problems with unit tests where a literal object is modified. I'll probably have time to work out the example tomorrow.
The following code works without error, even with the literal alist. I could not find a bug related to this in lisp-unit and am closing this issue.
(defun aval (key alist)
"Given alist and key, return value"
(cdr (assoc key alist :test #'equal)))
(defun val-reversed (alist &rest keys)
"Given an alist, and a list of keys, retrieve value dot-notation style (reversed)"
(if (null keys)
alist
(aval (first keys) (apply #'val-reversed alist (rest keys)))))
(defun val (alist &rest keys)
"Given an alist, and a list of keys, retrieve value dot-notation style."
(apply #'val-reversed alist (reverse keys)))
(define-test alist-highest-occurence
(assert-equal
1 (val '(("this" (NEXT . 1))) "this" 'next)))
Nice, no macros! Thanks :)
Which results in tests passing the first time, and failing the next..