diff --git a/docs/language/api.rst b/docs/language/api.rst index ac4f42b..bac3138 100644 --- a/docs/language/api.rst +++ b/docs/language/api.rst @@ -381,6 +381,12 @@ between the operands. eval ---- +`eval` evaluates a quoted expression and returns the value. + +.. code-block:: clj + + => (eval '(print "Hello World")) + "Hello World" eval-and-compile ---------------- @@ -719,6 +725,39 @@ the `print` form is used to output on screen. Example usage: .. note:: `print` always returns None +quasiquote +---------- + +`quasiquote` allows you to quote a form, but also to +selectively evaluate expressions, expressions inside a `quasiquote` +can be selectively evaluated using `unquote` (~). The evaluated form can +also be spliced using `unquote-splice` (~@). Quasiquote can be also written +using the backquote (`) symbol. + + +.. code-block:: clj + ;; let `qux' be a variable with value (bar baz) + `(foo ~qux) + ; equivalent to '(foo (bar baz)) + `(foo ~@qux) + ; equivalent to '(foo bar baz) + + +quote +----- + +`quote` returns the form passed to it without evaluating. `quote` can +be alternatively written using the (') symbol + + +.. code-block:: clj + => (setv x '(print "Hello World")) + ; variable x is set to expression & not evaluated + => x + (u'print' u'Hello World') + => (eval x) + Hello World + require ------- diff --git a/docs/language/core.rst b/docs/language/core.rst index 8a34549..acdc025 100644 --- a/docs/language/core.rst +++ b/docs/language/core.rst @@ -429,11 +429,11 @@ as an example of how to use some of these functions. .. code-block:: clojure (defn fib [] - (setf a 0) - (setf b 1) + (setv a 0) + (setv b 1) (while true (yield a) - (setf (, a b) (, b (+ a b))))) + (setv (, a b) (, b (+ a b))))) Note the ``(while true ...)`` loop. If we run this in the REPL,