On 05.10.2017 17:48, jmh530 wrote:
On Thursday, 5 October 2017 at 06:42:14 UTC, Timon Gehr wrote:
Why curly braces? Multiple function arguments are a form of built-in
tuple, so the syntax should be consistent:
auto (success, message) = callVoldemortFunction();
The only unresolved question is (as using the result of the comma
operator has been deprecated already): How to write a unary tuple. My
favourite is what python does: "(3,)". This is however already
accepted as a function argument list. I think it is worth breaking
though. Maybe we should deprecate it.
The curly bracket syntax looks straight out of DIP 32
https://wiki.dlang.org/DIP32
auto {x, y} = {1, "hi"};.
There are many good ideas in DIP32, including this one:
Basic () syntax, perhaps the cleanest, but can't be used:
----
import std.stdio, std.algorithm, std.container, std.array;
auto encode(T)(Group!("a == b", T[]) sf) {
auto heap = sf.map!((c, f) => (f, [(c, "")])).array.heapify!q{b < a};
while (heap.length > 1) {
auto (lof, loa) = heap.front; heap.removeFront;
auto (hif, hia) = heap.front; heap.removeFront;
foreach ((_, ref e); loa) e = '0' ~ e;
foreach ((_, ref e); hia) e = '1' ~ e;
heap.insert((lof + hif, loa ~ hia));
}
return heap.front[1].schwartzSort!((c, e) => (e.length, c));
}
void main() {
auto s = "this is an example for huffman encoding"d;
foreach ((c, e); s.dup.sort().release.group.encode)
writefln("'%s' %s", c, e);
}
---
The reason why back then it seemed as if it "can't be used" is that it
was taken by the comma operator. This is no longer the case.