# Ruby-dev summary 26468-26661

**URL:** <https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927>\
**Category:** ruby-talk\
**Created:** [3 August 2005 16:36 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927 "2005-08-03T16:36:04Z")\
**Posts on this page:** 12\
**Page:** 3

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [5 August 2005 02:01 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/41 "2005-08-05T02:01:07Z")

</div>

Yukihiro Matsumoto wrote:

> Hi,
> 
> \>I suprised no one's picked up on this.  
> \>  
> \> [:a,:b,:c].each do n(i)  
> \> p n.count;  
> \> end  
> \> #=\> 1 2 3
> 
> The meaning of above code is not obvious for me at all, besides its  
> syntax conflicts existing ones.

Read as "each do n of i ... end" such that "n of i" is the block name  
and args. That's too bad if syntax conflicts, I had though maybe it was  
possible. But even so I think giveng the block handle (i.e. a name such  
as n above) has a lot of merit. No more need fo \_with\_index for  
instance. Perhaps you can find another way to have block handle.

Thanks,  
T.

P.S. I sent this post once but it seems to have been lost. Forgive me  
if it comes up twice.

> **···**
>
> > In message "Re: ruby-dev summary 26468-26661" \> on Fri, 5 Aug 2005 10:06:05 +0900, "Trans" \<transfire@gmail.com\> writes:

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [5 August 2005 02:06 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/42 "2005-08-05T02:06:05Z")

</div>

Yukihiro Matsumoto wrote:

> Hi,
> 
> \>I suprised no one's picked up on this.  
> \>  
> \> [:a,:b,:c].each do n(i)  
> \> p n.count;  
> \> end  
> \> #=\> 1 2 3
> 
> The meaning of above code is not obvious for me at all, besides its  
> syntax conflicts existing ones.

Hmm.. read as "each do n of i ... end". But if the syntax conflict  
that's too bad. Having a handle on the block (i.e. n) would be very  
useful --no more \_with\_index stuff. Perhaps there is another way you  
can work in a block handle?

Thanks,  
T

> **···**
>
> > In message "Re: ruby-dev summary 26468-26661" \> on Fri, 5 Aug 2005 10:06:05 +0900, "Trans" \<transfire@gmail.com\> writes:

---

<div class="post-metadata">

