I'm presenting some aspects of functional programming to my students. We are using python as our main language. To me, composing functions is one of the main aspects of functional programming. To illustrate this i proposed the following example, nothing but classic.
import dis
def f(x):
return 2*x+1
def g(x):
return x**2
def comp(fun1, fun2):
return lambda x:fun1(fun2(x))
dis.dis(f)
dis.dis(g)
dis.dis(comp(f,g))
I was just wondering, is there a way to get back the expression for comp(f,g) with the dis module. I understood there are parameters to tune the level of recursive calls sommehow, but I did not spend enough time exploring. I also came across the ast module which looked a bit tedious at first glance.
So I thought this was a question for Stackoverflow : way before any idea of symbolic calculcation, is there a way to get dis describe comp(f,g) being lambda x:2*x**2+1 or ast displaying the abstract syntax tree for this expression ?
Thank's for any advice.