From: Zsban Ambrus Date: 2005-01-08T07:28:46+09:00 Subject: List assignment syntax I'm a little dissatisfied with the list assignment syntax of ruby. On an example: irb(main):001:0> a = [2, [3, 5], 8] => [2, [3, 5], 8] This works: irb(main):002:0> x, (y, ), z = a => [2, [3, 5], 8] But this doesn't, although I'd like to use it instead of the above. irb(main):003:0> x, (y), z = a SyntaxError: compile error (irb):3: syntax error x, (y), z = a ^ from (irb):3 None of these work, so I know of no simple way to ignore an array element: irb(main):004:0> x, (), z = a SyntaxError: compile error (irb):4: syntax error x, (), z = a ^ from (irb):4 irb(main):005:0> x, (, ), z = a SyntaxError: compile error (irb):5: syntax error x, (, ), z = a ^ (irb):5: syntax error from (irb):5 irb(main):006:0> These flexible list forms could imo be very useful. If ruby had the array slicing idioms found in other languages (eg perl, mathematica), for example if `a[[0, 2]]' returned `[a[0], a[2]]', there wouldn't be so much need to this, as one would just say `x, z = a[[0, 2]]'. (Does ruby have such a slicing method built in that I'm unaware of?) I'd like to see your opinion about whether you think this kind of lhs syntax are worth to be added to ruby, and especially whether it can cause any kind of syntax ambugnuity or confusion. And at last, two quick random thoughts: 1. Why does parse.y have the declaration `%token tRPAREN' if that token type is apparently never used? (Even bison shows unused tokens in the .output file if called with -d.) 2. It would be nice if irb printed a linefeed if you quit the readline prompt by pressing control-d. This way it causes the shell prompt to be printed in the same line as the ruby prompt. This, of course, causes problem only to non-windows users that quit with control-d instead of exit, and have readline in irb, which is a minority, but still... Thanks in advance, ambrus