From: Paul Vaughan
Subject: multiple values and conditionals
Date: 
Message-ID: <886@cadillac.CAD.MCC.COM>
This is a specification for a multiple-value handling OR construct.  It
behaves like the traditional OR, but returns all the values of the first
form which returns a non-nil first value.  (The usual OR does this only
if the first such form is the last form, otherwise, it returns only the
first value.)

(defmacro mv-or (&rest forms)
  (cond ((null forms) nil)
	((null (cdr forms)) (first forms))
	(t (let ((values-symbol (gensym "VALUES")))
	     `(let ((,values-symbol (multiple-value-list ,(first forms))))
		(if (car ,values-symbol) (values-list ,values-symbol)
		    (mv-or . ,(cdr forms))))))))

I might use it in a function that did something like

(defun lookup (key primary-table secondary-table)
  (declare (values value found found-key))
  (mv-or (gethash key primary-table) (gethash key secondary-table)))

Somebody please tell me why such a thing is stupid, unnecessary, or
should never arise.

 Paul Vaughan, MCC CAD Program | ARPA: ·······@mcc.com | Phone: [512] 338-3639
 Box 200195, Austin, TX 78720  | UUCP: ...!cs.utexas.edu!milano!cadillac!vaughan

From: Barry Margolin
Subject: Re: multiple values and conditionals
Date: 
Message-ID: <39643@think.UUCP>
In article <···@cadillac.CAD.MCC.COM> ·······@puma.cad.mcc.com (Paul Vaughan) writes:
>This is a specification for a multiple-value handling OR construct.
...
>Somebody please tell me why such a thing is stupid, unnecessary, or
>should never arise.

As you've shown, there's a perfectly good use for such a construct.
Perhaps your real question is why the built-in OR construct doesn't
behave this way.  For the same reason that there's a PROG1 and a
MULTIPLE-VALUE-PROG1: allocating space for a single temporary is
easier than doing it for arbitrary-length temporaries.

Barry Margolin
Thinking Machines Corp.

······@think.com
{uunet,harvard}!think!barmar
From: Dan Hoey
Subject: Re: multiple values and conditionals
Date: 
Message-ID: <293@ai.etl.army.mil>
In article <···@cadillac.CAD.MCC.COM> ·······@puma.cad.mcc.com (Paul Vaughan)
writes of a multiple-value OR, specified to return all the values of the
first form that returns a non-NIL first value.  He motivates it with

>(defun lookup (key primary-table secondary-table)
>  (declare (values value found found-key))
>  (mv-or (gethash key primary-table) (gethash key secondary-table)))

But in this case we probably want a MV-OR that returns the values of the
first form to return a non-NIL *second* value.  Furthermore, using a
generalized MV-OR requires MULTIPLE-VALUE-LIST, which conses; for combining
results of GETHASH we prefer MULTIPLE-VALUE-BIND or MULTIPLE-VALUE-SETQ, which
generate no garbage but must be written with knowledge of the number of values
to handle.

Dan