まつもと ゆきひろです
In message "Re: Local variables & blocks"
on 03/02/05, Yukihiro Matsumoto <matz / ruby-lang.org> writes:
||>Hmm, this is interesting issue. If you're OK, shall we discuss at the
||><ruby-list / ruby-lang.org> list in Japanese?
||
|| I'm Okay.
|
|OK, let's move. Honestly, it's kinda hard for me to discuss.
ということで、引っ越してきました。やはり英語で難しいことを話
すのはツラいです。
元々はnilが偽なのは良くないのでは、という話です(末尾参照)。
Schemeでは「未初期化の変数値」である#<undef>(Gaucheの場合)は
偽ではなく真です。だから、Rubyでもそうあるべきでは、という主
張なのだと理解しました。
それに対する私の返答は
* RubyはRuby、SchemeはSchemeなので、Schemeの#<undef>が真だ
からといってRubyのnilが真でなければならない理由にはなら
ない。
というものです。さらに言えば(ruby-talkでは書かなかったけど)、
* nilを真にするというのは(Schemeでなく)Lispの伝統に反する。
* 互換性で大問題が起きる
* nilは3値論理(真、偽、未定義)を表現するのに都合が良い
などの状況もあります。ということで、nilを真にすることも、nil
を唯一の偽の値にすることもRubyについてはありえないかなあと考
えています。ちなみに昔はnilは唯一の偽値でした。
とはいうものの、「#<undef>は偽であってはならない理由」という
のに興味はありますから(R5RSにも理由の説明はないし)、ぜひとも
聞きたいなあと思っているのです。
まつもと ゆきひろ /:|)
In message "Re: Local variables & blocks"
on 03/02/05, ichimal / fenix.ne.jp <ichimal / fenix.ne.jp> writes:
|
|Hi,
|
|In message "Re: Local variables & blocks"
| on 03/02/04, matz writes:
|
|>Hmm, this is interesting issue. If you're OK, shall we discuss at the
|><ruby-list / ruby-lang.org> list in Japanese?
|
| I'm Okay.
|
|>|>What's wrong with that?
|>|
|>| Is it meaning that Scheme is just Scheme, Ruby is just Ruby?
|>
|>Maybe. Scheme is not an excuse for me. I'm interested in whether
|>there's any other reason to "separate false and nil".
|
| I think, nil in Ruby is representative value of "{unavailable|invalid|
|no effect} in this context" rather than "not initialized".
|
| I think, following representation is valid:
| a variable points to nil.
|
| But following representation is not good:
| a variable points to non-initialized value.
|It should be: a variable is not initialized.
|
|# But, we can initialize a variable with non-initialized value
|# explicitlly by tricky way s.t. (set! x (if #f #f)) in scm, and it
|# should not be forbidden. It's programmer's responsibility.
|## Note for reader who don't know scm:
|## (set! x (if #f #f)) => #<unspecified>,
|## (set! x #<unspecified>) => error.
|## It may be great policy. This is why I said "tricky way".
|
| Then, the semantics "nil is also false" restricts the meaning of
|{unavailable|invalid|no effect}. It's default value of the default
|value for {unavailable|invalid|no effect} but the default^2 shuold
|belong to programmer, not to PL, I think.
|
| e.g.
| def questionnaire
| print_somewhat_Q
| str = gets
| parse_answer(str) if str
| end
|
| This method should return nil as "non-effective answer" or somewhat
|effective answer including boolean. When a programmer sets the default
|answer to false, the programmer may save an extra test because "nil is
|also false" :-P
|
|Thanks.
|
|----
|1002.(ichimal)
|SUZUKI Shingo.