Path: katsu From: katsu@sra.co.jp (WATANABE Katsuhiro) Message-ID: Date: 25 Oct 1994 03:38:41 GMT Organization: Software Research Associates, Inc.,Japan In-reply-to: deguchi@glocom.ac.jp's message of 23 Oct 1994 00:15:32 GMT Newsgroups: fj.lang.st80 Followup-To: fj.lang.st80 Subject: Re: How to use object as a key? Distribution: fj References: <38c9v4$eei@izanagi.glocom.ac.jp> 記事 <38c9v4$eei@izanagi.glocom.ac.jp> で deguchi@glocom.ac.jp (deguchi) さんいはく > Dictionaryのクラスでオブジェクトとして一意ではない、 > Arrayのようなものをキーとして使う工夫ができるでしょうか。 a Dictionary がキーから値を検索する(at:)ときには、指定されたキーと 「オブジェクトとして一意」に等しいキーを探すのではなく、 「メソッド = の意味で等しい」キーを探します。だから、普通に使って | dict arrayKey1 arrayKey2 | dict := Dictionary new. arrayKey1 := #(a b c). arrayKey2 := arrayKey1 copy. "arrayKey1 = arrayKey2 であるが、両者はオブジェクトとしては異なる." dict at: arrayKey1 put: #value1 dict at: arrayKey2 を print it すると、#value1 が得られると思います。これでは不都合ですか? (逆に、オブジェクトとして一意に等しいキーを探してもらいたいときは IdentityDictionary を使います。上の例で Dictionary の代わりに IdentityDictionary を使い、最後で dict at: arrayKey1 や dict at: arrayKey2 を試すと違いがわかると思います。) -- 渡邊克宏@SRA