diff options
author | Steve Bennett <steveb@workware.net.au> | 2010-03-03 16:00:33 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2010-10-15 11:02:48 +1000 |
commit | b83beb2febcbe0abcf338e3f915b43889ce93eca (patch) | |
tree | 8baa5d1ff957f3209ac40a3d89d5fa5644796398 /stdlib.tcl | |
parent | 80ddfb1fe799cde11aa65fcea5935686aacb4ca4 (diff) | |
download | jimtcl-b83beb2febcbe0abcf338e3f915b43889ce93eca.zip jimtcl-b83beb2febcbe0abcf338e3f915b43889ce93eca.tar.gz jimtcl-b83beb2febcbe0abcf338e3f915b43889ce93eca.tar.bz2 |
Move some core procs into the (Tcl) stdlib extension
Also implement 'local' to declare/delete local procs
* Add tests/alias.test for testing alias, current, local
* proc now returns the name of the proc created
* Add helper 'function' to stdlib
Reimplement glob and case to use local procs
* This keeps these internal procs out of the global namespace
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'stdlib.tcl')
-rw-r--r-- | stdlib.tcl | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/stdlib.tcl b/stdlib.tcl new file mode 100644 index 0000000..e406a4f --- /dev/null +++ b/stdlib.tcl @@ -0,0 +1,40 @@ +# Create a single word alias (proc) for one or more words +# e.g. alias x info exists +# if {[x var]} ... +proc alias {name args} { + set prefix $args + proc $name args prefix { + uplevel 1 $prefix $args + } +} + +# Creates an anonymous procedure +proc lambda {arglist args} { + set name [ref {} function lambda.finalizer] + uplevel 1 [list proc $name $arglist {*}$args] + return $name +} + +proc lambda.finalizer {name val} { + rename $name {} +} + +# Like alias, but creates and returns an anonyous procedure +proc curry {args} { + set prefix $args + lambda args prefix { + uplevel 1 $prefix $args + } +} + +# Returns the given argument. +# Useful with 'local' as follows: +# proc a {} {...} +# local function a +# +# set x [lambda ...] +# local function $x +# +proc function {value} { + return $value +} |