Search code examples
pythoncexeceval

The equivalent python exec/eval commands in C


is there a exec() / eval() function in C??

for example..

exec(printf(3 + 4))

or

eval(printf(3 + 4))

i've done this in python... but i don't know how to do this in C and C languages..

i understand that this might be harmful in python as it can take any input.. so to overcome that i came to C which is more strict

this is just a experiment i am curious to learn

an explaination would be appreiciated

i am using sublime text (just in case...:] )


Solution

  • Python is a simplified Lisp and in Lisp there is the eval/apply paradigm. In C this paradigm exists only inside the compiler. The compilation system of C uses eval/apply, also called the Maxwell equations of software. But at user level you do not interact with eval/apply, only if you write/develop in C a compiler for a language you cope with.

    So in C you need to implement this yourself, in case you develop some language that is Turing complete (a Turing machine is equivalent with eval+apply cycle).