Runtime evaluation

From Rosetta Code
Revision as of 15:35, 22 April 2009 by 165.222.184.132 (talk) (Added Common Lisp section)
Task
Runtime evaluation
You are encouraged to solve this task according to the task description, using any language you may know.

Demonstrate your language's ability for programs to execute other programs in the language provided at runtime. Show us how you get values in and out (e.g. environments, arguments, return values), and what facilities for restricting (e.g. sandboxes, resource limits) or specializing (e.g. debugging facilities) the execution.

You may not invoke a separate evaluator program, or invoke a compiler and then its output, unless the interface of that program, and the syntax and means of executing it, are considered part of your language/library/platform.

For a more restricted task, see Eval in environment.

Common Lisp

Using a list to represent code

<lang lisp>(eval '(+ 4 5)) ; Evaluate the program (+ 4 5)</lang>

Using a String to represent code

<lang lisp>(eval (read-from-string "(+ 4 5)")) ; Evaluate the program (+ 4 5)</lang>