diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2007-10-25 09:25:27 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2007-10-25 09:25:27 (GMT) |
commit | 859f56b5099b2bfd3ad42becd2aaddca16196ce2 (patch) | |
tree | a55358a428b5851b24d6a6406ae63dc80f3b016d /doc/apply.n | |
parent | 79cc10a2e22854d53a72f18f95e87a867df9925a (diff) | |
download | tcl-859f56b5099b2bfd3ad42becd2aaddca16196ce2.zip tcl-859f56b5099b2bfd3ad42becd2aaddca16196ce2.tar.gz tcl-859f56b5099b2bfd3ad42becd2aaddca16196ce2.tar.bz2 |
GOOBE for command results in examples
Diffstat (limited to 'doc/apply.n')
-rw-r--r-- | doc/apply.n | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/doc/apply.n b/doc/apply.n index 1e69e69..22b068d 100644 --- a/doc/apply.n +++ b/doc/apply.n @@ -65,6 +65,7 @@ proc apply {fun args} { This shows how to make a simple general command that applies a transformation to each element of a list. .CS +.ta 2i proc map {lambda list} { set result {} foreach $item $list { @@ -73,21 +74,24 @@ proc map {lambda list} { return $result } map {x {return [string length $x]:$x}} {a bb ccc dddd} - \fI=> 1:a 2:bb 3:ccc 4:dddd\fR + \fB\(->\fI 1:a 2:bb 3:ccc 4:dddd\fR map {x {expr {$x**2 + 3*$x - 2}}} {-4 -3 -2 -1 0 1 2 3 4} - \fI=> 2 -2 -4 -4 -2 2 8 16 26\fR + \fB\(->\fI 2 -2 -4 -4 -2 2 8 16 26\fR .CE .PP The \fBapply\fR command is also useful for defining callbacks for use in the \fBtrace\fR command: .CS +.ta 2i set vbl "123abc" trace add variable vbl write {\fBapply\fR {v1 v2 op} { upvar 1 $v1 v - puts "updated variable to \\"$v\\"" + puts "updated variable to \e"$v\e"" }} set vbl 123 + \fB\(->\fI updated variable to "123"\fR set vbl abc + \fB\(->\fI updated variable to "abc"\fR .CE .SH "SEE ALSO" proc(n), uplevel(n) |