Dan Sugalski writes: : At 12:59 PM +0000 3/28/02, Piers Cawley wrote: : >Wouldn't it be nice if you could do: : > : >class Foo { : > ... : > : > &{intern('{}')} := method ($self: $key) is lvalue { : > ... : > } : >} : > : >So, later, you could do: : > : >$obj = Foo.new; : > : >$obj{something} = $something_else; : > : >ie, overriding hash lookups, array lookups, whatever. (I'm using a : >Lispish 'intern' here to return a symbol from a string by the way, I : >doubt it's a good 'real' syntax, but I'm not at all keen on C<sub '{}' : >{...}> : : Just have a ASSIGNHASH (or ASSIGNARRAY) sub and we'll probably do : this for you...
In fact, all objects will probably inherit such a method that makes an object look like a hash if you treat it as one, where the keys to the hash are mapped to the accessor methods. So you'd merely be overriding that method. The name of the method might well be &operator::{} rather than something uppercase. Depends on how we work out the relationship with ordinary operator overloading. In any event, operator overloading will be done simply by defining the appropriately named method. Larry