Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!ucsd!casbah.acns.nwu.edu!ils.nwu.edu!riesbeck From: riesbeck@ils.nwu.edu (Chris Riesbeck) Newsgroups: comp.lang.lisp.x Subject: Re: Can I do multiple value returns in X-Lisp? Message-ID: <791@anaxagoras.ils.nwu.edu> Date: 1 Feb 91 17:49:11 GMT References: <470@oha.UUCP> Sender: news@ils.nwu.edu Reply-To: riesbeck@ils.nwu.edu (Chris Riesbeck) Organization: The Institute for the Learning Sciences Lines: 39 In article <470@oha.UUCP>, tony@oha.UUCP (Tony Olekshy) writes: > I am trying to write a macro that sets the value of each symbol in a list > of symbols to the corresponding value from a list of values (presumably > returned by a function. But when I try the following, the global foo and > bar are set, not those local to the let, which is what I want. Reading > leads me to believe that this a property of set, so I have tried screwing > around with setq to no avail. Does anyone have a lantern? > > (defmacro setset (names vals) > `(mapcar (lambda (n v) (set n v)) ,names ,vals)) > > (defun baz () (list 234 436)) > > (let (foo bar) > (setset '(foo bar) (baz)) > (print (list foo bar)) > ) SET, like EVAL, only works on globals. There's a better way to do this, by defining something that looks like Common Lisp's multiple value forms. (defun values (&rest args) args) ;;for clarity (defmacro multiple-value-bind (vars exp &rest body) `(apply #'(lambda ,vars ,@body) ,exp)) (defun baz () (values 234 436)) (multiple-value-bind (foo bar) (baz) (print (list foo bar))) => (234 436) The nice thing about this is that if you move to Common Lisp, you're code could potentially be more efficient, no longer constructing and deconstructing lists. Chris Riesbeck --------------