Add a docstring for hy-eval

It's just a copy of the documentation for hy.core.langauge.eval.
This commit is contained in:
Kodi Arfer 2017-07-03 17:00:55 -07:00
parent ca95194240
commit f55fcf43bd
1 changed files with 13 additions and 0 deletions

View File

@ -144,6 +144,19 @@ def import_buffer_to_module(module_name, buf):
def hy_eval(hytree, namespace=None, module_name=None, ast_callback=None):
"""``eval`` evaluates a quoted expression and returns the value. The optional
second and third arguments specify the dictionary of globals to use and the
module name. The globals dictionary defaults to ``(local)`` and the module
name defaults to the name of the current module.
=> (eval '(print "Hello World"))
"Hello World"
If you want to evaluate a string, use ``read-str`` to convert it to a
form first:
=> (eval (read-str "(+ 1 1)"))
2"""
if namespace is None:
frame = inspect.stack()[1][0]
namespace = inspect.getargvalues(frame).locals