[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
define and set! with multiple values
- To: firstname.lastname@example.org
- Subject: define and set! with multiple values
- From: email@example.com
- Date: Thu, 31 Dec 92 11:56:44 EST
- Posted-date: Thu, 31 Dec 92 11:56:44 EST
Jonathan Bachrach (Jonathan.Bachrach%ircam.FR@princeton.edu) writes:
I propose to extend `set!' and `define' to allow accomodate
multiple-values. The syntax would be:
(SET! PLACE-1 PLACE-2 ... NEW-VALUE) => NEW-VALUE
I think the goal is a good one, but I'd suggest a different syntax:
using a VALUES form as the place instead:
(SET! (VALUES PLACE-1 PLACE-2 ...) NEW-VALUE)
Or, translating your later example:
(SET! (VALUES X Y) (LOCATION WINDOW))
I believe this has a number of advantages. First, the current
(simpler) syntax is retained: SET! still takes two arguments, a place
form and a new-values form. Thus, multiple values are not treated as
a (particularly) special case.
Second, conceptual clarity: SET! can still be explained as it
currently is on page 61:
Subsequent evaluations of PLACE will yield NEW-VALUE.
Again using your example, (VALUES X Y) is made to return whatever
(LOCATION WINDOW)) returns, by in turn altering X and Y. In another
example, SET! can be used to swap two (or "rotate" more) values, e.g.
(SET! (VALUES OLD NEW) (VALUES NEW OLD))
This can be done with your syntax, but I find the above much clearer
(SET! OLD NEW (VALUES NEW OLD))
Third, the VALUES syntax is more compatible with other Lisps,
including CommonLisp, where the VALUES form of SETF is a common
extension. Moreover, the CommonLisp analogue, SETF, actually takes
any number of place/new-value pairs, e.g.
(SETF PI (COMPUTE-PI 10)
HALF-PI (/ PI 2))
Your proposal would disallow this.
Finally, the VALUES syntax could be implemented (probably) with a
macro extension to SET!, as is usually done in CommonLisp. I think
this is in line with what Patrick Logan (firstname.lastname@example.org)
I would rather see your goals met by using a more general solution:
macros (i.e. syntax extensions).
Your proposal requires completely NEW syntax, however.
As for extending DEFINE! in a similar manner, I think that could be
done using the VALUES syntax as well, though I find it less important
than for SET! case.