Re: Generics vs. Message passing: object namespaces
"Joe Marshall" <[email protected]> Fri, 23 Feb 2007 20:16:27 -0800
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
Again I ask, is it an observable property? Is there code I can write that gives me different results depending on whether I look up the method by using the object first or the method name first? On 2/23/07, [email protected] <[email protected]> wrote: > > What do you mean by `primary'? Is it an observable property? > > > > When you are selecting a method through a two-dimensional dispatch (which > > you > > must be doing regardless because that is the dimension of the method > > space) > > it makes not one whit of difference if you choose the row first or the > > column first, > > you still end up at the same location. > > Hmm, not sure where the misunderstanding is here. I think it's pretty > clear: with obj1.foo, I look in the namespace associated with 'obj1'. > With obj2.foo, I look in the namespace associated with 'obj2'. Not clear to me at all. We have two items: an object of some type and a name `foo'. We have a function (the dispatch function) that maps from the tuple of object types and names to invokable methods. Essentially, obj1.foo is evaluated as this: (funcall (select-method (type-of obj1) 'foo) obj1) Now it is *usually* the case that select-method works by inspecting a table that is manifestly part of the type descriptor, but that is an implementation detail. It would just as well if stored the methods on the property list of the method name indexed by the type name. We depend on the types of different objects being distinguishable (this almost goes without saying). It would *also* work just as well if we stored the methods in a lexical closure somewhere and arranged for that closure to be placed in the function cell of the symbol so that the dispatch happened through the function call mechanism. Essentially I am taking `select-method' and swapping the arguments: (funcall (select-method 'foo (type-of obj1)) obj1) and then currying (funcall (funcall (curried-select-method 'foo) (type-of obj1)) obj1) and simply implemented `curried-select-method' as `symbol-function'. Obviously re-ordering the arguments to a function makes no difference if I re-order them at all call sites, and currying a function makes no difference if I arrange for the call sites to use the curried form. Semantically, these are identical. > With > (foo obj1), I look in the same namespace that functions are looked up > in. With (foo obj2), I also look in the same namespace functions are > looked up in. In the latter two cases, it's the same namespace. In > the former two cases, they are different namespaces. > > It's not a grid, but a graph; cadr is not the same thing as cdar. No, but if I swap all calls to CADR with calls to CDAR and swap the contents of all cadrs with cdrs, there is no observable difference. It doesn't matter how you get to the cell in question, it matters what the contents are. -- ~jrm