[plt-scheme] An Editors Tale
On Fri, 2004-02-06 at 10:10, Joe Marshall wrote:
> > Ken's list of methods with __names__ covers operator overloading and
> > metaprogramming. Methods like __getitem__ and __cmp__ are just there to
> > support overloading for indexing and comparison, respectively. I assume
> > they don't pose an issue for analysis.
>
> It depends. In a language like Scheme, a vector is an object that you
> can index. The semantics of indexing into a vector are well-defined,
> and narrow. For example, fetching the contents of a vector can never
> side effect. A fetch from a vector can be transposed with another
> operation if you can prove the other operation does not side-effect
> *that particular* vector.
>
> Now if you are willing to *guarantee* that no use of __getitem__
> anywhere will violate the standard semantics of indexing, then you can
> pretty much ignore it. Some operators, like __names__, have trivial
> semantics and such obvious intent that it seems rather pointless to
> code defensively in case someone redefined __names__ to cause side
> effects to irrelevant structures. But other operators are
> specifically *designed* to be hooked on to in arbitrary ways and these
> are the ones that cause problems.
I'm assuming the analysis would just need to be conservative. The
expression L[2] is equivalent to L.__getitem__(2). You can't know, in
general, whether a method call will have a side-effect, but method calls
aren't a special case of the analysis.
Jeremy