flightaware / Tcl-bounties

Bounty program for improvements to Tcl and certain Tcl packages
104 stars 8 forks source link

Intent to work on "array default arrayName value" #9

Closed ahumph closed 3 years ago

ahumph commented 7 years ago

I have a basic patch ready for this. Usage would be as follows:

% array set a [list one 1]
% array default [list a 0]
% puts %a(one)
1
% puts $a(three)
0
% set b(one) 1
% puts $b(two)
can't read "b(two)": no such element in array
% parray a
one 1
% parray b
one 1
% array default [list a 2 b 3]
% puts $a(two)
2
% puts $b(two)
3

If there are any comments on this usage let me know, and I can modify before submitting a TIP.

Edit: Fixed return for $b(two)

zvr commented 7 years ago

On the sixth command, why would $b(two) evaluate to 0, when no default has been declared for array b?

And I would discuss whether referencing a hitherto non-existing element (and getting the default value) should actually create the array element. In other words, maybe the parray in the example above should include the values for two as well.

ahumph commented 7 years ago

Ah that was a typo. If no default is set the standard TCL error message is returned.

Currently the non existing elements are not created, but this can be added pretty simply. Alternatively, an extra argument could be added to make this optional.

ahumph commented 7 years ago

Any update on this issue?

Specifically: is creation of a requested non-existing element desired, and if so, should it be optionally specified in the command?

resuna commented 6 years ago

Looking at this now.

Why a list of {array-name value...}?

What's wrong with multiple [array default array_name value]?

The value should not be instantiated in the array.

dkfellows commented 6 years ago

I confirm that an implementation of array default will be available from the next release of Tcl 8.7, using code linked to #31; I believe that this issue can be Closed.

UnitedMarsupials commented 3 years ago

Two years later, this is still labeled as an open item -- is it?