Re: [q-lang-users] A proposal to adopt Python tuple syntax
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2005-06-24 09:08:15
|
John.Cowan wrote: > Speaking as a human programmer, I wouldn't; speaking as someone who > writes code that generates code, I have found redundant generation of > parens to make my life simpler, secure in the knowledge that the next > stage will discard them. Ok, that is a point. To work around this right now, you could just generate all expressions in prefix form ((+) X Y etc.), though. > De gustibus. Well, I can say that in favour of my solution, too. ;-) > Indeed, and in ML foo(99) works just fine, since there are no 1-tuples > and the 0-tuple syntax means something else. Yees, but in those languages you just can't write a generic function operating on tuples of arbitrary sizes, much less on an argument that can have _any_ type. In Q you can, and actually it's fairly straightforward, see e.g. lambda.q. > I think it is a real problem. Ok, point taken. To summarize: So far the most problematic usability issues related to Q's 1-tuples seem to be the following: - You have to remember to write foo X, not foo(X), unless you really want the argument to be a 1-tuple. - You have to remember that -X is not a primary, so (-X) is not a 1-tuple, but ((-X)) is. - Superflous extra parentheses around non-primaries can sometimes be useful, especially in code generation. 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. 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. ;-) > One approach is to have prefix syntax to mark tuples, like the #(...) > of Scheme or Smalltalk (but not implying that the tuple members are > literals). This would be mandatory for 1-tuples and optional for all other > tuples. No, then I'd favour the (X,) solution. 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? Comments, please! I need _your_ inputs on that matter. Or do you all prefer that John and I decide this issue on our own? ;-) I'm soon going to start work on Q 6.1, this could be one of the language changes going into it (besides the $ operator proposed by Tim Haynes). Cheers, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikwissenschaft.uni-mainz.de/~ag |