Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tuple Format?

0 views
Skip to first unread message

Gene C

unread,
Aug 31, 2000, 4:43:50 PM8/31/00
to
Has anyone considered a different format for tuples to get around the
somewhat strange single element tuple format? I find when explaining the
language to others, the single tuple format always solicits a, "Thats
weird."

For example, instead of (x,) how about <x>
and (a, b, c) would be <a, b, c>

Thanks


Moshe Zadka

unread,
Sep 1, 2000, 7:25:49 AM9/1/00
to Gene C, pytho...@python.org
On Thu, 31 Aug 2000, Gene C wrote:

> Has anyone considered a different format for tuples to get around the
> somewhat strange single element tuple format? I find when explaining the
> language to others, the single tuple format always solicits a, "Thats
> weird."

That's because you're not explaining it correctly. Paraphrasing the NRA,
"parens don't build tuples, commas build tuples". Parens serve only
the purpose of disambiguating. Now,

"1" is a number
"1, 2," is a tuple.
The last comma is optional, so
"1, 2" is a tuple too.
There is only one case where the comma isn't optional: where it would
otherwise cause an ambiguty
--
Moshe Zadka <mos...@math.huji.ac.il>
There is no IGLU cabal.
http://advogato.org/person/moshez


Cliff Crawford

unread,
Sep 1, 2000, 9:13:48 AM9/1/00
to
* Gene C <gchiar...@yahoo.com> menulis:

Good idea, but it would be hard to parse..for example:

# tuple of booleans

< a==b, c>d, e!=f >


--
http://www.people.cornell.edu/pages/cjc26/ "This is what his platitudes
amount to, although, of course, they're daubed over with the viscid slobber
of demented drivel devised by his henchmen and mindlessly multiplied by
treasonous heartless pissants. And that, in my view, is our real problem."

Rainer Deyke

unread,
Sep 1, 2000, 11:04:51 AM9/1/00
to
"Moshe Zadka" <mos...@math.huji.ac.il> wrote in message
news:Pine.GSO.4.10.10009011423130.22219-100000@sundial...

> On Thu, 31 Aug 2000, Gene C wrote:
> "1" is a number
> "1, 2," is a tuple.
> The last comma is optional, so
> "1, 2" is a tuple too.
> There is only one case where the comma isn't optional: where it would
> otherwise cause an ambiguty

(,) is a tuple.


--
Rainer Deyke (ro...@rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor


Duncan Booth

unread,
Sep 1, 2000, 11:12:11 AM9/1/00
to
ro...@rainerdeyke.com (Rainer Deyke) wrote in
<nAPr5.117279$6y5.78...@news2.rdc2.tx.home.com>:

>(,) is a tuple.

Actually it is a syntax error.

Rainer Deyke

unread,
Sep 1, 2000, 12:25:16 PM9/1/00
to
"Duncan Booth" <dun...@rcp.co.uk> wrote in message
news:8FA2A8E92du...@194.238.50.13...

Argh! I've gotten too used to thinking of tuples as being designated by
commas. The empty tuple is, of course, (), which involes no commas at all.
So much for consistency!

Grant Edwards

unread,
Sep 1, 2000, 1:11:26 PM9/1/00
to
In article <Pine.GSO.4.10.10009011423130.22219-100000@sundial>, Moshe Zadka wrote:
>On Thu, 31 Aug 2000, Gene C wrote:
>
>> Has anyone considered a different format for tuples to get around the
>> somewhat strange single element tuple format? I find when explaining the
>> language to others, the single tuple format always solicits a, "Thats
>> weird."
>
>That's because you're not explaining it correctly. Paraphrasing the NRA,
>"parens don't build tuples, commas build tuples".

What about ()?

It's a tuple, but there are no commas, only parens.

--
Grant Edwards grante Yow! .. Like I always
at say -- nothing can beat
visi.com the BRATWURST here in
DUSSELDORF!!

Quinn Dunkan

unread,
Sep 1, 2000, 5:53:30 PM9/1/00
to
On Fri, 01 Sep 2000 17:11:26 GMT, Grant Edwards <g...@nowhere.none> wrote:
>In article <Pine.GSO.4.10.10009011423130.22219-100000@sundial>, Moshe Zadka wrote:
>>On Thu, 31 Aug 2000, Gene C wrote:
>>
>>> Has anyone considered a different format for tuples to get around the
>>> somewhat strange single element tuple format? I find when explaining the
>>> language to others, the single tuple format always solicits a, "Thats
>>> weird."
>>
>>That's because you're not explaining it correctly. Paraphrasing the NRA,
>>"parens don't build tuples, commas build tuples".
>
>What about ()?

The single tuple format *is* weird. The tutorial says so: "A special
problem is the construction of tuples containing 0 or 1 items: the syntax
has some extra quirks to accommodate these." Python has some weird bits.
They're generally not seriously weird, though.

There have been a few random discussions about alternate ways to write tuples,
but nothing is likely to change, because it would be grossly incompatible for
not much gain. Other python-like languages approach this in different ways,
for example, ruby has no tuples, but has a 'freeze' method which marks an
object as immutable. To each their own :)

