* changing multiple-value calls in emacs code.
@ 2009-03-13 19:42 Dave Goel
2009-03-13 20:57 ` Dave Goel
2009-03-14 0:21 ` Miles Bader
0 siblings, 2 replies; 5+ messages in thread
From: Dave Goel @ 2009-03-13 19:42 UTC (permalink / raw
To: emacs-devel
There are a very few places in emacs that do things like
(multiple-value-bind). As we know, this does not in reality use any
m-v facility, mostly it is meant to bind vars to a list, rather than
to a host of values. Indeed, (values-list) is an identity.
In such cases, the right thing to do would be to change such calls:
(multiple-value-setq (a b) (foo))
to
(multiple-value-setq (a b) (values-list (foo))).
While the former is == the latter, the latter is the proper "RIGHT"
way of setq-ing a and b to members of a list.
I have committed some such changes. Please let me know if you think I did
anything wrong.
It is just a cosmetic change, since values-list just returns its
argument unchanged.
----
It is much rarer still that a function actually invokes any m-v
facility and returns (values ..) in its output. This happens only in
mh.el .. In emacs, we want to stay away using m-v, and such (values)
should be changed to (list.. ). Of course, this is again a cosmetic
change.
The uses of these values should again be used by (multiple-value-bind
... (values-list ... ))
----
I restress that any changes I made above are merely cosmetic changes.
(But, with a proper m-v facility, like the one I am proposing, these
changes will matter. Furthermore, these changes ensure that we never
use m-v facitily by default any way.)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: changing multiple-value calls in emacs code.
2009-03-13 19:42 changing multiple-value calls in emacs code Dave Goel
@ 2009-03-13 20:57 ` Dave Goel
2009-03-14 10:07 ` Tobias C. Rittweiler
2009-03-14 0:21 ` Miles Bader
1 sibling, 1 reply; 5+ messages in thread
From: Dave Goel @ 2009-03-13 20:57 UTC (permalink / raw
To: Dave Goel; +Cc: emacs-devel
I can now assure that no function in emacs tries to pass out multiple
or zero values. [not even floor* etc. which always passed
lists.].. In other words, no function invokes either (values) or
(values-list) to pass out values.
Conversely, nowhere in the entire emacs does any code expect multiple
or zero values from another function.
The latter, except for immediate self-contained invocations, such as
(multiple-value-setq (a b) (values-list <fn>))
where <fn> returns a list such as (1 2) and *not* (values 1 2).
So, if we want to install a better implementation of multiple values,
now's the time ;-) ..
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: changing multiple-value calls in emacs code.
2009-03-13 19:42 changing multiple-value calls in emacs code Dave Goel
2009-03-13 20:57 ` Dave Goel
@ 2009-03-14 0:21 ` Miles Bader
1 sibling, 0 replies; 5+ messages in thread
From: Miles Bader @ 2009-03-14 0:21 UTC (permalink / raw
To: emacs-devel
Dave Goel <deego3@gmail.com> writes:
> There are a very few places in emacs that do things like
> (multiple-value-bind). As we know, this does not in reality use any
> m-v facility, mostly it is meant to bind vars to a list, rather than
> to a host of values. Indeed, (values-list) is an identity.
>
> In such cases, the right thing to do would be to change such calls:
> (multiple-value-setq (a b) (foo))
> to (multiple-value-setq (a b) (values-list (foo))).
In cases where it uses `multiple-value-bind' in that way, instead of
adding `values-list', wouldn't it be more clear to just use
`destructuring-bind' (since that's what's actually meant)?
[The only wart is that you have to add `&rest' to the variable list if
there are values to be ignored, wheras. It seems you don't need to
actually supply a variable following the &rest though; I dunno if
omitting it saves any consing or not... destructuring-bind also does
more error-checking of the list before binding, I dunno if that's
desirable or not...]
-Miles
--
Defenceless, adj. Unable to attack.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: changing multiple-value calls in emacs code.
2009-03-13 20:57 ` Dave Goel
@ 2009-03-14 10:07 ` Tobias C. Rittweiler
2009-03-14 10:50 ` Miles Bader
0 siblings, 1 reply; 5+ messages in thread
From: Tobias C. Rittweiler @ 2009-03-14 10:07 UTC (permalink / raw
To: emacs-devel
Dave Goel <deego3@gmail.com> writes:
> Conversely, nowhere in the entire emacs does any code expect multiple
> or zero values from another function.
There's third-party code which relies on the current implementation.
Indeed, I'm among the culprits. :-)
I used to use (values ...) instead of (list ...) to convey that the
first element is the primary return value, the other elements merely
auxiliary, and that more "return values" may be added in future. (So you
cannot use `destructuring-bind' on the returned list value.)
I considered the current implementation a quirk I regretfully took for
granted.
-T.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: changing multiple-value calls in emacs code.
2009-03-14 10:07 ` Tobias C. Rittweiler
@ 2009-03-14 10:50 ` Miles Bader
0 siblings, 0 replies; 5+ messages in thread
From: Miles Bader @ 2009-03-14 10:50 UTC (permalink / raw
To: emacs-devel
"Tobias C. Rittweiler" <tcr@freebits.de> writes:
> more "return values" may be added in future. (So you
> cannot use `destructuring-bind' on the returned list value.)
destructuring-bind understands &rest, e.g.,
(destructuring-bind (a b &rest) '(1 2 3 4 5) (cons a b))
=> (1 . 2)
--
Infancy, n. The period of our lives when, according to Wordsworth, 'Heaven
lies about us.' The world begins lying about us pretty soon afterward.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-03-14 10:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-13 19:42 changing multiple-value calls in emacs code Dave Goel
2009-03-13 20:57 ` Dave Goel
2009-03-14 10:07 ` Tobias C. Rittweiler
2009-03-14 10:50 ` Miles Bader
2009-03-14 0:21 ` Miles Bader
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.