[#17615] substitution at when-clause — Takaaki Tateishi <ttate@...>

立石です.

47 messages 2002/07/01
[#17619] Re: substitution at when-clause — matz@... (Yukihiro Matsumoto) 2002/07/01

まつもと ゆきひろです

[#17621] Re: substitution at when-clause — Takaaki Tateishi <ttate@...> 2002/07/02

At Tue, 2 Jul 2002 02:54:01 +0900,

[#17622] Re: substitution at when-clause — matz@... (Yukihiro Matsumoto) 2002/07/02

まつもと ゆきひろです

[#17624] Re: substitution at when-clause — Takaaki Tateishi <ttate@...> 2002/07/02

At Tue, 2 Jul 2002 13:30:17 +0900,

[#17627] Re: substitution at when-clause — matz@... (Yukihiro Matsumoto) 2002/07/02

まつもと ゆきひろです

[#17630] Re: substitution at when-clause — Takaaki Tateishi <ttate@...> 2002/07/02

立石です.

[#17631] Re: substitution at when-clause — matz@... (Yukihiro Matsumoto) 2002/07/02

まつもと ゆきひろです

[#17635] Re: substitution at when-clause — Takaaki Tateishi <ttate@...> 2002/07/03

立石です.

[#17639] Re: substitution at when-clause — matz@... (Yukihiro Matsumoto) 2002/07/03

まつもと ゆきひろです

[#17644] Re: substitution at when-clause — keiju@... (石塚圭樹) 2002/07/03

けいじゅ@日本ラショナルソフトウェアです.

[#17645] Re: substitution at when-clause — matz@... (Yukihiro Matsumoto) 2002/07/03

まつもと ゆきひろです

[#17647] Re: substitution at when-clause — keiju@... (石塚圭樹) 2002/07/03

けいじゅ@日本ラショナルソフトウェアです.

[#17649] Re: substitution at when-clause — Takaaki Tateishi <ttate@...> 2002/07/03

At Wed, 3 Jul 2002 17:48:58 +0900,

[#17651] Re: substitution at when-clause — keiju@... (石塚圭樹) 2002/07/03

けいじゅ@日本ラショナルソフトウェアです.

[#17730] Re: self in block — masaki <GEC01122@...>

16 messages 2002/07/20

[#17764] Re: self in block — masaki <GEC01122@...>

31 messages 2002/07/22
[#17765] Re: self in block — matz@... (Yukihiro Matsumoto) 2002/07/23

まつもと ゆきひろです

[#17768] Re: self in block — Tanaka Akira <akr@...17n.org> 2002/07/23

In article <1027383423.558649.31176.nullmailer@picachu.netlab.jp>,

[#17769] Re: self in block — matz@... (Yukihiro Matsumoto) 2002/07/23

まつもと ゆきひろです

[#17770] Re: self in block — Tanaka Akira <akr@...17n.org> 2002/07/23

In article <1027404202.545188.1283.nullmailer@picachu.netlab.jp>,

[#17771] Re: self in block — matz@... (Yukihiro Matsumoto) 2002/07/23

まつもと ゆきひろです

[#17772] Re: self in block — Tanaka Akira <akr@...17n.org> 2002/07/23

In article <1027406979.880878.1358.nullmailer@picachu.netlab.jp>,

[#17832] Re: [ruby-cvs] ruby: * random.c: replace with Mersenne Twister RNG. — nobu.nakada@...

なかだです。

17 messages 2002/07/26
[#17835] Re: [ruby-cvs] ruby: * random.c: replace with Mersenne Twister RNG. — matz@... (Yukihiro Matsumoto) 2002/07/26

まつもと ゆきひろです

[#17837] Re: [ruby-cvs] ruby: * random.c: replace with Mersenne Twister RNG. — nobu.nakada@... 2002/07/26

なかだです。

[#17842] Re: [ruby-cvs] ruby: * random.c: replace with Mersenne Twister RNG. — matz@... (Yukihiro Matsumoto) 2002/07/26

まつもと ゆきひろです

[#17886] line number(Re: Re: [ruby-cvs] ruby: * random.c: replace with Mersenne Twister RNG.) — nobu.nakada@... 2002/08/02

なかだです。

[#17893] Re: line number(Re: Re: [ruby-cvs] ruby: * random.c: replace with Mersenne Twister RNG.) — matz@... (Yukihiro Matsumoto) 2002/08/03

まつもと ゆきひろです

[#17897] Re: line number(Re: Re: [ruby-cvs] ruby: * random.c: replace with Mersenne Twister RNG.) — nobu.nakada@... 2002/08/03

なかだです。

[#17973] Re: line number(Re: Re: [ruby-cvs] ruby: * random.c: replace with Mersenne Twister RNG.) — nobu.nakada@... 2002/08/11

なかだです。

[ruby-dev:17706] self in block

From: masaki <GEC01122@...>
Date: 2002-07-18 02:53:29 UTC
List: ruby-dev #17706
正木です。

block 内の変数の問題については、変数の scope のこと以外に、私にとっては
重要な問題がもう一つあります。

今仮に
{ <x> ・・・ }
で block 内の変数の local 性が保証されたとしても

class Sequence
  def initialize(list=[],*parameter)
    @list=list
    @para=parameter
    @lambda=eval "lambda{"+yield+"}"
  end

  def [](n)
    @list[n] || @list[n]=@lambda.call(n,*@para)
  end
end

Fact=Sequence.new([1]){"|n| n*self[n-1]"}

を

class Sequence
  def initialize(list=[],*parameter,&block)
    @list=list
    @para=parameter
    @lambda=block
  end
end

で置き換えるためには

Fact=Sequence.new([1]){<n> n*self[n-1]}

の self が Fact を指してくれないと困ります。

そこで提案ですが、

block が 
object.method(){<x> ...}
の形のとき、その中での self は、その method を呼んだ object を
指す。

というのは如何でしょうか。

上記の例では、この block が渡される initialize
を呼んでいるのは Fact であると解釈して(self=Sequence ではなく)
self=Fact
ですが無理ですか?

上記の仕様が採用されれば
Proc.new{<n> (n==0)? 1: n*self[n-1]}[5] => 120
といったこともできて便利だと思いますが。

In This Thread

Prev Next