John W. Baxter

unread,
Sep 1, 2000, 9:29:51 PM9/1/00
to
In article <B1Xr5.8502$6E.22...@ptah.visi.com>, g...@nowhere.none
(Grant Edwards) wrote:

> Had standard keyboards and charsets just one more set of
> delimiters I imagine that this "wierd bit" wouldn't be there
> at all.

Syntax expands to fill the delimiters available.

--John

--
John W. Baxter Port Ludlow, WA USA jwb...@scandaroon.com

Grant Edwards

unread,
Sep 1, 2000, 7:33:53 PM9/1/00
to
In article <slrn8r09ho...@krone.ugcs.caltech.edu>, Quinn Dunkan wrote:

>>>> Has anyone considered a different format for tuples to get
>>>> around the somewhat strange single element tuple format? I find
>>>> when explaining the language to others, the single tuple format
>>>> always solicits a, "Thats weird."
>>>
>>>That's because you're not explaining it correctly. Paraphrasing
>>>the NRA, "parens don't build tuples, commas build tuples".
>>
>>What about ()?
>
>The single tuple format *is* weird. The tutorial says so: "A
>special problem is the construction of tuples containing 0 or 1
>items: the syntax has some extra quirks to accommodate these."
>Python has some weird bits. They're generally not seriously
>weird, though.

Had standard keyboards and charsets just one more set of


delimiters I imagine that this "wierd bit" wouldn't be there
at all.

--
Grant Edwards grante Yow! LOOK!!! I'm WALKING
at in my SLEEP again!!
visi.com

Moshe Zadka

unread,
Sep 2, 2000, 2:32:04 AM9/2/00
to Grant Edwards, pytho...@python.org
On Fri, 1 Sep 2000, Grant Edwards wrote:

> In article <Pine.GSO.4.10.10009011423130.22219-100000@sundial>, Moshe Zadka wrote:
> >On Thu, 31 Aug 2000, Gene C wrote:
> >
> >> Has anyone considered a different format for tuples to get around the
> >> somewhat strange single element tuple format? I find when explaining the
> >> language to others, the single tuple format always solicits a, "Thats
> >> weird."
> >
> >That's because you're not explaining it correctly. Paraphrasing the NRA,
> >"parens don't build tuples, commas build tuples".
>
> What about ()?
>
> It's a tuple, but there are no commas, only parens.

Right you are! This is the special case, not the 1-element tuple.
But people don't have a problem with this, and it even looks nice.

Alex Martelli

unread,
Sep 2, 2000, 6:10:34 AM9/2/00
to
"Moshe Zadka" <mos...@math.huji.ac.il> wrote in message
news:Pine.GSO.4.10.10009020931130.4823-100000@sundial...
[snip]

