Open nbro opened 3 years ago
Hi, I met the same problem when I was evaluating the dataframes. So what I should do is to create a new class that includes repr ? or any better suggestions? Thank you!
I understand the confusion, but I think eval is also miss leading as it could be confuse with the evaluation function. I like compile as it creates a callable from the representation. The discussion is leading me to the more general question, could we eliminate the compile function altogheter? Or more simpler could it be anything else than compile of eval?
It looks to me that python's compile is doing a somewhat similar thing no?
The function
compile
defined insidegp
actually calls Python'seval
and notcompile
, so the name of this function is highly misleading. In fact, you can get syntax errors if you try to evaluate an individual that cannot be converted to a string and evaluated as an expression. For example, if you had defined a terminal of the formThen use
a
as a terminal of your primitive set, you may get aSyntaxError: invalid syntax
if you calgp.compile
to evaluate an individual that usesa
as a terminal, more precisely, you may get an error message like thisIf you had defined a
__repr__
method forMyTerminal
that returns something that can be evaluated, then you would not get this error.So, given that Python's
eval
andcompile
are different functions, it's highly misleading to have a functioncompile
that actually callseval
. In other words, I'm proposinggp.compile
to be changed togp.eval
orgp.evaluate
.