symbolic python
Benjamin Tai
bt98 at doc.ic.ac.uk
Sat May 25 14:31:30 EDT 2002
> Hi, Benjamin. Not as you say it.
>
> However, I often met needs that could have been resolved as you say in
> some other languages, and that were easily addressed using more Pythonic
> paradigms. My belief if that Python is very flexible for such problems,
> if you accept to "negotiate" with the language.
>
> If you explain a bit more precisely what is the problem you are trying to
> solve, it is likely that many members of the Python list will have ideas
> or solutions to offer, that you might find workable and even elegant.
> This is my guess, do not take it as a promise :-).
>
I am afriad it is only simple (stupid + abstract) question out of
cuirosity. It does sound like some simple form of program transformation
(although I am not try to achieve any optimisation or static checking
here).
Example 1):
Could it be possible to have a parser to rewrite my derived class:
class base:
def b_fun(self):
pass
def overloaded(self):
print "base"
class derived(base):
def overloaded(self):
print "derived"
into something like:
class derived(base):
def b_fun(self):
pass
def overloaded(self):
print "derived"
such that methods inherited from the base class is also written inside
the derived class.
Example 2):
Could it be possible to have a parser to rewrite my derived class:
class base:
def b_fun(self):
pass
class derived(base):
def d_fun(self):
self.b_fun()
into something like:
class derived(base):
def d_fun(self):
self.b_fun()
def b_fun(self):
pass
such that methods called from the base class is also written inside the
derived class.
Simply speaking, I can look up a module to find out name of the
functions located inside. Could I also find out their function body?
I can get Python to evaluate the function, but is it possible to return
the source code of the funciton body at the same time?
In a symbolic language, I would imagine there should be direct access
towards the body of the function. Could it be possible for Python to
have a similar behaviour?
Thanks
Ben
More information about the Python-list
mailing list