> > What about ()?
> >
> > It's a tuple, but there are no commas, only parens.
>
> Right you are! This is the special case, not the 1-element tuple.

I disagree. For any N, an N-element tuple is normally
written with N-1 commas.

Except for N==0, where N (0) commas are required; and
N==1, where N (1) commas are required. So, 0 and 1 are
both special-cases in this sense.

An N-element tuple *may* be written with N commas
(putting an 'extra' one after the last element). If N is
0 or 1, the N-element tuple *must* be written with N
commas.


Alex

Gene C

unread,
Sep 2, 2000, 9:39:14 AM9/2/00
to
Right, it was just a suggestion. I still think the list [] and dictionary {}
formats are quite elegant. I only wish the tuple could be implemented in a
similar manner. (Keeping the current format so tuples in the current format
is not broken.)

What about using the pipe to define tuples?

Empty Tuple ||
1 Element Tuple |'a'|
3 Element Tuple |'a', 'b', 'c'|

That looks nice to me and now we have no special cases and I don't think
this clashes with anything in the language.

Gene

"Cliff Crawford" <cj...@nospam.cornell.edu> wrote in message
news:slrn8qvb36...@synecdoche.sowrong.org...

Grant Edwards

unread,
Sep 2, 2000, 11:32:55 AM9/2/00
to
On Sat, 02 Sep 2000 13:39:14 GMT, Gene C <gchiar...@yahoo.com> wrote:
>Right, it was just a suggestion. I still think the list [] and dictionary {}
>formats are quite elegant. I only wish the tuple could be implemented in a
>similar manner. (Keeping the current format so tuples in the current format
>is not broken.)
>
>What about using the pipe to define tuples?
>
>Empty Tuple ||
>1 Element Tuple |'a'|
>3 Element Tuple |'a', 'b', 'c'|

Same problem as with using < and >, it's aready a binary
operator, so the syntax is a bit ambiguous. One thought would
be to use the single quotes for tuple delimiters (as in `a,b,c'
or `x' or `'). This has the advantage (in my mind) of reminding
one that tuples are like strings: immutable.

Nope, the only reasonable solution is an entirely new set of
delimiters for tuples. Everybody please queue up on left to
have your keyboards replaced.

--
Grant Edwards grante Yow! Yow! And then we
at could sit on the hoods of
visi.com cars at stop lights!

John W. Baxter

unread,
Sep 2, 2000, 11:34:59 AM9/2/00
to
In article <6q7s5.19214$C42.7...@newsread2.prod.itd.earthlink.net>,
"Gene C" <gchiar...@yahoo.com> wrote:

> Right, it was just a suggestion. I still think the list [] and dictionary
> {}
> formats are quite elegant. I only wish the tuple could be implemented in
> a
> similar manner. (Keeping the current format so tuples in the current
> format
> is not broken.)
>
> What about using the pipe to define tuples?
>
> Empty Tuple ||
> 1 Element Tuple |'a'|
> 3 Element Tuple |'a', 'b', 'c'|
>
> That looks nice to me and now we have no special cases and I don't think
> this clashes with anything in the language.

With | .... | one has similar opportunities to confuse the compiler and
get strange error messages as with ' or " by leaving one off, or having
one too many.

It's really nicer to have character pairs to work with.

Rainer Deyke

unread,
Sep 2, 2000, 11:54:40 AM9/2/00
to
"Gene C" <gchiar...@yahoo.com> wrote in message
news:6q7s5.19214$C42.7...@newsread2.prod.itd.earthlink.net...

> Right, it was just a suggestion. I still think the list [] and dictionary
{}
> formats are quite elegant. I only wish the tuple could be implemented in a
> similar manner. (Keeping the current format so tuples in the current
format
> is not broken.)
>
> What about using the pipe to define tuples?
>
> Empty Tuple ||
> 1 Element Tuple |'a'|
> 3 Element Tuple |'a', 'b', 'c'|
>
> That looks nice to me and now we have no special cases and I don't think
> this clashes with anything in the language.

