A Discussion of Tuple Syntax
bearophile
bearophileHUGS at lycos.com
Fri Aug 16 16:48:52 PDT 2013
Meta:
> Andrei/Walter didn't want to merge that pull request without a
> full consideration of the different design issues involved,
> which in retrospect was a good decision.
I agree that before adding some new syntax you have to think well.
> - {a, b} is not as pretty, but it's not that bad of an
> alternative (though it may still have issues as well)
It has technical issues, they were discussed in one of the last
threads. Such problems should be added in a note in the DIP32, so
they don't get lost in time.
> - #(a, b) is unambiguous and would probably be the easiest
> option. I don't think it looks too bad, but some people might
> find it ugly and noisy
It looks nice (but I don't know if it's technically usable), I
have added it at the end of the list of alternative syntaxes:
http://wiki.dlang.org/DIP32#Use_case_of_uniform_tuple_syntax
> I personally think #(a, ?) or #(a, *) would be best, but all
> that's really necessary is a symbol that cannot also be an
> identifier.
I think ? is clear, unambiguous, etc, and I like it. The * is
already used for pointers, product, dereferencing, ** is used for
pow, so it's better to not add further meanings to it.
> - Concatenating tuples with ~. This is nice to have, but not
> particularly important.
In theory I like this operation, but in practice in my D code I
don't need it often, so I think it should be left out, for later.
In Python I sometimes concatenate tuples, but in such use cases
they are essentially immutable dynamically typed arrays, losing
their positional meaning.
Tuples could also be used in switch/case statements, to support a
very basic form of pattern matching. See also a standard method
named "unapply" I have discussed a bit here, coming from Scala
language, that is a very simple solution to solve a significant
problem:
http://d.puremagic.com/issues/show_bug.cgi?id=596
Bye,
bearophile
More information about the Digitalmars-d
mailing list