Kenneth Tilton
7/10/2015 8:52:00 AM
On Thursday, July 9, 2015 at 11:18:24 AM UTC-4, Jim Newton wrote:
> For example if I have a function FOO which returns (values a b c)
> I'd like to write three accessor functions which return the a, b, and c respectively.
>
> I know several ways to write this, but i'm not sure which is the most efficient.
>
> (define get-1 (x)
> (multiple-value-bind (a b c) (FOO x)
> (declare (ignore b c))
> a)))
>
> (define get-2 (x)
> (multiple-value-bind (a b c) (FOO x)
> (declare (ignore a c))
> b)))
>
> (define get-3 (x)
> (multiple-value-bind (a b c) (FOO x)
> (declare (ignore a b))
> c)))
Wow, what a train wreck.
As Kaz pointed out: define?
As Matthew wondered: nth-value? Too easy?
My minor quibble is that you said you could think of several ways then typed in several functions all using the same way. Hunh?
Next up: efficiency? You see this as a performance issue? What are we worried about here, ram or cpu?
But here is the whopper and I am disappointed the yobbos of c.l.l seem to have gotten no better since Himself last dwelt here regularly and have obediently gone to work on giving you what you want instead of pointing out you do not want for what you asked: an accessor dedicated to a selected multiple value?! You must be abusing multiple values.
OK, the spec includes nth-value, but the spec includes everything. An application hiding nth-value behind an accessor is abuse, not completeness.
Himself just checked 100kloc of lisp and found one use of nth-value: postmodern's query returns the number of records affected as a second value and I am just verifying that, in my case, an update I know should update something updated something.
Multiple values are used to return "oh, by the way" information ancillary to the function result and it is inconceivable that dedicated accessors would be needed for ancillary results.
What are you up to over there?
-hk