aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2017-08-26 09:23:03 +1000
committerSteve Bennett <steveb@workware.net.au>2017-09-01 09:01:15 +1000
commit52c8b8b6adba1e32b460d44cb0a716db9fda69bc (patch)
tree4f882baf7ca1bac403389f12112d3406dc890975
parent9b746a28ddeaab0610c423b4426bb6f18b72c515 (diff)
downloadjimtcl-52c8b8b6adba1e32b460d44cb0a716db9fda69bc.zip
jimtcl-52c8b8b6adba1e32b460d44cb0a716db9fda69bc.tar.gz
jimtcl-52c8b8b6adba1e32b460d44cb0a716db9fda69bc.tar.bz2
Support lambda even if references are disabled
It's convenient to support a non-gc lambda, even if references are disabled. Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--stdlib.tcl7
-rw-r--r--tcltest.tcl2
-rw-r--r--tests/alias.test4
3 files changed, 10 insertions, 3 deletions
diff --git a/stdlib.tcl b/stdlib.tcl
index 9cffb93..7fd1313 100644
--- a/stdlib.tcl
+++ b/stdlib.tcl
@@ -1,5 +1,12 @@
# Implements script-based standard commands for Jim Tcl
+if {![exists -command ref]} {
+ # No support for references, so create a poor-man's reference just good enough for lambda
+ proc ref {args} {{count 0}} {
+ format %08x [incr count]
+ }
+}
+
# Creates an anonymous procedure
proc lambda {arglist args} {
tailcall proc [ref {} function lambda.finalizer] $arglist {*}$args
diff --git a/tcltest.tcl b/tcltest.tcl
index b98164a..b7e3983 100644
--- a/tcltest.tcl
+++ b/tcltest.tcl
@@ -166,7 +166,7 @@ proc testConstraint {constraint {bool {}}} {
}
testConstraint {utf8} [expr {[string length "\xc2\xb5"] == 1}]
-testConstraint {references} [expr {[info commands ref] ne ""}]
+testConstraint {references} [expr {[info commands getref] ne ""}]
testConstraint {jim} 1
testConstraint {tcl} 0
diff --git a/tests/alias.test b/tests/alias.test
index c539920..4f6e553 100644
--- a/tests/alias.test
+++ b/tests/alias.test
@@ -62,8 +62,8 @@ test curry-1.4 "Two word curry" {
list [$two x] [$two y]
} {1 0}
-collect
-test curry-1.5 "Delete curry" {
+test curry-1.5 "Delete curry" references {
+ collect
unset one two
collect
} {2}