A better self

Alex Martelli aleax at aleax.it
Sat Jul 20 04:15:59 EDT 2002


Grant Griffin wrote:
        ...
>>to return various quantities.  In a language that boasts of how
> 
> I don't remember any "boasting".  Python is for the humble (except for
> maybe Tim and Fredrik <wink>).

Nah, ALL of us bots are unhumble -- even I, the one programmed for
occasional human-like errors in order to better fool you all.

>    with self:
>       result=sin(t)*x**y+sqrt(z)  # A pretend formula
> 
> I don't know if there's a technical reason (in terms of either Python
> grammar or C implementation) why this wouldn't work, but perhaps it's not

If we adopted the Visual Basic variant of this, with a leading dot
to distinguish fields of the with-ed objects (as others have often
suggested), technical feasibility would be guaranteed.

Without such a tweak, it's something of a mess.  Is this statement
computing a local variable result, or a field self.result, for
example?  Either interpretation could be quite desirable, and any
choice between them seems rather arbitrary.  Access to local
variables inside a with would be slow, since each time it would
have to be preceded by a lookup in the with-ed object.  Etc, etc.

WITH the leading-dot convention, and some drastic simplification
about what happens on nested with (e.g.: all leading-dot names
always only refer to the innermost with -- there is just NO way
to refer to outer-nested withs), I think it would be feasible.

Desirable, I dunno...:

> any-construct-that's-in-pascal-and-ada-but-not-in-C
>    -can't-be-all-bad-<wink>-ly y'rs,

yes but, if it's also in Visual Basic ... ???


Alex




More information about the Python-list mailing list