about summary refs log tree commit diff
path: root/Doc/Zsh/func.yo
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-06-30 10:37:11 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-06-30 10:37:11 +0000
commit950756d57943a0bf104d9f015b8da604171a956e (patch)
treec1555284c1e0009d89f9fe70f5757ee1e994b43c /Doc/Zsh/func.yo
parentd09e51d6090df6e7c052d48543dcbd32af1a986f (diff)
downloadzsh-950756d57943a0bf104d9f015b8da604171a956e.tar.gz
zsh-950756d57943a0bf104d9f015b8da604171a956e.tar.xz
zsh-950756d57943a0bf104d9f015b8da604171a956e.zip
25255: add anonymous function capability
Diffstat (limited to 'Doc/Zsh/func.yo')
-rw-r--r--Doc/Zsh/func.yo36
1 files changed, 36 insertions, 0 deletions
diff --git a/Doc/Zsh/func.yo b/Doc/Zsh/func.yo
index 6b6202831..65bcd9abc 100644
--- a/Doc/Zsh/func.yo
+++ b/Doc/Zsh/func.yo
@@ -150,6 +150,42 @@ executing tt(myfunc), use:
 
 example(autoload +X myfunc)
 
+sect(Anonymous Functions)
+cindex(anonymous functions)
+cindex(functions, anonymous)
+
+If no name is given for a function, it is `anonymous' and is handled
+specially.  Either form of function definition may be used: a `tt(())' with
+no preceding name, or a `tt(function)' with an immediately following open
+brace.  The function is executed immediately at the point of definition and
+is not stored for future use.  The function name is set to `tt((anon))' and
+the parameter list passed to the function is empty.  Note that this means
+the argument list of any enclosing script or function is hidden.
+Redirections may be applied to the anonymous function in the same manner as
+to a current-shell structure enclosed in braces.  The main use of anonymous
+functions is to provide a scope for local variables.  This is particularly
+convenient in start-up files as these do not provide their own local
+variable scope.
+
+For example,
+
+example(variable=outside
+function {
+  local variable=inside
+  print "I am $variable"
+}
+print "I am $variable")
+
+outputs the following:
+
+example(I am inside
+I am outside)
+
+Note that function definitions with arguments that expand to nothing,
+for example `tt(name=; function $name { )var(...)tt( })', are not
+treated as anonymous functions.  Instead, they are treated as normal
+function definitions where the definition is silently discarded.
+
 sect(Special Functions)
 Certain functions, if defined, have special meaning to the shell.