Welcome to Web-News
A Web-based News Reader
Subject Tuple literal syntax
From Walter Bright <newshound2@digitalmars.com>
Date Wed, 06 Oct 2010 23:04:35 -0700
Newsgroups digitalmars.D

There have been a couple of looong threads about tuples:

http://www.digitalmars.com/d/archives/digitalmars/D/Reddit_why_aren_t_people_using_D_93528.html

http://www.digitalmars.com/d/archives/digitalmars/D/Should_the_comma_operator_be_removed_in_D2_101321.html

A lot of it foundered on what the syntax for tuple literals should be. The top
of the list is simply enclosing them in ( ). The problem with this is

  (expression)

Is that a parenthesized expression, or a tuple? This really matters, since
(e)[0] means very different things for the two. Finally, I got to thinking, why
not just make it a special case:


  ( ) == tuple
  (a) == parenthesized expression
  (a,b) == tuple
  (a,b,c) == tuple
  (a,b,c,d) == tuple

etc.

No ambiguities! Only one special case. I submit this special case is rare,
because who wants to define a function that returns a tuple of 1? Such will come
about from generative programming, but:

(a,b,c)[0]

may be how the generative programming works, and that suggests:

(a,0)[0]

as how a user could generate a tuple of 1. Awkward, sure, but like I said, I
think this would be rare.

Recent messages in this thread
 
-# Tuple literal syntax (Current message) Walter Bright 07-Oct-2010 02:04 am
.-# Re: Tuple literal syntax Kagamin 07-Oct-2010 02:33 am
.|\# Re: Tuple literal syntax Walter Bright 07-Oct-2010 02:41 am
.|# Re: Tuple literal syntax Jonathan M Davis 07-Oct-2010 02:41 am
.|# Re: Tuple literal syntax Denis Koroskin 07-Oct-2010 03:55 am
.-# Re: Tuple literal syntax Andrei Alexandrescu 07-Oct-2010 04:20 am
.|-# Re: Tuple literal syntax retard 07-Oct-2010 06:39 am
.|||# Re: Tuple literal syntax Kagamin 07-Oct-2010 08:06 am
.|||# Re: Tuple literal syntax Juanjo Alvarez 07-Oct-2010 08:24 am
.||-# Re: Tuple literal syntax Andrei Alexandrescu 07-Oct-2010 10:46 am
.||.-# Re: Tuple literal syntax retard 07-Oct-2010 11:12 am
.||..-# Re: Tuple literal syntax Simen kjaeraas 07-Oct-2010 11:22 am
.||...|# Re: Tuple literal syntax Andrei Alexandrescu 07-Oct-2010 11:36 am
.||...\# Re: Tuple literal syntax retard 07-Oct-2010 11:39 am
.|\# Re: Tuple literal syntax Michel Fortin 07-Oct-2010 11:01 am
.-# Re: Tuple literal syntax Justin Johansson 07-Oct-2010 08:23 am
.|\# Re: Tuple literal syntax Andrei Alexandrescu 07-Oct-2010 10:56 am
.-# Re: Tuple literal syntax Ellery Newcomer 07-Oct-2010 09:23 am
.|\# Re: Tuple literal syntax Justin Johansson 07-Oct-2010 09:34 am
.|# Re: Tuple literal syntax Simen kjaeraas 07-Oct-2010 10:02 am
.|# Re: Tuple literal syntax Michel Fortin 07-Oct-2010 12:19 pm
.-# Re: Tuple literal syntax Juanjo Alvarez 07-Oct-2010 03:44 am
..|# Re: Tuple literal syntax Don 07-Oct-2010 03:58 am
..\# Re: Tuple literal syntax Olivier Pisano 07-Oct-2010 10:54 am