Tim Moore writes:
 > 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.


Thanks.  I will try that out right away.
 > 
 > > 
 > > 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:

I'm not!  :-)  and IT'S NOT MY CODE!  I'm porting someone else's code
from Allegro to CMUCL.  Otherwise I would have rewritten it a bunch.
Should my lexical environment be caught or killed, I will disavow any
knowledge of this macro.

Seriously, I'm trying to port this as part of a consulting job, and
thus want to make as few changes to the source as possible; if I make
too many, I'll cause a code fork, and all kinds of unpleasant
professional ramifications.  I'm supposed to be making these folks'
jobs easier, not imposing all kinds of code rewrite!

 > 
 > * Association list elements are usually cons cells, not lists

The person who wrote this uses proper lists instead of dotted-pairs.
I don't know why and I'm not in a position to fix it.

 > * 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

Yup.

 > * Write this as a defsetf for extra credit :)

But thanks, anyway!

Best,
R

Reply via email to