Document eval
, quasiquote' and
quote'.
Also, fix the usage of `setv`.
This commit is contained in:
parent
b8efb5c242
commit
63a9e35f7f
@ -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
|
||||
-------
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user