Anonymous user
Runtime evaluation: Difference between revisions
→{{header|Common Lisp}}: Merge the 2 Common Lisp sections into 1 section. We had 2 sections after a broken </lang> tag swallowed the 1st section, and I stupidly added a 2nd section.
(reword to avoid "executing programs" language) |
(→{{header|Common Lisp}}: Merge the 2 Common Lisp sections into 1 section. We had 2 sections after a broken </lang> tag swallowed the 1st section, and I stupidly added a 2nd section.) |
||
Line 124:
=={{header|Common Lisp}}==
The <tt>eval</tt> function evaluates Lisp code at runtime.
<lang lisp>(eval '(+ 4 5)) ; returns 9</lang>
In Common Lisp, programs are represented as trees (s-expressions). Therefore, it is easily possible to construct a program which includes externally specified values, particularly using backquote template syntax:
Line 139 ⟶ 138:
(funcall (eval '(lambda (n) (+ 4 n)))) a-number)</lang>
If your program came from a file or user input, then you have it as a string, and [http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_rd.htm <code>read</code>] or <code>read-from-string</code> will convert it to s-expression form:
<lang lisp>(eval (read-from-string "(+ 4 5)"))</lang>
Common Lisp has lexical scope, but <code>eval</code> always evaluates “in the null lexical environment”. In particular,
There are no sandboxing facilities in standard Common Lisp. Because CL has so many shared mutable objects (packages and symbols), no attempt to design a CL sandbox (other than at the OS process level<!-- ; see e.g. [telnet://prompt.franz.com prompt.franz.com] (not mentioning because this seems to be down now)-->) has yet succeeded.▼
There are no standardized debugging facilities specific to the <code>eval</code> operation itself, but code evaluted may be affected by the current [http://www.lispworks.com/documentation/HyperSpec/Body/03_c.htm global declarations], particularly the [http://www.lispworks.com/documentation/HyperSpec/Body/d_optimi.htm <code>optimize</code> declaration]'s <code>debug</code> and <code>safety</code> qualities.▼
<lang lisp>(let ((x 11) (y 22))
Line 168 ⟶ 148:
(format t "~%x + y = ~a" (eval '(+ x y))))</lang>
One way to fix the error is to
<lang lisp>(let ((x 11) (y 22))
(format t "~%x + y = ~a" (eval `(+ ,x ,y))))</lang>
▲There are no sandboxing facilities in standard Common Lisp. Because CL has so many shared mutable objects (packages and symbols), no attempt to design a CL sandbox (other than at the OS process level<!-- ; see e.g. [telnet://prompt.franz.com prompt.franz.com] (not mentioning because this seems to be down now)-->) has yet succeeded.
▲There are no standardized debugging facilities specific to the <code>eval</code> operation itself, but code evaluted may be affected by the current [http://www.lispworks.com/documentation/HyperSpec/Body/03_c.htm global declarations], particularly the [http://www.lispworks.com/documentation/HyperSpec/Body/d_optimi.htm <code>optimize</code> declaration]'s <code>debug</code> and <code>safety</code> qualities.
=={{header|E}}==
|