a = ||||||||

Is a (the empty tuple binary_or the empty tuple) binary_or the empty tuple
(() | () | () in current notation)?

Or is it the tuple containing the tuple containing the tuple containing the
empty tuple (((((),),),) in current notation)?

Either way, can you read it?

Even ignoring binary or, what about this:

||-||||

Is this the empty tuple minus the tuple containing the empty tuple (()-((),)
in the old notation) or the tuple containing the tuple containing the
opposite of the empty tuple (((-(),),) in the old notation)?

Gene C

unread,
Sep 2, 2000, 1:16:32 PM9/2/00
to
I think I like this idea the best.

Thanks for all the feedback. Now who wants to try and convince Guido? lol

"Grant Edwards" <nob...@nowhere.nohow> wrote in message
news:H49s5.8547$6E.22...@ptah.visi.com...

Erik Max Francis

unread,
Sep 2, 2000, 1:10:50 PM9/2/00
to
Grant Edwards wrote:

> One thought would
> be to use the single quotes for tuple delimiters (as in `a,b,c'
> or `x' or `'). This has the advantage (in my mind) of reminding
> one that tuples are like strings: immutable.

Then how would you ever distinguish between the _string_ 'a,b,c' and the
_tuple_ ('a','b','c')?

--
Erik Max Francis / m...@alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ I won't pretend / That I intend to stop living
\__/ Sade
Alcyone Systems / http://www.alcyone.com/
Alcyone Systems, San Jose, California.

Erik Max Francis

unread,
Sep 2, 2000, 1:45:16 PM9/2/00
to
Gene C wrote:

> I think I like this idea the best [using || to delimit tuples].

It has a major flaw; having separate tokens for the beginning and end of
tuples would be nearly mandatory, because of the ambiguities you can get
due to the legality of nested tuples.

--
Erik Max Francis / m...@alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE

/ \ Light ... more light!
\__/ (the last words of Goethe)
blackgirl international / http://www.blackgirl.org/
The Internet resource for black women.

Ben Wolfson

unread,
Sep 2, 2000, 3:09:27 PM9/2/00
to
On Sat, 02 Sep 2000 15:32:55 GMT, nob...@nowhere.nohow (Grant Edwards)
wrote:

>Same problem as with using < and >, it's aready a binary
>operator, so the syntax is a bit ambiguous. One thought would
>be to use the single quotes for tuple delimiters (as in `a,b,c'
>or `x' or `'). This has the advantage (in my mind) of reminding
>one that tuples are like strings: immutable.
>
>Nope, the only reasonable solution is an entirely new set of
>delimiters for tuples. Everybody please queue up on left to
>have your keyboards replaced.

Backticks! They currently don't do anything, as far as I can tell, that
repr() doesn't.

`a,b,c`

--
Barnabas T. Rumjuggler's page of dumbth: members.home.net/rumjuggler

Si puer cum puellula
Moraretur in cellula
Felix coniunctio!
-- Carmina Burana

Carel Fellinger

unread,
Sep 2, 2000, 3:17:31 PM9/2/00
to
Alex Martelli <ale...@yahoo.com> wrote:
...

> I disagree. For any N, an N-element tuple is normally
> written with N-1 commas.

> Except for N==0, where N (0) commas are required; and
> N==1, where N (1) commas are required. So, 0 and 1 are
> both special-cases in this sense.

> An N-element tuple *may* be written with N commas
> (putting an 'extra' one after the last element). If N is
> 0 or 1, the N-element tuple *must* be written with N
> commas.

So 2-and-up element tuples are the special case, as
a N-tuple has to be written with N commas, but as a
special case 2-and-up element tuples may omit the last one.

How is that for turning things upside down:)
--
groetjes, carel

"Jürgen A. Erhard"

