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
|
||||||
----
|
----
|
||||||
|
|
||||||
|
`eval` evaluates a quoted expression and returns the value.
|
||||||
|
|
||||||
|
.. code-block:: clj
|
||||||
|
|
||||||
|
=> (eval '(print "Hello World"))
|
||||||
|
"Hello World"
|
||||||
|
|
||||||
eval-and-compile
|
eval-and-compile
|
||||||
----------------
|
----------------
|
||||||
@ -719,6 +725,39 @@ the `print` form is used to output on screen. Example usage:
|
|||||||
.. note:: `print` always returns None
|
.. 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
|
require
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
@ -429,11 +429,11 @@ as an example of how to use some of these functions.
|
|||||||
.. code-block:: clojure
|
.. code-block:: clojure
|
||||||
|
|
||||||
(defn fib []
|
(defn fib []
|
||||||
(setf a 0)
|
(setv a 0)
|
||||||
(setf b 1)
|
(setv b 1)
|
||||||
(while true
|
(while true
|
||||||
(yield a)
|
(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,
|
Note the ``(while true ...)`` loop. If we run this in the REPL,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user