deadalnix:
http://blog.thebird.nl/?p=93
...
I spreaded the word. This article is great and I 100% agree
with it :D
The article says:
There are a few things I miss in D. For example pattern
recognition on unpacking data, which is great in Haskell,
Erlang, and Scala (see example
[http://www.scala-lang.org/node/120 ]).<
The author of that article has missed that D lacks something much
simpler than pattern matching, and even more commonly useful.
Currently in D you have to write something like:
int[2][] directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];
foreach (sx_sy; directions) {
immutable sx = sx_sy[0];
immutable sy = sx_sy[1];
// code that uses sx and sy
While a less clunky language allows you to unpack them better,
something like:
auto directions = [tuple(-1, 0), tuple(1, 0), tuple(0, -1),
tuple(0, 1)];
foreach (immutable (sx, sy); directions) {
// code that uses sx and sy
If you use tuples, you want to unpack them often, it's a basic
operation on tuples.
Bye,
bearophile