unread,
Sep 2, 2000, 8:29:51 PM9/2/00
to mos...@math.huji.ac.il, g...@nowhere.none, pytho...@python.org
>>>>> "Moshe" == Moshe Zadka <mos...@math.huji.ac.il> writes:

Moshe> On Fri, 1 Sep 2000, Grant Edwards wrote:
>> In article <Pine.GSO.4.10.10009011423130.22219-100000@sundial>, Moshe Zadka wrote:
>> >On Thu, 31 Aug 2000, Gene C wrote:
>> >
>> >> Has anyone considered a different format for tuples to get around the
>> >> somewhat strange single element tuple format? I find when explaining the
>> >> language to others, the single tuple format always solicits a, "Thats
>> >> weird."
>> >
>> >That's because you're not explaining it correctly. Paraphrasing the NRA,
>> >"parens don't build tuples, commas build tuples".
>>
>> What about ()?
>>
>> It's a tuple, but there are no commas, only parens.

Moshe> Right you are! This is the special case, not the 1-element
Moshe> tuple. But people don't have a problem with this, and it
Moshe> even looks nice.

People don't have a problem because they don't use it... at least *I*
don't. I didn't even know it's there...

Or I don't have to (what use is an empty tuple?)

A one-element tuple is something you *have* to deal with (at least for
the apply(...) case, I think).

Bye, J

PS: I had just learned that "parens don't build tuples, commas build
tuples", then you folks come along and get me back to square one. The
tuple syntax is a bigger crock than I thought.

--
Jürgen A. Erhard juergen...@gmx.net phone: (GERMANY) 0721 27326
MARS: http://members.tripod.com/Juergen_Erhard/mars_index.html
George Herrimann's Krazy Kat (http://www.krazy.com)
Fuck the system? Nah, you might catch something.

--pgp-sign-Multipart_Sun_Sep__3_02:29:48_2000-1
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.2 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEABECAAYFAjmxm34ACgkQN0B+CS56qs2yYgCgkVpIbGUtHwSTjFpSp5cspzGF
V+QAoKJcSa8iGq+/ttPhKQM+zqtBDXJB
VCyv
-----END PGP SIGNATURE-----

--pgp-sign-Multipart_Sun_Sep__3_02:29:48_2000-1--

Grant Edwards

unread,
Sep 2, 2000, 10:49:58 PM9/2/00
to
In article <39B1349A...@alcyone.com>, Erik Max Francis wrote:
>Grant Edwards wrote:
>
>> One thought would be to use the single quotes for tuple delimiters (as in
>> `a,b,c' or `x' or `'). This has the advantage (in my mind) of reminding one
>> that tuples are like strings: immutable.
>
>Then how would you ever distinguish between the _string_ 'a,b,c' and the
>_tuple_ ('a','b','c')?

Single quotes would not be string delimiters any more. Strings would all be
double-quoted. That means we'd loose the convenience of being able to type
things like 'he said "this is a string."' and would have to fall back to
escaping quotes inside strings: "he said \"this is a string\".".

This would, of course, break tons and tons of existing code with little
benefit other than eliminating the "weird" bit about singleton and empty
tuples and eliminating some ambiguity over whether commas are part of
certain statement's syntax or are tuple-constructors.

I don't think the single back-quote "`" is used for anything in Python, is
it?

--
Grant Edwards grante Yow! .. I must be a
at VETERINARIAN...
visi.com

Grant Edwards

unread,
Sep 2, 2000, 10:56:49 PM9/2/00
to
In article <03092...@sanctum.local.jae.ddns.org>, Jürgen A. Erhard wrote:

>People don't have a problem because they don't use it... at least *I* don't.
>I didn't even know it's there...
>
>Or I don't have to (what use is an empty tuple?)

dunno.

>A one-element tuple is something you *have* to deal with (at least for
>the apply(...) case, I think).

>PS: I had just learned that "parens don't build tuples, commas build


>tuples", then you folks come along and get me back to square one. The
>tuple syntax is a bigger crock than I thought.

