Andrew Koenig wrote:
I am not advocating this, but this could be:
    

  
def abs(self):
   with self:
     with math:
       return sqrt(x**2 + y**2 + z**2)
    

  
The idea being that "with self" use
creates a new namespace:
   newGlobal= oldGlobal + oldLocal
   newLocal= names from self
    

You don't know what those names are until runtime.  Suppose, for example,
that self happens to have acquired an attribute named "math"?  Then

	with self:
	    with math:
		 return sqrt(x**2 + y**2 + z**2)

doesn't do what you expected, because "with math" turns out to have meant
"with self.math"

  
You are right, they rules of the game need to be set out more clearly.
I had envisaged that the new and newer above would be executed at
runtime.

To take your example:
   with self:
      with math:
         return self.math(x**2 + y**2 + z**2)

or:
  with math:
    with self:
       return math(x**2 + y**2 + z**2)

Would appear to do it.  The important thing is that math and self are
available in the global namespace.

Colin W.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to