On eval in dynamic languages generally and in Racket specifically posted by Matthew Flatt The eval function is at the heart of a dynamic language, and it strikes many newcomers as an amazingly powerful tool. At the same time, experienced programmers avoid eval, because unnecessary use creates trouble. It’s not easy to explain why eval should be avoided or when it"s appropriate to use eval, but I’ll take another stab at it here. What is eval? Consider the following “program” in English prose: Assume that your favorite color is red. Now imagine a balloon that is your favorite color. Paint a canvas the same color as the balloon. As English goes, that’s a fairly clear program with a fairly well-defined result. When I follow those instructions, at least, I will always produce a red canvas (assuming that I have a canvas and some red paint, but a potential lack of art supplies is not the point here). I would come up with a red canvas even if I read the instructions when surrounded by people who speak only Chinese, obviously, since I’m the one reading the instructions. Furthermore, it would be straightforward to translate the program to Chinese, and then a person who reads Chinese would produce a red canvas. A translator might even take the liberty of simplifying the program to just Paint a canvas red. The translation loses some of the poetry of the original, but the result is the same. In Racket terms, the paragraph corresponds to a module. It can be compiled (i.e., translated) and optimized (i.e., simplified). A program can be made up of multiple modules that are written in different languages, but since each module can be reliably translated, they can all be compiled into some common language to run the program. Here’s a different program: Tell the person next to you “Assume that your favorite color is red.” Tell the person “Now, imagine a balloon that is your favorite color.” Tell the person “Paint canvas the same color as the balloon.” Getting a red canvas back may be ...
First seen: 2025-05-30 12:23
Last seen: 2025-05-30 19:24