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
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
Daniel Schierbeck wrote:
Is there a reason why I can't do this?
foo = lambda { |foo = bar| puts foo }
foo.callI can't think of any good reason why this isn't valid.
Cheers,
Daniel Schierbeck
I of course meant |foo = "bar"|
Sorry
Hi,
In message "Re: Default argument values for blocks" on Wed, 12 Oct 2005 01:56:52 +0900, Daniel Schierbeck <daniel.schierbeck@gmail.com> writes:
Is there a reason why I can't do this?
foo = lambda { |foo = bar| puts foo }
foo.callI 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.
Hi,
In message "Re: Default argument values for blocks" on Wed, 12 Oct 2005 02:25:33 +0900, Yukihiro Matsumoto <matz@ruby-lang.org> writes:
Is there a reason why I can't do this?
foo = lambda { |foo = bar| puts foo }
foo.callI 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.
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.
Mostly because yacc does not allow it. It confuses
lambda { |foo = bar| puts foo }
as
lambda { |foo = (bar| puts foo) }
and causes syntax error.
(Mostly) out of curiosity:
Would this
whatever_method {(x, foo=bar) puts x,foo}
and also this
whatever_method do(x, foo=bar)
puts x,foo
end
be possible.
Cheers,
Thomas.
-> means lambda?
-a
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 <matz@ruby-lang.org> 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.callin 1.9.
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
===============================================================================
Yukihiro Matsumoto wrote:
Hi,
>>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.callin 1.9.
matz.
Cool. Is "->" the same as "lambda"? Can you write this:
collection.each -> (element) { puts element }
In message "Re: Default argument values for blocks" > on Wed, 12 Oct 2005 02:25:33 +0900, Yukihiro Matsumoto <matz@ruby-lang.org> writes:
Yukihiro Matsumoto wrote:
Hi,
>>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.callin 1.9.
matz.
MY EYES!!!!
Please, no.
Dan
In message "Re: Default argument values for blocks" > on Wed, 12 Oct 2005 02:25:33 +0900, Yukihiro Matsumoto <matz@ruby-lang.org> writes:
You were informed wrong.
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.
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 <matz@ruby-lang.org> 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.callin 1.9.
Is this definitely going to remain? (Please say no.... ![]()
David
--
David A. Black
dblack@wobblini.net
"Yukihiro Matsumoto" <matz@ruby-lang.org> wrote in message
For your information, you can do
foo = ->(foo="bar"){puts foo}
I hope you can find a better syntax ...
Yukihiro Matsumoto wrote:
Hi,
>>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
What of &?
a.each( &->(foo="bar"){puts foo} ) # Ick.
Can we drop?
a.each( ->(foo="bar"){puts foo} ) # Better.
T.
In message "Re: Default argument values for blocks" > on Wed, 12 Oct 2005 02:25:33 +0900, Yukihiro Matsumoto <matz@ruby-lang.org> writes:
whatever_method {(x, foo=bar) puts x,foo}
and also this
whatever_method do(x, foo=bar)
puts x,foo
end
Or
whatever_method do(x, foo=bar) {puts x,foo}
Hi,
In message "Re: Default argument values for blocks" on Wed, 12 Oct 2005 02:40:48 +0900, "Ara.T.Howard" <Ara.T.Howard@noaa.gov> writes:
foo = ->(foo="bar"){puts foo}
-> means lambda?
Yes, as in Perl6. "lambda" here means lambda in other languages, not
the lambda method in Ruby.
matz.
Hi,
In message "Re: Default argument values for blocks" on Wed, 12 Oct 2005 06:40:07 +0900, "David A. Black" <dblack@wobblini.net> writes:
foo = ->(foo="bar"){puts foo}
Is this definitely going to remain? (Please say no....
It is, but appearance may be changed. But I haven't got the better
one.
matz.
Hi,
In message "Re: Default argument values for blocks" on Wed, 12 Oct 2005 03:16:52 +0900, Daniel Schierbeck <daniel.schierbeck@gmail.com> writes:
Cool. Is "->" the same as "lambda"? Can you write this:
collection.each -> (element) { puts element }
Yes. It is still experimental though.
matz.
What of &?
a.each( &->(foo="bar"){puts foo} ) # Ick.
Can we drop?
a.each( ->(foo="bar"){puts foo} ) # Better.
I was dreaming for a long time of a ruby dialect that has all these fancy arrows haskell has. Everybody proposing arrows, please (try to) read some haskell code.
But seriosly, I personally would prefer something in the line lambda(x, y=1) {...} as it was proposed by other people too.
The => in the hash syntax is IMHO already one kind of arrow too much.
Regards,
Thomas.
Selon Thomas <sanobast-2005a@yahoo.de>:
whatever_method do(x, foo=bar) {puts x,foo}
Despite the fact that it looks like a monstruous cross between do... end and
{...}, and would allow the stuttering:
whatever_method do(x, foo=bar) do puts x,foo end
I don't find it that bad at all. If we go for a keyword rather than symbol
solution, I wouldn't mind it. For returning a Proc, using lambda is still the
best idea so far:
a = lambda(x, foo=bar) {puts x,foo}
Maybe "with"?
whatever_method with(x, foo=bar) {puts x,foo}
whatever_method with(x, foo=bar) do puts x,foo end
I still like my colon better
.
--
Christophe Grandsire.
http://rainbow.conlang.free.fr
It takes a straight mind to create a twisted conlang.
Other than syntax, what's the difference between this and the
Proc that comes from the lambda method? Maybe how return,
break, etc is handled?
In addition to handling defaults in arguments, I think these
issues need to be addressed in blocks/lambdas:
- all variables in the defining scope of a block/lambda are
prevented from being GCed by the block/lambda (because of the
#binding). This can easily result in a leaky program if not
careful. I discussed several solutions to this in a previous
thread.
- a facility for making variables local (regardless of whether
a variable of the same name exists in the defining scope).
This would also be good to have for a begin-end type block (I'd
like to have it for making inlined macros where I don't want to
worry about what variables are already used). I discussed
several solutions for this in another thread.
Also, I saw some slides for ruby 2 back in 2003 showing that
arguments will always be local to the block and other variables
in the block will be in the same scope as the defining scope.
I think always making arguments local is a good thing, but
never localizing the other variables will be problematic if
another local variable facility is not provided.
--- Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
Hi,
In message "Re: Default argument values for blocks" > on Wed, 12 Oct 2005 02:40:48 +0900, "Ara.T.Howard" > <Ara.T.Howard@noaa.gov> writes:
>> foo = ->(foo="bar"){puts foo}
>-> means lambda?
Yes, as in Perl6. "lambda" here means lambda in other
languages, not
the lambda method in Ruby.matz.
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005