It's not that bad unless you think about it too much.

I suspect that most people always use parens around tuples (and probably
think they have to unless you actually pin them down and make them think
about it).

That means that in practice, tuples look like:

empty: ()
singleton: (x,)
general: (x,y,z)

Noticed that if you always use parens, all you have to remember is to throw
a comma in at the end of a singleton. It's a rule that works, but it's
fuzzing over the actual syntax a bit.

--
Grant Edwards grante Yow! LOOK!! Sullen
at American teens wearing
visi.com MADRAS shorts and "Flock of
Seagulls" HAIRCUTS!

Ben Wolfson

unread,
Sep 2, 2000, 11:02:18 PM9/2/00
to
On Sun, 03 Sep 2000 02:49:58 GMT, nob...@nowhere.nohow (Grant Edwards)
wrote:

>I don't think the single back-quote "`" is used for anything in Python, is
>it?

Backquotes around an object (`x`) appear to be a shorthand for calling
repr() on that object. It seems rather odd, to me, that there should be
two ways to do such a simple thing.

--
Barnabas T. Rumjuggler's page of dumbth: members.home.net/rumjuggler

In Xanadu did Ozymandias a stately edict once decree: "look upon my
Pleasure Dome, ye mighty, and despair!"
-- David Zacuto

Grant Edwards

unread,
Sep 2, 2000, 11:56:13 PM9/2/00
to
On Sun, 03 Sep 2000 03:02:18 GMT, Ben Wolfson <rumju...@cryptarchy.org> wrote:
>On Sun, 03 Sep 2000 02:49:58 GMT, nob...@nowhere.nohow (Grant Edwards)
>wrote:
>
>>I don't think the single back-quote "`" is used for anything in
>>Python, is it?
>
>Backquotes around an object (`x`) appear to be a shorthand for
>calling repr() on that object. It seems rather odd, to me,
>that there should be two ways to do such a simple thing.

Doh! I knew that. For some reason I never use it.

That's it then. New keyboards for everybody.

--
Grant Edwards grante Yow! .. Am I in a SOAP
at OPERA??
visi.com

Alex Martelli

unread,
Sep 3, 2000, 3:04:34 AM9/3/00
to
"Jürgen A. Erhard" <juergen...@gmx.net> wrote in message
news:03092...@sanctum.local.jae.ddns.org...
[snip]

> People don't have a problem because they don't use it... at least *I*
> don't. I didn't even know it's there...
>
> Or I don't have to (what use is an empty tuple?)
>
> A one-element tuple is something you *have* to deal with (at least for
> the apply(...) case, I think).

apply is a typical case that comes to mind for the empty tuple as well.

Still, there are easy syntactic alternatives:

def tup(*stuff):
return stuff

tup() will now return (), tup("goo") will return ("goo",), and for
any number N>1 of arguments, it will be just as if the 'tup' word
was not there. [I'd rather say 'tuple', but it's better not to
pre-empt the existing built-in function that tupleizes sequences].


Alex

Grant Edwards

unread,
Sep 3, 2000, 2:36:20 PM9/3/00
to
In article <39B27F86...@alcyone.com>, Erik Max Francis wrote:
>Grant Edwards wrote:
>
>> Single quotes would not be string delimiters any more. Strings would all
>> be double-quoted. That means we'd loose the convenience of being able to
>> type things like 'he said "this is a string."' and would have to fall back
>> to escaping quotes inside strings: "he said \"this is a string\".".
>
>Why are you suggesting such a fundamental change in the language for
>such a strange change? You're basically reworking the entire way tuples
>and string literals work -- for what purpose?

1) The tuple syntax in Python is irregular. We're discussing ways to make
it more regular.

2) Such changes will never get implimented (for reasons I've already
explained), so relax, it's all moot.

>It has other problems. What is
>
> ''a''?

That's illegal sytax. You've got four tuple-end-delimiters and no
tuple-begin-delimeters.

