RCR 192: New variable declaration syntax in blocks
submitted by grenzi on Wed Jan 14 2004 02:23:07 AM -0800
Status: withdrawn
Abstract
this rcr suggest the removal of a "|" to shorten variable declarations
Problem
e block declaration like { |a| .. } requires to enclose the variable beetween a couple of "|". We may just use a single one, as in SmallTalk or Groovy
Proposal
change this syntax from do |a,b,c| .. end to do a,b,c | .. end
Analysis
This is just a little change but may break something.
but I may be wrong.
The proposed change reduces line noise and
saves one keystroke. Not a big saving, but better than actual syntax.
you would just need:
ary.map {x| x.succ}
instead of
ary.map {|x| x.succ}
Possibly we could introduce the change as a parallel syntax, leaving both available.
Warning:
This may cause ambiguity in cases like this
a=0; b=1
proc { a | b }
is it 'a' a formal argument or a reference to an external variable BitOR'ed with b ?
With the new syntax you may have to write like this:
a=0;b=1
proc {| a|b }
not a big deal for really rare cases.
If both syntax are available this may be hard to check. We could be forced to write
proc { || a|b}for this case
Implementation
none ATM
The ambiguities introduced into this grammar make it a very undesirable change, IMO. The initial pipe makes the grammar easier to parse, and easier to read--and I think ease of readability should come before ease of writability. Saving a single keystroke is not worth the added complexity and potential visual ambiguities.
- Jamis Buck
Thanks, James. I feel same way. Actually, in the pre-relase phase (back in 1993), the block parameter syntax was exactly what you described here. I changed the syntax for the particular reason which James stated above.
-matz.
I did not mind about parsing efficiency cause we're going to have a bytecompiled form for our script sometime in the future. But It seem I'm the only one that finds the proposed new syntax more clear than the old. Ok, let's kill this rcr :)
- grenzi
Add comments here
Back to RCRchive.
RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog