aboutsummaryrefslogtreecommitdiff
path: root/jim_tcl.txt
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-06-28 11:18:10 +1000
committerSteve Bennett <steveb@workware.net.au>2023-07-04 10:14:40 +1000
commit6fd2ff925d636fca8aaf5f8cd3beddfe95475b82 (patch)
tree3fce94143c663ca4f0ef05cff249670f29ed1a92 /jim_tcl.txt
parentc33f287435a41fa94aa494c315ecdb628322f72a (diff)
downloadjimtcl-6fd2ff925d636fca8aaf5f8cd3beddfe95475b82.zip
jimtcl-6fd2ff925d636fca8aaf5f8cd3beddfe95475b82.tar.gz
jimtcl-6fd2ff925d636fca8aaf5f8cd3beddfe95475b82.tar.bz2
core: add support for proc statics by reference
set a 5 proc b {} {&a} { incr a } b Now a is 6 because b captured a by reference instead of by value Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim_tcl.txt')
-rw-r--r--jim_tcl.txt20
1 files changed, 20 insertions, 0 deletions
diff --git a/jim_tcl.txt b/jim_tcl.txt
index bf4689c..67d5adc 100644
--- a/jim_tcl.txt
+++ b/jim_tcl.txt
@@ -61,6 +61,7 @@ Changes since 0.82
5. Improvements with `aio`, related to eventloop and buffering. Add `aio timeout`.
6. `socket` , `open` and `aio accept` now support '-noclose'
7. Add support for hinting with `history hints`
+8. Support for `proc` statics by reference (lexical closure) rather than by value
Changes between 0.81 and 0.82
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1369,6 +1370,25 @@ has an initialiser, so it is initialised to 2.
Unlike a local variable, the value of a static variable is retained across
invocations of the procedure.
+In addition to static variables by value, static variables may also be
+defined by "reference" by using a leading "&" character. In this case,
+the statics point to the original variable and when one changes, they
+both change. For example, here 'a' changes changes the value of the
+original 'x'.
+
+----
+ . set x 1
+ . proc a {} {&x} {
+ incr x
+ }
+ . a
+ 2
+ . a
+ 3
+ . puts $x
+ 3
+----
+
See the `proc` command for information on how to define procedures
and what happens when they are invoked. See also <<_namespaces,NAMESPACES>>.