|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi all,
This came up in a discussion about Ruby with a friend who is learning... Why aren't method definitions more like blocks? Perhaps it's easier to explain with some examples. Consider the method blah: def blah(x) ... end And this proc: lambda do |x| ... end Friend wondered why a method definition couldn't be like this: def blah do |x| ... end And I didn't have a good answer, except that "it just is." Maybe I could have gone into the semantic difference between methods and lambda procs, but does semantic difference necessitate syntactic difference? I tried to simulate this like so: blah = lambda do |x| ... end Which I realize is going down a different path, but still. Now I wish I could do this: blah(5) But I can't. I have to blah.call. I'm not complaining at all. This isn't bait. It's just me loving Ruby and wondering aloud. Any opinions? Joe |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Note: parts of this message were removed by the gateway to make it a legal Usenet post.
On 11/5/07, Joe Holt <joe07734@gmail.com> wrote: > > Which I realize is going down a different path, but still. Now I wish > I could do this: > > blah(5) > > But I can't. I have to blah.call. > > I'm not complaining at all. This isn't bait. It's just me loving Ruby > and wondering aloud. Any opinions? > > Joe > > > You don't have to do blah.call, you can do blah[5] which is pretty close ![]() |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Note: parts of this message were removed by the gateway to make it a legal Usenet post.
Apologies... Somehow i quoted myself out: You don't have to do blah.call, you can do blah[5] which is pretty close ![]() On 11/5/07, Dan <dan.macdaddy+ruby@gmail.com> wrote: > > On 11/5/07, Joe Holt <joe07734@gmail.com> wrote: > > > > > Which I realize is going down a different path, but still. Now I wish > > I could do this: > > > > blah(5) > > > > But I can't. I have to blah.call. > > > > I'm not complaining at all. This isn't bait. It's just me loving Ruby > > and wondering aloud. Any opinions? > > > > Joe > > > > > > > > |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
> |def blah do |x|
> | ... > |end Would it be possible, hypothetically speaking, to make the parser digest something like: def bla do(x, y=1, z=2) ... end and (maybe instead of or additionally to the experimental -> syntax) a = arr.map def(x, y=1) ... end fn = def(x, y=1) ... end or a = arr.map do(x, y=1) ... end fn = do(x, y=1) ... end I personally am not very fond of curly braces, vertical bars, and arrows. Maybe it's because I learned Pascal first. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Note: parts of this message were removed by the gateway to make it a legal Usenet post.
I think its almost perfect the way it is, but i would really enjoy blocks with optional parameters. -- Bernardo Rufino |
|
![]() |
| Outils de la discussion | |
|
|