A 'Python like' language

Stephen Horne steve at ninereeds.fsnet.co.uk
Sat Mar 27 20:35:43 EST 2004


On Fri, 26 Mar 2004 20:25:11 +0100, Valentino Volonghi aka Dialtone
<dialton3.NOSPAM#_ME_TAG#@virgilio.it> wrote:

>Anyway GvR just posted on the python-dev saying this:
>
>==
>No, I want to reserve the leading dot for attribute assignment to a
>special object specified by a 'with' statement, e.g.
>
>with self:
>    .foo = [1, 2, 3]
>    .bar(4, .foo)
>==

I missed that. There's good precedent - it's the Pascal 'with' block,
but better (the leading dot tells you that you're dealing with a
'with' item rather than normal scoping rules). But - well - just
recently, people keep telling me that indented blocks are purely about
control flow. I keep disagreeing, but no-one has bothered agreeing
with me so I was feeling rather lonely and miserable in this crusade
:-(

A 'with' block clearly has nothing at all to do with control flow. All
it does is provide some kind of local context for the contents of the
block. Very much like a suggestion or two that I have made recently
(none of which all that original, as far as I can tell).

Nonetheless, I will object. The with block, in this form, provides an
abbreviated alias for one identifier. Zero length is quite severely
abbreviated, of course, but better 'compression' could frequently be
achieved by abbreviating two or more identifiers.

For general applications, I'd rather have a small blocks and a simple
alias facility. An alias would never make it into dictionaries - it
would be handled entirely by the compiler. For example...

  someverylongname = 1

  block :
    alias x = someverylongname

    x = 2

  print someverylongname  #  result is '2'

Depending on how the alias was implemented, it might also be possible
to alias certain kinds of expression...

  alias x = someobj.someobj.membername

I wouldn't allow arbitrary expressions here, and it raises questions
about when the alias is bound to the referenced object which start to
push things towards normal identifiers so I'd have serious thoughts,
but there are cases that are probably worth considering where an alias
could reasonably be bound by the compiler without needing to insert
anything into any runtime dictionaries.

The trouble is that doing something like that would probably be
difficult as the compiler would need dictionary-like symbol tables
above and beyond what exists in the runtime environment, and the
run-time environment would have to provide for storage beyond what is
held in the normal dictionaries.

Anyway, personally, I'd say the prefix dot should be reserved for
'self' if used at all. It will certainly be by far the most common
case, perhaps to the point that people will assume 'self' as soon as
they see the prefix dot, which means that readability will be affected
by using 'with' for other variables. And if using 'with' for anything
other than 'self' creates readability issues and gets to be considered
bad style, the 'with' line itself is redundant.


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk



More information about the Python-list mailing list