-------------------------------------------------------------------------
ABSTRACT
----------
This TIP proposes a multiple assignment command as a
backwards-compatible extension to the Tcl _set_ command.
INTRODUCTION
--------------
Often one needs to assign values to several variables in close
proximity. Right now several _set_ commands are necessary:
set a 123
set b 456
or
set a 123; set b 456
Or one abuses the _foreach_ command:
foreach {a b} {123 456} break
However, by analogy to the _variable_ and _array set_ commands, the
following would be useful:
set a 123 b 456
This would assign 123 to the variable _a_ and 456 to the variable _b_.
Note that this extension is backwards-compatible to existing uses of
the _set_ command since until now only one or two arguments to _set_
were allowed.
SPECIFICATION
---------------
The _set_ command is extended to allow either one or an even number of
arguments. The behaviour in the case of one argument remains the one
documented in the _set_ manual page; when an even number of arguments
is specified, the behaviour of _set v0 e0 ... vn en_ is identical to
that of the sequence of commands _set v0 e0; ...; set vn en_ according
to the traditional semantics.
The command _set v0 e0 ... vn en_ returns the value of _en_.
RATIONALE
-----------
This extension is an obvious analogy to the _variable_ and _array set_
commands of Tcl, both of which allow an alternating list of names and
expressions to be given as arguments. It is completely
backwards-compatible (_set_ invocations with more than two arguments
used to be syntax errors) and very easily implemented.
This extension in no way prejudices against the adoption and use of
other multiple-assignment commands, such as _lassign_ (see [TIP #57]).
In particular, the _set_ extension is unsuitable for assigning a list
result to a number of variables element by element. However, its
simplicity and consistency to other similar Tcl commands is appealing.
REFERENCE IMPLEMENTATION
--------------------------
A patch to Tcl 8.4a3 which implements the _set_ extension may be found
at <URL:http://anselm.our-isp.org/set-patch.diff> - a patched Tcl 8.4a3
passes the Tcl 8.4a3 regression test suite with no test failures. No
test cases nor documentation for the _set_ extensions have been devised
yet but this is easy to do once there is a consensus that this feature
is actually desirable.
COPYRIGHT
-----------
This document is placed in the public domain.
-------------------------------------------------------------------------
TIP AutoGenerator - written by Donal K. Fellows
[[Send Tcl/Tk announcements to tcl-an...@mitchell.org
Send administrivia to tcl-announ...@mitchell.org
Announcements archived at http://groups.yahoo.com/group/tcl_announce/
The primary Tcl/Tk archive is ftp://ftp.neosoft.com/pub/tcl/ ]]
Bruce
"Anselm Lingnau" <ans...@strathspey.org> wrote in message news:pgpmoose.2001...@non.non.net...
The particular thing I like is being able to do a one-command swap:
set x $y y $x
Donal.
--
Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ fell...@cs.man.ac.uk
-- I could even declare myself a religion, if that'd help.
-- Mark Loy <ml...@iupui.edu>
Bruce