Re: Canonical Way to Mask SETF?
- From: peder@xxxxxxxxxxxxxxxxxxx (Peder O. Klingenberg)
- Date: Thu, 30 Jun 2005 09:08:30 +0200
Robert Uhl <eadmund42@xxxxxxxxxxxxxxx> writes:
> (defsetf menu-title (menu) (title)
> `(setf (getf ,menu :title) ,title))
I've never been able to grok defsetf. But I find that for my uses,
(defun (setf ...) ...) has always done the trick.
As an example, I have an application that makes extensive use of a
cache of data, contained in a data structure built up of nested hashes
(yes, I've been a perl programmer).
The handling of the nested hashes are in a package of its own, but to
save some typing in my application, I defined the following two
functions.
(defun cache-get (&rest keys)
(nh:nhget keys *portfolio-cache*))
(defun (setf cache-get) (newval &rest keys)
(setf (nh:nhget keys *portfolio-cache*) newval))
This allows me to write things like
(cache-get :traversal :path through :tree) => value1
(setf (cache-get :traversal :path through :tree) value2) => value2
This works flawlessly, at least in lispworks 4.3.
(As you may infer, the nested hash package contains its own
(defun (setf nhget) ...), but its definition is rather more complex.)
....Peder...
--
This must be Thursday. I never could get the hang of Thursdays.
.
- Follow-Ups:
- Re: Canonical Way to Mask SETF?
- From: Kent M Pitman
- Re: Canonical Way to Mask SETF?
- References:
- Canonical Way to Mask SETF?
- From: Robert Uhl
- Canonical Way to Mask SETF?
- Prev by Date: Re: Implementing custom containers in Lisp
- Next by Date: Re: Canonical Way to Mask SETF?
- Previous by thread: Re: Canonical Way to Mask SETF?
- Next by thread: Re: Canonical Way to Mask SETF?
- Index(es):