A Discussion of Tuple Syntax

bearophile bearophileHUGS at lycos.com
Mon Aug 19 11:19:10 PDT 2013


Wyatt:

> The octothorpe _is_ much better than the t simply in terms of 
> readability, though, even more than q{} or t{}, I have concerns 
> about its ability to be found with an ordinary search engine by 
> an ordinary user.  Have you tried looking for documentation on 
> weird operators with a search engine lately?  They don't 
> exactly take to it well. :/ (cf. Perl's <=>)

I think none of the suggested tuple syntaxes are well searchable 
on Google, but the "tuple()" syntax.

But in the Haskell world the Hoogle direct&reverse search engine 
supports symbols too (but it's mostly used to search for 
functions given their signature, I think so far this is something 
not present in the D world):

http://www.haskell.org/hoogle/?hoogle=%3D%3E


> I even don't like how the unicode version of that one looks;

It was just an idea, to show what I meant by representing the 
bananas with Unicode glyphs. The actual choice of glyphs is not 
an urgent choice :-) The idea comes from the now dead Fortress 
language.


> I feel weird admitting this, but if we can't use some manner of 
> bare brace, I think I'd rather have tup(), tup[], tup{} (or 
> even tuple() et al) as a prefix over any single character.

At the moment I prefer #() syntax, with ? for single wildcards. 
It's better than tup{} or t{} because the # symbol pops out more 
visually. tuple() syntax is long, but it's readable, and perhaps 
partially backwards compatible.


> Can't make it a single underscore? Question mark works best 
> then, IMO.  It isn't as burdened with meanings elsewhere (sure 
> there's ternary and possibly-match in regex, but...have I 
> forgotten something?)

The ? of regexes is inside strings, so I think it causes no 
problems. And I think it doesn't clash with the ternary operator 
because before the ? wildcard you put a comma, a semicolon or a 
#(.


>> Assuming the "..." syntax for unpacking, it would be useful to 
>> name the captured tail. For example, you could unpack #(1, 3, 
>> #(4, 6)) into #(a, b, x...), where a = 1, b = 3, x = #(4, 6). 
>> Similarly, #(head, rest...) results in head = 1, rest = #(2, 
>> #(4, 6)). I think this would be very useful.

In Haskell there is also a way to give a name to the whole tuple 
and names to its parts:

Prelude> let t1 = (10, 20)
Prelude> let a@(b, c) = t1
Prelude> a
(10,20)
Prelude> b
10
Prelude> c
20

-------------------------

Meta:

> Bearophile has mentioned a couple times that we could use the 
> tuple syntax for both, and bring about a unification of these 
> two tuple types. I don't like this, as they're both very 
> different entities, and don't really have any relation to 
> each-other whatsoever.

Mine was an idea, but if it turns out to be a bad idea, then 
let's ignore it.

Bye,
bearophile


More information about the Digitalmars-d mailing list