Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!ub!galileo.cc.rochester.edu!rochester!pt.cs.cmu.edu!glinda.oz.cs.cmu.edu!mkant From: mkant@glinda.oz.cs.cmu.edu (Mark Kantrowitz) Newsgroups: comp.lang.lisp Subject: Re: (setf (values ... Message-ID: <13457@pt.cs.cmu.edu> Date: 14 Jun 91 04:09:10 GMT References: <1991Jun13.204847.5625@jpl-devvax.jpl.nasa.gov> Organization: Carnegie-Mellon University, CS/RI Lines: 82 In article <1991Jun13.204847.5625@jpl-devvax.jpl.nasa.gov> charest@AI-Cyclops.JPL.NASA.GOV writes: > Anyone out there have CL code for a setf method for values as > mentioned on page 129 of CLtL2? The code should handle the case > wherein any of the sub-forms of values can themselves have setf > methods. Thanks in advance. What follows is an excerpt from a mail message I sent to a local mailing list a while ago on this topic. I've omitted the code, since the changes are specific to the implementation of setf methods in CMU Common Lisp, but the change to defsetf should be fairly easy to do in other lisps. Once the change is in place, writing this kind of multiple value setf method is about as easy as writing a normal defsetf method. I have not heard whether X3J13 is considering anything along these lines. --mark Return-Path: Received: from glinda.oz.cs.cmu.edu by A.GP.CS.CMU.EDU id aa18637; 25 Dec 90 0:01:36 EST Date: Mon, 24 Dec 90 16:50:07 EST From: Mark.Kantrowitz@GLINDA.OZ.CS.CMU.EDU To: slisp-group@B.GP.CS.CMU.EDU Subject: setf of multiple values Cc: mkant@A.GP.CS.CMU.EDU CLtL2 talks a little about setf of multiple values (e.g., the discussion of get-setf-method-multiple-value), but does not mention how the multiple values should be specified or even how to define a setf method. Anyway, I needed this, so I played around with an implementation by hacking the definitions of setf, defsetter and defsetf in CMU-CL. Since it was extremely desirable that setf retain the syntax setf {place newvalue}* I made the changes such that newvalue could be a form that returned multiple values. I also modified defsetf, so that instead of restricting you to only one store variable defsetf access-fn lambda-list (store-variable) ... it would allow any number of store variables. For example, if I have (defun foo (x) (values (car x) (cadr x))) instead of having to do (define-setf-method foo (x) (let ((store-1 (gensym)) (store-2 (gensym)) (temp-x (gensym))) (values (list temp-x) ; temp for X (list x) ; the value of X (list store-1 store-2) ; the store variables `(progn ; storing form (rplaca ,temp-x ,store-1) (rplaca (cdr ,temp-x) ,store-2) (values ,store-1 ,store-2)) `(foo ,temp-x)))) to define a multiple value setf method, all I need to do is (defsetf foo (x) (v1 v2) `(progn (rplaca ,x ,v1) (rplaca (cdr ,x) ,v2) (values ,v1 ,v2))) Then we have * (setq a '(1 2)) (1 2) * (foo a) 1 2 * (setf (foo a) (values 3 4)) 3 4 * a (3 4) With this unification of single and multiple values in defsetf, the distinction between get-setf-method and get-setf-method-multiple-value seems to be moot. ;;; *EOF*