Re: with-slots usage question
Peter Seibel <[email protected]> 10 Nov 2003 09:12:06 -0800
| Newsgroups | gmane.lisp.clump |
|---|---|
| Message-ID | <[email protected]> |
Miles Egan <[email protected]> writes: > Since discovering with-slots I've started using it pretty heavily in my > code since it really cuts down the verbosity of clos-based code. It > makes me a little uneasy that with-slots goes directly to the slot value > without using an accessor though. I suppose the more proper thing would > be to use with-accessors but it seems so much more verbose. > > The ideal thing would be a with-? macro that's as terse as with-slots > but does invoke accessor functions. Does such a macro exist? Would it > be possible to write one without using the MOP? Assuming you're happy to live with the variable names matching the accessor names, doesn't this do what you want? (Coming up with a better name than with-foo is left as an exercise for the reader): (defmacro with-foo ((&rest names) obj &body body) `(with-accessors ,(mapcar #'(lambda (n) (list n n)) names) ,obj ,@body)) -Peter -- Peter Seibel [email protected] Lisp is the red pill. -- John Fraser, comp.lang.lisp