Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Default argument values for blocks

Reply
Thread Tools

Default argument values for blocks

 
 
Daniel Schierbeck
Guest
Posts: n/a
 
      10-11-2005
Is there a reason why I can't do this?

foo = lambda { |foo = bar| puts foo }
foo.call

I can't think of any good reason why this isn't valid.


Cheers,
Daniel Schierbeck
 
Reply With Quote
 
 
 
 
Daniel Schierbeck
Guest
Posts: n/a
 
      10-11-2005
Daniel Schierbeck wrote:
> Is there a reason why I can't do this?
>
> foo = lambda { |foo = bar| puts foo }
> foo.call
>
> I can't think of any good reason why this isn't valid.
>
>
> Cheers,
> Daniel Schierbeck


I of course meant |foo = "bar"|

Sorry
 
Reply With Quote
 
 
 
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      10-11-2005
Hi,

In message "Re: Default argument values for blocks"
on Wed, 12 Oct 2005 01:56:52 +0900, Daniel Schierbeck <(E-Mail Removed)> writes:

|Is there a reason why I can't do this?
|
| foo = lambda { |foo = bar| puts foo }
| foo.call
|
|I can't think of any good reason why this isn't valid.

Mostly because yacc does not allow it. It confuses

lambda { |foo = bar| puts foo }

as

lambda { |foo = (bar| puts foo) }

and causes syntax error.

matz.


 
Reply With Quote
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      10-11-2005
Hi,

In message "Re: Default argument values for blocks"
on Wed, 12 Oct 2005 02:25:33 +0900, Yukihiro Matsumoto <(E-Mail Removed)> writes:

||Is there a reason why I can't do this?
||
|| foo = lambda { |foo = bar| puts foo }
|| foo.call
||
||I can't think of any good reason why this isn't valid.
|
|Mostly because yacc does not allow it. It confuses
|
| lambda { |foo = bar| puts foo }
|
|as
|
| lambda { |foo = (bar| puts foo) }
|
|and causes syntax error.

For your information, you can do

foo = ->(foo="bar"){puts foo}
foo.call

in 1.9.

matz.


 
Reply With Quote
 
Ara.T.Howard
Guest
Posts: n/a
 
      10-11-2005
On Wed, 12 Oct 2005, Yukihiro Matsumoto wrote:

> Hi,
>
> In message "Re: Default argument values for blocks"
> on Wed, 12 Oct 2005 02:25:33 +0900, Yukihiro Matsumoto <(E-Mail Removed)> writes:
>
> ||Is there a reason why I can't do this?
> ||
> || foo = lambda { |foo = bar| puts foo }
> || foo.call
> ||
> ||I can't think of any good reason why this isn't valid.
> |
> |Mostly because yacc does not allow it. It confuses
> |
> | lambda { |foo = bar| puts foo }
> |
> |as
> |
> | lambda { |foo = (bar| puts foo) }
> |
> |and causes syntax error.
>
> For your information, you can do
>
> foo = ->(foo="bar"){puts foo}
> foo.call
>
> in 1.9.


-> means lambda?

-a
--
================================================== =============================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
================================================== =============================



 
Reply With Quote
 
Daniel Schierbeck
Guest
Posts: n/a
 
      10-11-2005
Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: Default argument values for blocks"
> on Wed, 12 Oct 2005 02:25:33 +0900, Yukihiro Matsumoto <(E-Mail Removed)> writes:
>
> ||Is there a reason why I can't do this?
> ||
> || foo = lambda { |foo = bar| puts foo }
> || foo.call
> ||
> ||I can't think of any good reason why this isn't valid.
> |
> |Mostly because yacc does not allow it. It confuses
> |
> | lambda { |foo = bar| puts foo }
> |
> |as
> |
> | lambda { |foo = (bar| puts foo) }
> |
> |and causes syntax error.
>
> For your information, you can do
>
> foo = ->(foo="bar"){puts foo}
> foo.call
>
> in 1.9.
>
> matz.
>
>


Cool. Is "->" the same as "lambda"? Can you write this:

collection.each -> (element) { puts element }
 
Reply With Quote
 
Kevin Ballard
Guest
Posts: n/a
 
      10-11-2005
Yukihiro Matsumoto wrote:
> Mostly because yacc does not allow it. It confuses
>
> lambda { |foo = bar| puts foo }
>
> as
>
> lambda { |foo = (bar| puts foo) }
>
> and causes syntax error.


yacc? Maybe I was informed wrong, but I was under the impression that
Ruby used a hand-rolled parser.

 
Reply With Quote
 
Daniel Berger
Guest
Posts: n/a
 
      10-11-2005
Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: Default argument values for blocks"
> on Wed, 12 Oct 2005 02:25:33 +0900, Yukihiro Matsumoto <(E-Mail Removed)> writes:
>
> ||Is there a reason why I can't do this?
> ||
> || foo = lambda { |foo = bar| puts foo }
> || foo.call
> ||
> ||I can't think of any good reason why this isn't valid.
> |
> |Mostly because yacc does not allow it. It confuses
> |
> | lambda { |foo = bar| puts foo }
> |
> |as
> |
> | lambda { |foo = (bar| puts foo) }
> |
> |and causes syntax error.
>
> For your information, you can do
>
> foo = ->(foo="bar"){puts foo}
> foo.call
>
> in 1.9.
>
> matz.


MY EYES!!!!

Please, no.

Dan


 
Reply With Quote
 
Eric Hodel
Guest
Posts: n/a
 
      10-11-2005
On Oct 11, 2005, at 12:21 PM, Kevin Ballard wrote:

> Yukihiro Matsumoto wrote:
>> Mostly because yacc does not allow it.

>
> yacc? Maybe I was informed wrong, but I was under the impression that
> Ruby used a hand-rolled parser.


You were informed wrong.



 
Reply With Quote
 
David A. Black
Guest
Posts: n/a
 
      10-11-2005
Hi --

On Wed, 12 Oct 2005, Yukihiro Matsumoto wrote:

> Hi,
>
> In message "Re: Default argument values for blocks"
> on Wed, 12 Oct 2005 02:25:33 +0900, Yukihiro Matsumoto <(E-Mail Removed)> writes:
>
> ||Is there a reason why I can't do this?
> ||
> || foo = lambda { |foo = bar| puts foo }
> || foo.call
> ||
> ||I can't think of any good reason why this isn't valid.
> |
> |Mostly because yacc does not allow it. It confuses
> |
> | lambda { |foo = bar| puts foo }
> |
> |as
> |
> | lambda { |foo = (bar| puts foo) }
> |
> |and causes syntax error.
>
> For your information, you can do
>
> foo = ->(foo="bar"){puts foo}
> foo.call
>
> in 1.9.


Is this definitely going to remain? (Please say no....


David

--
David A. Black
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Methods and blocks - not that clear when blocks passed into Steven Taylor Ruby 9 04-27-2009 08:46 AM
How do I get a dictionary of argument names with their default values? Noah Python 2 12-22-2005 11:12 PM
"Building Blocks" are "Application Blocks" Arjen ASP .Net 3 02-27-2005 01:06 AM
procs/blocks - blocks with procs, blocks with blocks? matt Ruby 1 08-06-2004 01:33 AM



Advertisments