Re: [q-lang-users] A proposal to adopt Python tuple syntax
Brought to you by:
agraef
From: John.Cowan <jc...@re...> - 2005-06-24 21:16:32
|
Albert Graef scripsit: > - You have to remember to write foo X, not foo(X), unless you really > want the argument to be a 1-tuple. I think the Lispish impulse to write lambda (X) instead of lambda X fits in here too. > - You have to remember that -X is not a primary, so (-X) is not a > 1-tuple, but ((-X)) is. That is, that -3.14159 is not a primary (it's self-evident that -X is not). > OTOH, I'm arguing that Q's way to write 1-tuples avoids the ugliness of > a special notation like (X,). But I see the point that the current > notation is a possible source of confusion. Guido characterizes the Python style as "ugly but effective", which I think sums it up. > How does everyone else here feel about this? If you have any anecdotal > evidence where you have been bitten by Q's 1-tuples, please speak up! > I'm not going to make a change like this light-heartedly, as it might be > a big inconvenience for some (it'll be one for me ;-). But if everyone > agrees that this must be changed, then it ought to change asap, before > everybody and his brother starts using Q. ;-) It's plausible, I think, to stage the change in: let 6.1 accept trailing commas everywhere, and start to warn about the old style (but still accept it as making a tuple); 6.2 then drops support for the old style, and plain parens are just for grouping thereafter. Something I didn't realize until today is that Python doesn't actually require parens around tuples: it's the comma that is the (currying) tuple constructor: $ python Python 2.4.1 (#1, May 27 2005, 18:02:40) [GCC 3.3.3 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> 1,2,3 (1, 2, 3) >>> $ q Q interpreter version 6.0 (i686-pc-cygwin) Copyright (c) 1991-2004 by Albert Graef This software is distributed under the terms of the GNU General Public License version 2 or later; type `copying' for details. ==> 1,2,3 1 ! Syntax error >>> 1,2,3 ^ ==> > Having thought about this a > little more, trailing commas could be allowed in all tuples and lists > (that's sometimes useful, anyway), and it would just be the 1-tuple case > where it's mandatory. Does that sound like a reasonable solution? Yes, that was my original proposal (trailing commas allowed in all tuples, required in 1-tuples). The extension to lists is sensible for the sake of having one fewer thing to learn. A minor point is whether (,) and [,] will become legal ways to write the empty tuple and list respectively. I don't much care either way. -- John Cowan jc...@re... www.ccil.org/~cowan www.reutershealth.com The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. --Edsger Dijkstra |