Tcl Source Code

View Ticket
Login
Ticket UUID: 1880941
Title: lassign behavior on excess arguments
Type: RFE Created on: 2008-01-28 03:42:22
Submitter: coldstore Assigned to: dgp
Subsystem: 16. Commands A-H Severity:
Priority: 5 Medium Last modified: 2008-01-29 06:55:31
Status: Open Closed by:
Resolution: None Closed on:
Version: None
Description:
[set y 1; lassign a x y; set y] returns "", I think it should return 1.

Commonly [lassign] is used to assign a list of values to variables, as (for example) a way of interpreting multiple return values.

In the case that there's no value, it's useful to be able to assign a default.  The proposed behavior, that unmatched variables be left alone, permits one to implement defaulting behavior, example:

  lassign $defaults x y z
  lassign [function] x y z

Where the current behavior requires a fairly tedious series of [if] if one needs to distinguish between defaulted values and "".
User Comments:
dgp added on 2008-01-28 21:53:30:
Logged In: YES 
user_id=80530
Originator: NO

see also 1671880

dkf added on 2008-01-28 22:02:08:
Logged In: YES 
user_id=79902
Originator: NO

The proposed change is more expensive to implement (needs more elaborate bytecode generation).

coldstore added on 2008-01-29 00:06:06:
Logged In: YES 
user_id=19214
Originator: YES

I find it counterintuitive that (as dkf claims) not touching a variable leads to more bytecode than initializing it to "", but it may well be the case.

dkf added on 2008-01-29 06:55:31:
Logged In: YES 
user_id=79902
Originator: NO

It's because [lindex {1 2 3} 4] is {} (not an error) and in the no-assign case I'd need to generate extra code to detect when the list is exhausted and stop assigning. Right now, I generate jump-free code...