Why we will use obj$func() often

Mark Hahn mark at prothon.org
Sun Apr 25 23:58:42 EDT 2004


"Greg Ewing" <greg at cosc.canterbury.ac.nz> wrote in message
news:c6hvdk$bs63j$1 at ID-169208.news.uni-berlin.de...
> Mark Hahn wrote:
> > The advantage of prefix symbols that Ruby and Prothon use right now is
that
> > the compiler and the program reader don't have to scan the code at all
to
> > see what scope the var belongs to.  When you see the & you know it's in
the
> > surrounding function,
>
> Hang on a minute. Do you literally mean the immediately
> surrounding function, and not one further out? In
>
>    def f():
>      def g():
>        def h():
>          &x = 42
>        h()
>      g()
>      print x
>
> does the &x in h refer to the x in f? If it does, then I
> don't see how you can deduce that in a single pass. If it
> doesn't, then how do you refer to the x in f from h?

You cannot.  Yes it literally means the immediately surrounding function.
In your example, I can't think of any scheme we've discussed that accesses x
in function f.  Python surely cannot.

I understand this is quite limiting, but it's simple. As always, I'm open to
suggestions...





More information about the Python-list mailing list