On Mon, 9 Dec 2002 [EMAIL PROTECTED] wrote:
>
>
> I've been getting some cryptic error messages from the following block
> of code with CMUCL 18d
>
> (in-package "COMMON-LISP-USER")
>
> (defmacro setassoc (key new-element alist &key (test #'eq))
^^^^
> `(let* ((new-element ,new-element)
> (old-assoc (assoc ,key ,alist :test ,test)))
>
> (if old-assoc (setf ,alist (delete old-assoc ,alist :test ,test)))
> (push (list ,key new-element) ,alist)))
>
> (defun bletch (job time first-calls)
> (setassoc job time first-calls))
Your default value for TEST is your problem. You're inserting a function
value, as a constant, from the macroexpand-time environment into your
code. Offhand I can't quote chapter and verse that says this isn't
allowed, and I know that ACL does support dumping this kind of constant in
fasl files, but as you've found CMUCL doesn't support that. If you
replace (test #'eq) with (test '#'eq) you should be back in business.
>
> The above code is certainly inelegant (LET* seems unnecessary, instead
> of LET, IF could be WHEN, etc.), but doesn't seem obviously buggy. As
> far as I know it works fine in Allegro CL, but CMULISP doesn't like it
> at all.
If you're interested in an critique of your code :), here are a couple of
observations:
* Association list elements are usually cons cells, not lists
* If you have the old-assoc element, you can directly set the cdr of the
element rather than delete the element and push a new one on the front
* Write this as a defsetf for extra credit :)
>
> Interestingly, the SETASSOC macro is fine when I enter it in a REPL,
> but doesn't compile. I'm afraid I don't have a clue why the compiler
> seems to hate #'eq so much.
Hope this helps,
Tim