[DGD] 1.3.8
Bruce Mitchener
bruce at cubik.org
Tue Oct 6 23:25:57 CEST 2009
Felix A. Croes wrote:
>> + - Allow ({ a, b }) = array; to facilitate returning multiple values from a
>> + function.
>
> This makes possible the following:
>
> int time;
> float millisec;
>
> ({ time, millisec }) = millitime();
>
> Any kind of array can be used for assignment, not just a function return
> value. So the following will also work:
>
> int a, b, c;
>
> ({ a, b, c }) = ({ 1, 2, 3 });
>
> though this would be somewhat less efficient than performing distinct
> assignments.
On the off-chance that you find this interesting ... some time ago in
Cold, we had this feature with a couple of extensions:
==================
Scatter
In a scatter assignment, multiple variables are specified within square
brackets on the left and each element from the list expression on the
right is assigned to the respective variable on the left, with any
remaining elements in the list being discarded. For example:
[var1, var2, var3] = ["this", ["for"], 1, 'that]
In this example var1 is assigned the string "this", var2 is assigned the
list ["for"], var3 is assigned the integer 1 and the remaining symbol
'that is discarded.
The remaining elements may all be grouped in a new list which is stored
in the last variable by using the list splice operator (@) on the last
variable in the scatter list, such as:
[var1, var2, @var3] = ["this", ["for"], 1, 'that]
In this example var3 would have the value [1, 'that]. The list splice
operator may only be used this way on the last variable in the scatter list.
Scatter assignments may also be nested, assuming the list expression is
a nested list in the same order as the scatter list. For example:
[var1, [var2, @var3], var4] = ["this", ["for", 1, 2, 3], 'that]
In this example var1 is assigned "this", var2 is assigned "for", var3 is
assigned the new list [1, 2, 3] and var4 is assigned the remaining
symbol 'that.
==================
Also visible here:
http://ice.cold.org:1180/bin/help?node=$help_coldc_scatter_assign
We also had default assignment:
http://ice.cold.org:1180/bin/help?node=$help_coldc_default_assign
Which could integrate with scatter assignment:
[b, c, d, e ?= 4] = [1, 2, 3];
And 'e' would have the value 4 in that case.
I haven't written ColdC in some years, but I remember these extensions
as having been pretty useful at the time. This was also related to a
list splicing operator:
http://ice.cold.org:1180/bin/help?node=$help_coldc_splice
Cheers,
- Bruce
More information about the DGD
mailing list