4 ms·
How is this any different from `eval`, except that lisp's syntax is particularly well suited to being `eval`'d by virtue of being so easy to parse?
by capitalsigma 10y ago
How is this any different from `eval`, except that lisp's syntax is particularly well suited to being `eval`'d by virtue of being so easy to parse?
- dfox 10y agoEval executes the code, while read only parses it. (incidentally, in lisp, to get same effect as eval in JS/Perl/whatever, you pass the string into read-from-string and then the result from that into actual eval)
- chowes 10y agoI think the main benefit comes from being able to build tools to transform, refactor, etc. your code in very little effort.
- agumonkey 10y agoYes, it raises the abstraction level to allow 'meta' programming as the normal level. Brown university had a chapter on their old PAIP book saying that they voluntarily skipped parsing because it's of no interest, so they used a scheme as a basis for classes.
- lottin 10y agoThe difference is that in most languages eval() parses a character string as code and evaluates it, whereas in Lisp you evaluate language objects (e.g. lists of symbols) rather than strings.
- eyelidlessness 10y agoAs mentioned, `eval` executes code. While macros are generally about manipulating code for eventual evaluation, `read` enables more than that, for instance static analysis. The distinction is also explicit in the term "REPL" (read eval print loop), though many REPLs just pass the input to an interpreter.