Peter Norvig in PAIP says:
in modern lisps...eval is used less often (in fact, in Scheme there is no eval at all). If you find yourself using eval, you are probably doing the wrong thing
What are some of the ways to circumvent using eval
in scheme? Arent there case where eval
is absolutely necessary?
EVAL executes arbitrary source code made of Lisp's data structures. This includes function calls, macro forms, special forms, variables and self-evaluating data. APPLY applies a function to a list of arguments.
Like all programming languages, Scheme allows us to build our own procedures and add them to the set of existing ones. Very few implementations of Scheme even distinguish between the built-in functions and the user-defined ones. symbol and a set of parameters with a parameterized expression.
There are cases where eval
is necessary, but they always involve advanced programs that do things like dynamically loading some code (eg, a servlet in a web server). As for a way to "circumvent" using it -- that depends on the actual problem you're trying to solve, there's no magic solution to avoiding eval
except for ... eval
.
(BTW, my guess is that PAIP was written a long time ago, before eval
was added to the Scheme Report.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With