From: Ken Bloom Date: 2007-03-02T11:10:07+09:00 Subject: Re: Duck Typing Hash-Like Objects On Fri, 02 Mar 2007 10:01:06 +0900, Gary Wright wrote: > On Mar 1, 2007, at 7:38 PM, James Edward Gray II wrote: >> You're still type checking, you're just doing it in a more fragile way. >> If you want to type check, use the class, I say. > > Yet if I test for (Hash == mystery_obj) that would not allow someone to > pass an RBTree object instead, which I think is a very reasonable thing > to allow and works just fine if I only use #fetch. > > A minimum interface to an indexable collection might be: > > has_key?(key) > fetch(key) > store(key, val) > > In a quick look it seems like only Hash and RBTree implement those > methods though. Is there a good reason why you can't just use different constructors for different types of objects, then just trust that they duck-type OK? --Ken -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/