>Is it the tuple ((a))?

No, that's just plain _a_ (both in current syntax and my theoretical,
new-and-improved syntax).

Perhaps you mean ((a,),)? [see why we're discussing this?]

If so, then that would be ``a''

>Or is it an empty tuple, an a and another empty tuple: () a ()?

That would be `'a`'

>> I don't think the single back-quote "`" is used for anything in Python, is
>> it?
>

>Sure it is.
>
> print `1`

Yea, I forgot about that.

But, _if_ we didn't use the single-quote for strings, and _if_ we didn't use
the single-back-quote for repr(), then we could have a pair of delimeters to
use for tuples: no more trying to explain that commas are tuple-construction
operators that are sometimes infix-binary and sometimes postfix-unary,
except for empty tuples where they aren't used at all because empty tuples
are constructed using parens and no commas.

Parens would only be overloaded for two different things, and it would be
unambiguious whether commas were part of statement syntax or list/tuple/dict
item seperators.

--
Grant Edwards grante Yow! I guess it was all a
at DREAM... or an episode of
visi.com HAWAII FIVE-O...

Delaney, Timothy

unread,
Sep 5, 2000, 6:59:55 AM9/5/00
to Rainer Deyke, pytho...@python.org
I do like the idea of adding constness (I prefer the term immutability) in a
general way to objects. This would enforce that only __getattr__,
__getslice__ etc could be called. There could be no assignment to instance
properties. etc etc etc ... sorry - bit slow right now ... just finished a
13-hour day on 3 hours sleep.

> Why use tuples at all? The Pythonic way to enforce usage
> restrictions is
> through convention:
>
> a = [1, 2, 3] # Do not modify this object!
>
> Another, more general way of dealing with mutable/immutable
> objects would be
> to introduce the concept of const references:
>
> a = [1, 2, 3]
> print isconst(a) # Prints 0
> b = const(a)
> print isconst(a) # Prints 0
> print isconst(b) # Prints 1

Martijn Faassen

unread,
Sep 5, 2000, 9:38:09 AM9/5/00
to
Grant Edwards <nob...@nowhere.nohow> wrote:
> In article <03092...@sanctum.local.jae.ddns.org>, Jürgen A. Erhard wrote:
[snip]

>>PS: I had just learned that "parens don't build tuples, commas build
>>tuples", then you folks come along and get me back to square one. The
>>tuple syntax is a bigger crock than I thought.

> It's not that bad unless you think about it too much.

Agreed! So let's think about it some more. :)

> I suspect that most people always use parens around tuples (and probably
> think they have to unless you actually pin them down and make them think
> about it).

I tend to use parens around tuples frequently, but not always:

a, b = b, a

x, y, z = foo()

And so on. I don't tend to use parens in the context of tuple unpacking,
but elsewhere, I do. Partially because in those contexts I tend to *need*
parens to disambiguate:

def foo(1, 2) versus def foo((1, 2))
[1, 2] versus [(1, 2)]

Regards,

Martijn
--
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?

Martijn Faassen

unread,
Sep 5, 2000, 9:44:39 AM9/5/00
to
Gene C <gchiar...@yahoo.com> wrote:
>> Why use tuples at all? The Pythonic way to enforce usage restrictions is
>> through convention:
>>
>> a = [1, 2, 3] # Do not modify this object!

> It's settled. Don't use tuples, they are evil! ;-)

Hah, I like tuples! I'm evil! Using lists for tuples is silly, they're just
conceptually different things. A tuple is a lightweight structure, a
list is a list of stuff. You loop through lists, you rarely loop through
tuples. You tend to unpack tuples, and you rarely unpack lists. While
these usages are not enforced (in good Python style), the different ways
you use them actually makes tuples and lists far more different
conceptually than they are different in their implementations.

Some more general mechanism for immutability sounds nice, though, but I
don't have the experience yet to know yet whether it is *wise*.

Rainer Deyke

