Lambda for block

e\$B0J2<\$N\$h\$&\$K!"%V%m%C%/\$Ke(B lambda e\$B\$rEO\$9\$H!"0z?t\$N?t\$,0c\$C\$F\$\$e(B
e\$B\$F\$b%(%i!<\$K\$J\$j\$^\$;\$s!#e(B

% ./ruby -ve ’
def m(&b)
b.call(&lambda {|x| p x })
end
m {|&b| p b; b.call(1,2,3) }’
ruby 1.9.0 (2007-06-26 patchlevel 0) [i686-linux]
#Proc:0xb7cded50@-e:3
1

e\$B!!\$5\$5\$@\$G\$9!#e(B

Tanaka A. wrote:

1
e\$B!!e(BProc e\$B%%V%8%’%/%He(B (A) e\$B\$GEO\$5\$l\$?%V%m%C%/\$re(B Proc
e\$B%
%V%8%’%/%He(B
e\$B\$G<u\$1\$k\$H\$-\$O!"\$=\$Ne(B (A) e\$B\$r\$=\$N\$^\$^EO\$9\$h\$&\$KJQ99\$7\$^\$7\$?!#e(B

e\$B!!\$5\$5\$@\$G\$9!#e(B

e\$B!!e(BProc e\$B%%V%8%’%/%He(B (A) e\$B\$GEO\$5\$l\$?%V%m%C%/\$re(B Proc e\$B%%V%8%’%/%He(B
e\$B\$G<u\$1\$k\$H\$-\$O!"\$=\$Ne(B (A) e\$B\$r\$=\$N\$^\$^EO\$9\$h\$&\$KJQ99\$7\$^\$7\$?!#e(B

e\$B!!AGKQ\$J5?Ld\$J\$s\$G\$9\$,!"e(B

a = Proc.new{}
def m
Proc.new
end
b = m(&a)

puts [a, b].map{|e| e.object_id}

e\$B!!\$H\$d\$C\$?\$H\$-!"e(Ba == b e\$B\$H\$J\$j\$^\$9!#e(Bproc e\$B\$de(B lambda
e\$B\$J\$iG<F@\$N5se(B
e\$BF0\$J\$N\$G\$9\$,!“e(BProc.new
e\$B\$H\$\$\$&!”!V?7\$7\$\$%\$%s%9%?%s%9\$r:n\$k!W\$he(B
e\$B\$&\$J5\$\$,\$9\$k%a%=%C%IL>\$G\$3\$N5sF0\$O\$I\$&\$J\$s\$G\$7\$g\$&\$+!#e(B1.8, 1.9
e\$B\$GF1\$8F0:n\$r\$7\$^\$9!#e(B

e\$B!!e(B1.9 e\$B\$G\$Oe(B Proc.new e\$B\$He(B proc
e\$B\$,A4\$/F1\$85sF0\$r\$9\$k\$N\$G!"\$3\$&\$\$\$&e(B
e\$B7k2L\$K\$J\$j\$^\$9!#e(B

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:31129] Re: lambda for block”
on Wed, 4 Jul 2007 05:06:26 +0900, SASADA Koichi [email protected]
writes:

|e\$B!!AGKQ\$J5?Ld\$J\$s\$G\$9\$,!"e(B
|
|a = Proc.new{}
|def m
| Proc.new
|end
|b = m(&a)
|
|puts [a, b].map{|e| e.object_id}
|
|e\$B!!\$H\$d\$C\$?\$H\$-!“e(Ba == b e\$B\$H\$J\$j\$^\$9!#e(Bproc e\$B\$de(B lambda e\$B\$J\$iG<F@\$N5se(B
|e\$BF0\$J\$N\$G\$9\$,!“e(BProc.new e\$B\$H\$\$\$&!”!V?7\$7\$\$%\$%s%9%?%s%9\$r:n\$k!W\$he(B
|e\$B\$&\$J5\$\$,\$9\$k%a%=%C%IL>\$G\$3\$N5sF0\$O\$I\$&\$J\$s\$G\$7\$g\$&\$+!#e(B1.8, 1.9
|e\$B\$GF1\$8F0:n\$r\$7\$^\$9!#e(B
|
|e\$B!!e(B1.9 e\$B\$G\$Oe(B Proc.new e\$B\$He(B proc e\$B\$,A4\$/F1\$85sF0\$r\$9\$k\$N\$G!”\$3\$&\$\$\$&e(B
|e\$B7k2L\$K\$J\$j\$^\$9!#e(B

e\$B0l=VG:\$_\$^\$7\$?\$,!"<BMx\$NJ}\$,Bg\$-\$=\$&\$J\$N\$G!V\$=\$l\$G\$h\$\$!W\$H\$7e(B
e\$B\$^\$7\$g\$&!#e(B