Document eval, quasiquote' and quote'.

Also, fix the usage of `setv`.
This commit is contained in:
Abhishek L 2013-11-27 00:01:10 +05:30 committed by Berker Peksag
parent b8efb5c242
commit 63a9e35f7f
2 changed files with 42 additions and 3 deletions

View File

@ -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
-------

View File

@ -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,