Version 0 of Multi-assign

Updated 2003-09-11 08:24:13

This page split out from Tcl 9.0 WishList


FW: Optimize the idiom

  foreach {a b} {1 2} break

to be byte-compiled automatically into a series of set operations, making it no longer a major slow-down for small utility procedures that are run repeatedly.

jcw - How about extending "set" a teeny bit? Perhaps like this:

   % set a b c {1 2 3}
   1 2 3
   % set a
   1
   % set b
   2
   % set c
   3
   %

FW: I was gonna suggest that, but that's a more dramatic change. In an ideal world, both would happen, but Tcl gets changed extremely slowly, so it'd be idealistic to suggest both at once ;)

rmax: I think both changes would even be allowed in a minor release, as the foreach optimization doesn't change behaviour at all, and the set extension only makes a backwards compatible change.

DKF: There's a currently Draft TIP on extending the set command, and it is really unpopular with the TCT. We're kind-of hoping the author will withdraw the TIP sometime so we don't have to be mean and vote the suggestion down. FWIW, the consensus seems to be that the set command is inviolate, even across major versions.

DKF: The TIP in question is #58[L1 ] and it looks like it will be rejected outright (as I write this, the vote is in progress but there have been many votes against and none for.)

DKF: Yep. Utter rejection. Anyone wanting to modify set had better not rely on core mods to do it!

FW: Does the TCT have an opinion on the foreach mod idea? :)

DKF: Try TIP #57[L2 ] instead, though perhaps recognizing the foreach-as-multi-set idiom and getting smart with it may be done at some point too.

FW: The thing is, the current idiom is just as understandable, already in use, and doesn't add a new command just for sugar.

DKF: If we put TclX's lassign in the core, I think you'll find that that does rather more than the foreach idiom. :^)


Category Suggestions