Xref: utzoo comp.lang.lisp:4916 comp.lang.scheme:2545 comp.sources.wanted:16779 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!ucselx!petunia!kestrel.edu!gyro From: gyro@kestrel.edu (Scott Layson Burson) Newsgroups: comp.lang.lisp,comp.lang.scheme,comp.sources.wanted Subject: SETF of LET Message-ID: <1991May22.072355.22077@kestrel.edu> Date: 22 May 91 07:23:55 GMT References: <1991May20.201244.21948@uicbert.eecs.uic.edu> Organization: Kestrel Institute, Palo Alto, CA Lines: 43 I have just come to the conclusion, after trying for several hours, that it is not possible to write a SETF method for LET using DEFINE-SETF-METHOD. In case it's not obvious what that means, here's one not-quite-right way to do it: (define-setf-method let (clauses &rest body) (let ((storevar (gensym))) (values '() '() (list storevar) `(let ,clauses ,@(butlast body) (setf ,(car (last body)) ,storevar) (car (last body)))))) So, roughly speaking, (setf (let ((x ...)) (car x)) 'foo) turns into (let ((x ...)) (setf (car x) 'foo)). The problem with the definition above is that it potentially evaluates the subforms of the last form in the body more than once; so (incf (let ((x ...)) (car (pop x))) 3) turns into (effectively) (let ((x ...)) (setf (car (pop x)) (+ 3 (car (pop x))))) I can fix this problem, but then I get a version that doesn't correctly handle DECLARE forms immediately inside the LET being SETFed. The point is not that it can't be done -- as far as I know, it is not hard to specify what the expansion of SETF of LET should be -- but that it can't be done with the DEFINE-SETF-METHOD interface. Why would anyone want this to work? It's not unusual for macros to expand into LET forms. It's true, I could write SETF methods for each such macro individually, but I don't see why I should have to. So I'm surprised that CLtL2 doesn't specify (at least not that I've been able to find) that SETF of LET should work. Is this perhaps simply an oversight, that should be brought to the attention of X3J13? -- Scott Gyro@Reasoning.COM