Re: Canonical Way to Mask SETF?



Robert Uhl <eadmund42@xxxxxxxxxxxxxxx> writes:

> I'm playing with a menu system, and would like to be able to write the
> following:
>
> (menu-item menu) -> item
> (setf (menu-item menu) item)
>
> I figured that something like this would do the trick:
>
> (defun menu-item (menu)
> (getf menu :title))
>
> (defsetf menu-title (menu) (title)
> `(setf (getf ,menu :title) ,title))
>
> But of course it doesn't work. Any advice on how this needs to be
> written?

Maybe you want to call the defun menu-TITLE, not menu-ITEM?
Or you want to call the setf function menu-ITEM, not menu-TITLE?

Otherwise I don't see why it shouldn't work.

> Unfortunately there aren't too many online references which deal with
> DEFSETF--at least none that I've found.

It's not supposed to be hard. It's like you did it, just with spelling
done right.
.



Relevant Pages

  • Re: difference between defsetf and defun (setf ...)
    ... (defun (setf name) ... Use the long form of DEFSETF, which is quite different from the two ... DEFSETF is _similar_ to the DEFUN on SETF. ... I have a function named ENTRY which is ...
    (comp.lang.lisp)
  • Re: Request for comments for my parse-float
    ... (defun sign-ok-p (str) ... (unless (empty-string-p str) ... (0 (setf start 1)) ... (setf state (fail)))) ...
    (comp.lang.lisp)
  • Re: Purpose of defmethod
    ... > reimplement defun as a macro expanding into such defmethod. ... And don't forget that CLOS was a late addition to the language -- it ... When SETF or DEFMETHOD are used, ... implemented in CL -- many CL implementations adopted the PCL (Portable ...
    (comp.lang.lisp)
  • Re: generic programming + Lisp
    ... Peter Seibel wrote: ... >> consider source code which may not be modified: ... >> (defun f (y) ... >> (setf x (random y)) ...
    (comp.lang.lisp)
  • Simularion of a (modest) star cluster
    ... (defun get-environment-variable (string) ... (xlib:display-force-output dpy) ... (setf *dpy* dpy ... (defmethod actualizar-aceleración ((e estrella) ...
    (comp.lang.lisp)