From a786577a8b7a5e7bb2ef0d545ba7ad486c1b749d Mon Sep 17 00:00:00 2001 From: Tuukka Turto Date: Fri, 19 Jul 2013 15:57:25 +0300 Subject: [PATCH] documentation for global --- docs/language/api.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/language/api.rst b/docs/language/api.rst index cf3cd1c..7443ed0 100644 --- a/docs/language/api.rst +++ b/docs/language/api.rst @@ -321,6 +321,25 @@ Example usages: global ------ +`global` can be used to mark a symbol as global. This allows the programmer to +assign a value to a global symbol. Reading a global symbol does not require the +`global` keyword, just the assigning does. + +Following example shows how global `a` is assigned a value in a function and later +on printed on another function. Without the `global` keyword, the second function +would thrown a `NameError`. + +.. code-block:: clj + + (defn set-a [value] + (global a) + (setv a value)) + + (defn print-a [] + (print a)) + + (set-a 5) + (print-a) if --