[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Receiving blocks in Proc?

james.cromwell

11/4/2004 9:19:00 PM

p = Proc.new { |*args,&block| }

produces syntax error

p = Proc.new { |*args,&block| }
----------------------^

It appears that Proc objects cannot receive blocks?
11 Answers

Yukihiro Matsumoto

11/4/2004 9:38:00 PM

0

Hi,

In message "Re: Receiving blocks in Proc?"
on Fri, 5 Nov 2004 06:23:43 +0900, james.cromwell@gmail.com (James) writes:

|p = Proc.new { |*args,&block| }
|
|produces syntax error
|
|p = Proc.new { |*args,&block| }
|----------------------^
|
|It appears that Proc objects cannot receive blocks?

Until 1.9, yes.

matz.


Mark Hubbart

11/4/2004 9:48:00 PM

0

On Fri, 5 Nov 2004 06:23:43 +0900, James <james.cromwell@gmail.com> wrote:
> p = Proc.new { |*args,&block| }
>
> produces syntax error
>
> p = Proc.new { |*args,&block| }
> ----------------------^
>
> It appears that Proc objects cannot receive blocks?

Not in 1.8. 1.9 has it; it's slated for 2.0, I believe...

b = lambda{|*args, &blk| args.each{|arg| blk[arg]}}
==>#<Proc:0x00522420@(irb):1>
b.call(1,2,3) {|n| puts "number #{n}"}
number 1
number 2
number 3
==>[1, 2, 3]
[RUBY_VERSION, RUBY_RELEASE_DATE]
==>["1.9.0", "2004-09-17"]


cheers,
Mark


Mark Hubbart

11/4/2004 10:01:00 PM

0

On Fri, 5 Nov 2004 06:37:47 +0900, Yukihiro Matsumoto
<matz@ruby-lang.org> wrote:
> Hi,
>
> In message "Re: Receiving blocks in Proc?"
> on Fri, 5 Nov 2004 06:23:43 +0900, james.cromwell@gmail.com (James) writes:
>
> |p = Proc.new { |*args,&block| }
>
>
> |
> |produces syntax error
> |
> |p = Proc.new { |*args,&block| }
> |----------------------^
> |
> |It appears that Proc objects cannot receive blocks?
>
> Until 1.9, yes.

Will it eventually be possible to pass the block when using the
bracket-call syntax? ie:

block[...] {|*args| ...}

Right now it gives a parse error. Or would that make it too difficult
for the parser?

thanks,
Mark


Yukihiro Matsumoto

11/5/2004 12:42:00 AM

0

Hi,

In message "Re: Receiving blocks in Proc?"
on Fri, 5 Nov 2004 07:00:35 +0900, Mark Hubbart <discordantus@gmail.com> writes:

|Will it eventually be possible to pass the block when using the
|bracket-call syntax? ie:
|
| block[...] {|*args| ...}
|
|Right now it gives a parse error. Or would that make it too difficult
|for the parser?

I have no plan to allow this. I have alternative idea, which allows
parentheses instead of brackets. But it still is a vague idea, no
promise.


matz.


gabriele renzi

11/5/2004 1:38:00 AM

0

Yukihiro Matsumoto ha scritto:

> Hi,
>
> In message "Re: Receiving blocks in Proc?"
> on Fri, 5 Nov 2004 07:00:35 +0900, Mark Hubbart <discordantus@gmail.com> writes:
>
> |Will it eventually be possible to pass the block when using the
> |bracket-call syntax? ie:
> |
> | block[...] {|*args| ...}
> |
> |Right now it gives a parse error. Or would that make it too difficult
> |for the parser?
>
> I have no plan to allow this. I have alternative idea, which allows
> parentheses instead of brackets. But it still is a vague idea, no
> promise.


(on the notes from James Brown)
please please please please (please please oh oh )

Ok, I'd love this, sorry for the noise :)

nobu.nokada

11/12/2004 3:21:00 AM

0

Hi,

At Fri, 5 Nov 2004 10:38:43 +0900,
gabriele renzi wrote in [ruby-talk:119146]:
> > I have no plan to allow this. I have alternative idea, which allows
> > parentheses instead of brackets. But it still is a vague idea, no
> > promise.
>
>
> (on the notes from James Brown)
> please please please please (please please oh oh )

I tried it but it breaks many code.

--
Nobu Nakada


nobu.nokada

11/12/2004 8:18:00 AM

0

Hi,

At Fri, 12 Nov 2004 12:38:37 +0900,
Yukihiro Matsumoto wrote in [ruby-talk:120009]:
> |> > I have no plan to allow this. I have alternative idea, which allows
> |> > parentheses instead of brackets. But it still is a vague idea, no
> |> > promise.
>
> |I tried it but it breaks many code.
>
> Yours was too thorough, I guess. What I was thinking was to allow
> calling parentheses only after
>
> * predefined local variables
> * explicit method calls (with parentheses)
>
> which should break less code.

Well, it did just those things, IIRC. Yes, "many" was not
correct word, but, even in bundled libraries, tests and
samples, some codes were using the variable of the same name as
a method.

--
Nobu Nakada


gabriele renzi

11/12/2004 10:23:00 AM

0

nobu.nokada@softhome.net ha scritto:

> Hi,
>
> At Fri, 12 Nov 2004 12:38:37 +0900,
> Yukihiro Matsumoto wrote in [ruby-talk:120009]:
>
>>|> > I have no plan to allow this. I have alternative idea, which allows
>>|> > parentheses instead of brackets. But it still is a vague idea, no
>>|> > promise.
>>
>>|I tried it but it breaks many code.
>>
>>Yours was too thorough, I guess. What I was thinking was to allow
>>calling parentheses only after
>>
>> * predefined local variables
>> * explicit method calls (with parentheses)
>>
>>which should break less code.
>
>
> Well, it did just those things, IIRC. Yes, "many" was not
> correct word, but, even in bundled libraries, tests and
> samples, some codes were using the variable of the same name as
> a method.


sorry if I'm asking a stupid question, I know I am dumb.. but would'nt
be enough to give precedence to a method when called and to the variable
when not explicit called?
I.e.


a=proc {|x| 'proc' }
a # #<Proc:0x02befeb0>
a() # 'proc'
a 10 # 'proc'
def a(x) p 'meth' end
a # #<Proc:0x02befeb0> precedence to var, as now
a() # 'meth' precedence to meth as now
a 10 # 'meth' precedence to meth as now


Maybe this is impossible to do at runtime and when building the ast you
were just making a simple 'text substitution' like
a() => a.call() ?

nobu.nokada

11/12/2004 1:01:00 PM

0

Hi,

At Fri, 12 Nov 2004 19:23:27 +0900,
gabriele renzi wrote in [ruby-talk:120026]:
> > Well, it did just those things, IIRC. Yes, "many" was not
> > correct word, but, even in bundled libraries, tests and
> > samples, some codes were using the variable of the same name as
> > a method.
>
>
> sorry if I'm asking a stupid question, I know I am dumb.. but would'nt
> be enough to give precedence to a method when called and to the variable
> when not explicit called?
> I.e.
>
>
> a=proc {|x| 'proc' }
> a # #<Proc:0x02befeb0>
> a() # 'proc'
> a 10 # 'proc'
> def a(x) p 'meth' end
> a # #<Proc:0x02befeb0> precedence to var, as now
> a() # 'meth' precedence to meth as now
> a 10 # 'meth' precedence to meth as now

Yes, my patch implemented as you mentioned. But, for instance,
a code in sample/test.rb:

method = method(m)

`method' is defined at the moment assignment expression
appears, so `method()' in RHS calls that variable which is
defined but not assigned yet.

--
Nobu Nakada


WanChonRen

2/1/2009 6:38:00 AM

0


Don't you know WanChonRen is formerly known as Goondoo ?

AleXX wrote:
> Hey! You are multiple mick of that kah kah kah observer ?
> "yan dao" <ZaiZai@yahoo.com.sg> wrote in message
> news:FGUgl.203$eK2.130@nwrddc01.gnilink.net...
>> Now you we know that the pay increase of our MIWs multimillion salaries
>> are unjust and corrupt. Unlike the excuse from old man that said without
>> multimillion salaries these people will leave and Sinkapoor will be kaput
>> finished. All but lies and to deceive the people of Sinkapoor.
>>
>> "truth" <truth@universe.com> wrote in message
>> news:h4Rgl.15986$cu.3307@news-server.bigpond.net.au...
>>> Yes the mood is right. The action correct. Law will
>>> be introduced in congress to limit the pay of ceo of
>>> company taking tax payer handout to that of the
>>> president US$400,000.
>>> Now we know that LHL as PM gets about S$3
>>> million. The for show President gets more.
>>> Singaporeans when are u going to cut the pay of this
>>> highly overpaid greedy idiots who is only good at
>>> delivering u people one recession after another.
>>>
>>>
>>
>
>