**Author:** ![Nakada\_Nobuyoshi](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@Nakada\_Nobuyoshi](https://rubytalk.org/u/Nakada_Nobuyoshi)\
**Post date:** [5 August 2005 02:20 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/43 "2005-08-05T02:20:41Z")

</div>

Hi,

At Fri, 5 Aug 2005 00:29:55 +0900,  
Eric Mahurin wrote in [ruby-talk:150730]:

> Here is my proposal:
> 
> { args : code }
> 
> Even if when you make the args : optional to preserve  
> compatibility, I think this would be parsable if you treat the  
> arg list (possibly with default expressions) like a normal  
> statment except that the delimiter is ":" instead of ";". This  
> should work because an arg list is a syntactically valid  
> statement. i.e.
> 
> a=1  
> other=[3,4]  
> a,b=2,\*other
> 
> When the lexer finds a ":" instead of a ";" or newline as the  
> statement delimiter of first statement, it would treat that as  
> the arg list.

Default values can be very long beyond new lines, if it is a  
block statement or is parenthesized. it seems very confusing  
and I guess such parser is impossible. Leading sign would be  
mandatory.

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [5 August 2005 12:51 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/44 "2005-08-05T12:51:06Z")

</div>

Florian Groß wrote:

> Trans wrote:
> 
> \> Seems like a very insteresting and useful notion to locally name the  
> \> block. And open up other possibilites like:  
> \>  
> \> [:a,:b,:c].each do n(i)  
> \> if n.first?  
> \> # ...  
> \> end  
> \> end  
> \> #=\> 1 2 3
> 
> I'd insert an as:
> 
> [:a, :b, :c].each as n(i) do  
> &nbsp;&nbsp;&nbsp;if n.first? then  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# ...  
> &nbsp;&nbsp;&nbsp;end  
> end
> 
> Still needs getting used to it, though.

That'll work. Fits in well with the "with" version too. And really if  
you substitute  
-\> == as/with  
{ == do  
} == end

&nbsp;&nbsp;[:a, :b, :c].each -\> n(i) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if n.first? then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# ...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;}

All except for the named block, this is excactly what matz has now.

T.

---

<div class="post-metadata">

**Author:** ![Eric\_Mahurin1](https://avatars.discourse-cdn.com/v4/letter/e/34f0e0/32.png) [@Eric\_Mahurin1](https://rubytalk.org/u/Eric_Mahurin1)\
**Post date:** [5 August 2005 21:58 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/45 "2005-08-05T21:58:23Z")

</div>

In the 1.9 I tried, the new syntax that few people like works  
both for lambdas and blocks.

> **···**
>
> --- James Edward Gray II \<james@grayproductions.net\> wrote:
> 
> > On Aug 5, 2005, at 3:59 PM, James Edward Gray II wrote:
> > 
> > \> I too hate the -\> (...) idea. I left Perl for Ruby. 😉
> > 
> > Now that I've read on, I understand that this is for lambdas  
> > only and  
> > it bothers me a \*little\* less. I still would prefer we  
> > translate -\>  
> > to a keyword though, if possible.
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Start your day with Yahoo! - make it your home page  
> [http://www.yahoo.com/r/hs](http://www.yahoo.com/r/hs)

---

<div class="post-metadata">

**Author:** ![Gavin\_Kistner2](https://avatars.discourse-cdn.com/v4/letter/g/b9e5f3/32.png) [@Gavin\_Kistner2](https://rubytalk.org/u/Gavin_Kistner2)\
**Post date:** [4 August 2005 20:43 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/46 "2005-08-04T20:43:56Z")

</div>

Though that opens up the question of how to define a param-less block whose first statement started with a paren:

10.times{ (a,b = [1,2]).each{ ... } }

> **···**
>
> On Aug 4, 2005, at 9:47 AM, Brian Schröder wrote:
> 
> > Why should you write it like that. If there is no starting ( there is  
> > no argument list. So
> > 
> > Hash.new { }

---

<div class="post-metadata">

**Author:** ![Jim\_Freeze3](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/jim_freeze3/32/2022_2.png) [@Jim\_Freeze3](https://rubytalk.org/u/Jim_Freeze3)\
**Post date:** [4 August 2005 21:51 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/47 "2005-08-04T21:51:49Z")

</div>

> Just thinking out loud, so to speak (so to speak [so to speak...]):
> 
> x(a,b) {|y, z(=2)| ... }
> 
> Sort of: "z (which defaults to 2)"

As long as we are being noisy in our thinking, I'm pretty sure  
that a parser would not confuse the character combo '(='  
with a valid syntax. 🙂

&nbsp;&nbsp;lambda { |x(=1), y(=(2\*\*(3-2))| ... }  
&nbsp;&nbsp;lambda { |(x=1), (y=(2\*\*(3-2))| ... }

Hmm, it defintely makes the arguments more visible when there are defaults.

> **···**
>
> --  
> Jim Freeze

---

<div class="post-metadata">

**Author:** ![Eric\_Mahurin1](https://avatars.discourse-cdn.com/v4/letter/e/34f0e0/32.png) [@Eric\_Mahurin1](https://rubytalk.org/u/Eric_Mahurin1)\
**Post date:** [5 August 2005 14:43 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/48 "2005-08-05T14:43:27Z")

</div>

When I said ";" or newline, the newlines I'm talking about are  
only those that delimit statements. So, you could have  
newlines in your arglist as long as they don't look like a  
statement terminator:

{ a,  
b=  
a\*  
a :  
a\*b  
}

"-\>" has also been suggested instead of ":". And I suggested  
;/newline if you can make the arg-list mandatory (possibly  
empty).

Would you agree that any valid arg-list is also syntactically a  
valid statement? Or am I wrong? Wouldn't this fact be useful  
in parsing this optional arg-list?

You still have the problem of ambiguities with the hash though.  
Here are a few potential options for that:

%h{ ... } # like another quoting operator  
hash( ... ) # simply a Kernel method  
h( ... )

{} seems too overloaded now:

{ key=\>value, ... } # hash  
{ code } # block/lambda without args  
{ |args| code } # block/lambda with args

I think that the syntax should either be left alone or  
backwards compatibility should be broken (where necessary) and  
these ambiguities solved once and for all.

> **···**
>
> --- nobuyoshi nakada \<nobuyoshi.nakada@ge.com\> wrote:
> 
> > Hi,
> > 
> > At Fri, 5 Aug 2005 00:29:55 +0900,  
> > Eric Mahurin wrote in [ruby-talk:150730]:  
> > \> Here is my proposal:  
> > \>  
> > \> { args : code }  
> > \>  
> > \> Even if when you make the args : optional to preserve  
> > \> compatibility, I think this would be parsable if you treat  
> > the  
> > \> arg list (possibly with default expressions) like a normal  
> > \> statment except that the delimiter is ":" instead of ";".  
> > This  
> > \> should work because an arg list is a syntactically valid  
> > \> statement. i.e.  
> > \>  
> > \> a=1  
> > \> other=[3,4]  
> > \> a,b=2,\*other  
> > \>  
> > \> When the lexer finds a ":" instead of a ";" or newline as  
> > the  
> > \> statement delimiter of first statement, it would treat that  
> > as  
> > \> the arg list.
> > 
> > Default values can be very long beyond new lines, if it is a  
> > block statement or is parenthesized. it seems very confusing  
> > and I guess such parser is impossible. Leading sign would be  
> > mandatory.
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Start your day with Yahoo! - make it your home page  
> [http://www.yahoo.com/r/hs](http://www.yahoo.com/r/hs)

---

<div class="post-metadata">

**Author:** ![Ryan\_Leavengood2](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@Ryan\_Leavengood2](https://rubytalk.org/u/Ryan_Leavengood2)\
**Post date:** [4 August 2005 22:08 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/49 "2005-08-04T22:08:43Z")

</div>

Jim Freeze said:

> As long as we are being noisy in our thinking, I'm pretty sure  
> that a parser would not confuse the character combo '(='  
> with a valid syntax. 🙂
> 
> &nbsp;&nbsp;lambda { |x(=1), y(=(2\*\*(3-2))| ... }  
> &nbsp;&nbsp;lambda { |(x=1), (y=(2\*\*(3-2))| ... }
> 
> Hmm, it defintely makes the arguments more visible when there are  
> defaults.

I agree. I like this one more than most of the other suggestions. In fact,  
a lot of them I strongly dislike. But I tend to resist changes in  
programming languages I use, especially Ruby. Mostly because changes are  
usually wanted by novices or new programmers who haven't yet fully  
embraced the idioms of the language (though this does not always apply,  
like any generalization.)

I'm still mulling over the original -\>(...){...} change, but my first gut  
reaction was dislike.

Ryan

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [5 August 2005 01:01 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/50 "2005-08-05T01:01:06Z")

</div>

Jim Freeze wrote:

> &nbsp;&nbsp;lambda { |x(=1), y(=(2\*\*(3-2))| ... }  
> &nbsp;&nbsp;lambda { |(x=1), (y=(2\*\*(3-2))| ... }

It may seem simple enough but its horrible. I think maybe this should  
be looked upon as an oppurtunity to go back and really think about this  
part of the Ruby syntax and how it all fits together. Really, there  
won't be another chance. I can't imagine this kind of indepth  
consideration come Ruby 3.0. So now is the time to do it. I think  
truely fixing the issue rather than patching it is a better solution  
even if mens some work on our part to transition our old programs.

2c,  
T.

---

<div class="post-metadata">

**Author:** ![Nakada\_Nobuyoshi](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@Nakada\_Nobuyoshi](https://rubytalk.org/u/Nakada_Nobuyoshi)\
**Post date:** [8 August 2005 03:05 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/51 "2005-08-08T03:05:27Z")

</div>

Hi,

At Fri, 5 Aug 2005 23:43:27 +0900,  
Eric Mahurin wrote in [ruby-talk:150889]:

> Would you agree that any valid arg-list is also syntactically a  
> valid statement? Or am I wrong? Wouldn't this fact be useful  
> in parsing this optional arg-list?

Agree for the former, but not for the later. I think it  
would be confusing rather than useful.

And your suggenstion would require re-parsing the source or  
re-construction of nodes, after the separator was found.

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [5 August 2005 01:06 UTC](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927/52 "2005-08-05T01:06:36Z")

</div>

Hi --

> **···**
>
> On Fri, 5 Aug 2005, Trans wrote:
> 
> > Jim Freeze wrote:
> > 
> > > &nbsp;&nbsp;lambda { |x(=1), y(=(2\*\*(3-2))| ... }  
> > > &nbsp;&nbsp;lambda { |(x=1), (y=(2\*\*(3-2))| ... }
> > 
> > It may seem simple enough but its horrible. I think maybe this should  
> > be looked upon as an oppurtunity to go back and really think about this  
> > part of the Ruby syntax and how it all fits together. Really, there  
> > won't be another chance. I can't imagine this kind of indepth  
> > consideration come Ruby 3.0. So now is the time to do it. I think  
> > truely fixing the issue rather than patching it is a better solution  
> > even if mens some work on our part to transition our old programs.
> 
> Sorry for the "horrible" suggestion, but I think we are all discussing  
> and examining the syntax in good faith.
> 
> David
> 
> --  
> David A. Black  
> dblack@wobblini.net

[Previous page](https://rubytalk.org/t/ruby-dev-summary-26468-26661/19927.md?page=2)