unread,
Sep 5, 2000, 2:52:46 PM9/5/00
to
"Delaney, Timothy" <tdel...@avaya.com> wrote in message
news:D133051DBC4AD111B908...@natasha.auslabs.lucent.com...

> I do like the idea of adding constness (I prefer the term immutability) in
a
> general way to objects. This would enforce that only __getattr__,
> __getslice__ etc could be called. There could be no assignment to instance
> properties. etc etc etc ... sorry - bit slow right now ... just finished a
> 13-hour day on 3 hours sleep.

It would probably have to be a bit more complicated so get_something methods
still work. I recommend an exception be thrown if a const object's __dict__
is modified (considering only class instances for now).

war...@zem.zem

unread,
Sep 5, 2000, 8:36:11 PM9/5/00
to
Steve Holden <sho...@holdenweb.com> wrote:
>
>This thread has become a veteran, but ironically I have not yet seen
>a SINGLE suggestion which would be easier to explain to novices than
>the current syntax. Anything which tries to use the same token to open
>AND close a tuple is doomed to failure when nested tuples are needed.
>
>Ho, hum.
>
>regards
> Steve


Isn't this concern about bracketing tuples a red herring?
Except for an empty tuple, tuples are defined by the comma.
Parentheses are only needed to resolve ambiguities in argument
lists,
foo(x, (a,tuple))

lists,
[1, (2, 3)]

and to group tuples inside tuples.
1, (2, 3)

The first two are because the comma is used for reasons other
than tuple creation. I think the last example is unavoidable.

So, just come up with another tuple delimiter. Let's use a
semicolon, I never use them anyway.

foo(x, a;tuple)
[1, 2;3]
1;(2;3)

That just leaves the problem of an empty tuple. Why not this?
empty_tuple = ;

The inconsistancy of trailing commas or semicolons (tuple
operators?) can be solved by requiring them.

one_item_tuple = 1;
two_item_tuple = 1;2;

Now tuple construction can be explained by saying:

The tuple operator - ';' - concatenates the preceeding
item into a tuple.

[item] ; [item ; ...]

Is that simple enough?
Would it work?
Does any of this thread really matter? :)

(BTW, I really am curious if it would work.)

Warren


Grant Edwards

unread,
Sep 5, 2000, 11:18:58 PM9/5/00
to
On Tue, 5 Sep 2000 19:36:11 -0500, war...@Zem.Zem <war...@Zem.Zem> wrote:

>Isn't this concern about bracketing tuples a red herring?

I don't think so.

>Except for an empty tuple, tuples are defined by the comma.

"Except" is a Bad Thing when defining sytax. Tuple syntax has
two "excepts":

1) Commas are used to construct tuples _except_ when they're
empty.

2) You put commas between tuple elements, except for the extra
trialing comma with is optional (except for singletons).

Maybe that should be five [three, sir]... three "excepts."

>Parentheses are only needed to resolve ambiguities in argument
>lists,

There are those of who think that syntaxes with such
ambiguities could be improved. Unfortunately the improvement
requires another set of delimiters, and we're fresh out. I
don't think anybody would have come up with the current syntax
if there _was_ another set of delimiters laying unused on your
keyboard.

--
Grant Edwards grante Yow! I always liked FLAG
at DAY!!
visi.com

Gene C

unread,
Sep 6, 2000, 8:09:53 AM9/6/00
to
> The inconsistancy of trailing commas or semicolons (tuple
> operators?) can be solved by requiring them.
>
> one_item_tuple = 1;
> two_item_tuple = 1;2;
>
> Now tuple construction can be explained by saying:
>
> The tuple operator - ';' - concatenates the preceeding
> item into a tuple.
>
> [item] ; [item ; ...]
>
> Is that simple enough?

yes

> Would it work?

no - semicolons are used to delimit statements. pg 14 - Python Essential
Ref

two_item_tuple = 1;2;

is the same as

two_item_tuple = 1;
2;


0 new messages