From: Jeff Siegal
Subject: Re: Multiple Return values in Common Lisp.
Date: 
Message-ID: <4174@mit-eddie.MIT.EDU>
In article <····@sunybcs.UUCP> ······@sunybcs.UUCP (James Geller) writes:
>[...]
>It would be much more reasonable to create a calling convention that
>permits to access the different return values at different points.
>
>Example:
>
>          (defun extent (rectangle-name)
>[comments omitted]
>               .......)
>
>          (defun perimeter (rectangle-name)
>[comments omitted]
>                 (+ (* (extent/1 rectangle-name) 2)
>                    (* (extent/2 #*) 2)))
>
>Its just that I had to write a number of functions lately that
>would have benefited from above mechanism. 

As has been mentioned before, multiple-value-bind is the probable
solution

>Example:
>
>         (defun square-of-hard-to-get-number (argument)
>             (* (long-computation argument)
>                (long-computation #*)))
>
>People who don't hesitate to use a "setq" will not understand
>why I don't write:
>
>         (defun square-of-hard-to-get-number (argument)
>
>             (* (setq dummy (long-computation argument))
>                dummy))
>
>But I have been raised in the tradition of functional programming.
>
>[code omitted]

To see why wanting the #* form is not consistent with functional
programming, let's look at an (sub-optimal) implementation (yes,
you may use this in your own programs):

(setq *applyhook*
  #'(lambda (funct args env)
      (if (symbolp funct)
	  (let ((last-call-result-symbol
		 (intern (concatenate "prev-call-result-#"
				      (print-name funct)))))
	    (if (eq (car args) '|#*|)
		(let ((*applyhook* nil))
		  (symbol-value last-call-result-symbol))
	        (set last-call-result-symbol 
		     (applyhook funct
				args
				*evalhook*
				*applyhook*
				env)))))))

Now, what do we find within this code?  None other than "set", which
is what you were trying to avoid.  You've removed the state variable
from the program by putting it into the interpreter.

If anyone does decide to use (or even test) this code, please 
let me know, since I didn't actually test it.

Jeff Siegal