summaryrefslogtreecommitdiffstats
path: root/config/commence.am
Commit message (Expand)AuthorAgeFilesLines
* Merge pull request #426 in HDFFV/hdf5 from ~LRKNOX/hdf5_lrk:hdf5_1_10 to hdf5...Larry Knox2017-04-251-6/+4
* [svn-r29226] HDFFV-9552: merge in java code.Allen Byrne2016-02-291-0/+1
* [svn-r26303] remove files with .clog2 extension generated by MPE when doing m...Mohamad Chaarawi2015-02-251-2/+2
* [svn-r22709] HDFFV-8129: reconfigured on jam, Remove overloading of autotools...Allen Byrne2012-08-231-7/+0
* [svn-r20504] Purpose:Mike McGreevy2011-04-141-0/+2
* [svn-r19506] Bring changes from revisions 19408, 19421, and 19442 from branch...Larry Knox2010-10-041-5/+15
* [svn-r19366] Updated autoconf to version 2.6.7, libtool to version 2.2.10, an...Larry Knox2010-09-101-0/+2
* [svn-r18107] bug 1673:Albert Cheng2010-01-121-2/+2
* [svn-r17616] Purpose:Mike McGreevy2009-10-081-7/+9
* [svn-r16561] Purpose:Mike McGreevy2009-03-101-1/+0
* [svn-r15942] Purpose: Bug Fixes and Libtool UpgradeMike McGreevy2008-10-241-6/+0
* [svn-r13418] Cleaned up some old paths in config/commence.am and removed some...James Laird2007-02-271-4/+4
* [svn-r13379] Added 'make help' target. This actually runs a script, bin/make...James Laird2007-02-231-1/+4
* [svn-r13365] Bug fix.Albert Cheng2007-02-211-12/+13
* [svn-r13359] Fixed a bug where the -shlib flag for h5cc would end up on the D...James Laird2007-02-201-5/+5
* [svn-r13312] Updated copyright notice.Albert Cheng2007-02-141-11/+12
* [svn-r13181] Added a configure check to prevent a failure on Cygwin.James Laird2007-01-231-1/+0
* [svn-r12431] Purpose:James Laird2006-06-211-16/+6
* [svn-r12295] Purpose:James Laird2006-04-211-1/+1
* [svn-r12229] Purpose:Pedro Vicente Nunes2006-04-121-0/+3
* [svn-r12149] Purpose:James Laird2006-03-231-6/+0
* [svn-r11738] Purpose:James Laird2005-11-181-0/+4
* [svn-r11737] Purpose:James Laird2005-11-171-0/+9
* [svn-r11646] Purpose:James Laird2005-10-311-4/+16
* [svn-r11614] Frank Baker2005-10-281-1/+1
* [svn-r11592] Frank Baker2005-10-211-0/+14
* [svn-r11431] Purpose:Albert Cheng2005-09-181-0/+1
* [svn-r11421] Purpose:James Laird2005-09-161-0/+7
* [svn-r11323] Purpose:Albert Cheng2005-08-311-1/+2
* [svn-r11303] Purpose:Albert Cheng2005-08-261-12/+3
* [svn-r11185] Purpose:James Laird2005-08-021-2/+0
* [svn-r11179] Purpose:James Laird2005-08-011-4/+8
* [svn-r11095] Purpose:James Laird2005-07-211-1/+15
* [svn-r11008] Purpose:James Laird2005-06-301-0/+2
* [svn-r10517] Purpose:James Laird2005-03-311-5/+15
* [svn-r10511] James Laird2005-03-301-0/+6
* [svn-r10459] James Laird2005-03-281-0/+1
* [svn-r9988] Purpose:James Laird2005-02-111-5/+3
* [svn-r9915] Purpose:James Laird2005-02-021-6/+6
* [svn-r9912] Purpose:James Laird2005-02-011-83/+6
* [svn-r9907] Purpose:James Laird2005-02-011-0/+1
* [svn-r9902] Purpose:James Laird2005-02-011-0/+116
'>novem_freeifrefcountzero Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
path: root/doc/apply.n
blob: 9d373e1715adc0dc8920f3fe85db82d3c387d1fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'\"
'\" Copyright (c) 2006 Miguel Sofer
'\" Copyright (c) 2006 Donal K. Fellows
'\"
.so man.macros
.TH apply n "" Tcl "Tcl Built-In Commands"
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
apply \- Apply an anonymous function
.SH SYNOPSIS
\fBapply \fIfunc\fR ?\fIarg1 arg2 ...\fR?
.BE
.SH DESCRIPTION
.PP
The command \fBapply\fR applies the function \fIfunc\fR to the arguments
\fIarg1 arg2 ...\fR and returns the result. 
.PP
The function \fIfunc\fR is a two element list \fI{args body}\fR or a three
element list \fI{args body namespace}\fR (as if the
\fBlist\fR command had been used). 
The first element \fIargs\fR specifies the formal arguments to
\fIfunc\fR. The specification of the formal arguments \fIargs\fR
is shared with the \fBproc\fR command, and is described in detail in the
corresponding manual page.
.PP
The contents of \fIbody\fR are executed by the Tcl interpreter
after the local variables corresponding to the formal arguments are given
the values of the actual parameters \fIarg1 arg2 ...\fR.
When \fIbody\fR is being executed, variable names normally refer to
local variables, which are created automatically when referenced and
deleted when \fBapply\fR returns.  One local variable is automatically
created for each of the function's arguments.
Global variables can only be accessed by invoking
the \fBglobal\fR command or the \fBupvar\fR command.
Namespace variables can only be accessed by invoking
the \fBvariable\fR command or the \fBupvar\fR command.
.PP
The invocation of \fBapply\fR adds a call frame to Tcl's evaluation stack
(the stack of frames accessed via \fBuplevel\fR). The execution of \fIbody\fR
proceeds in this call frame, in the namespace given by \fInamespace\fR or
in the global namespace if none was specified. If given, \fInamespace\fR is
interpreted relative to the global namespace even if its name does not start
with
.QW :: .
.PP
The semantics of \fBapply\fR can also be described by:
.PP
.CS
proc apply {fun args} {
    set len [llength $fun]
    if {($len < 2) || ($len > 3)} {
         error "can't interpret \e"$fun\e" as anonymous function"
    }
    lassign $fun argList body ns
    set name ::$ns::[getGloballyUniqueName]
    set body0 {
         rename [lindex [info level 0] 0] {}
    }
    proc $name $argList ${body0}$body
    set code [catch {uplevel 1 $name $args} res opt]
    return -options $opt $res
}
.CE
.SH EXAMPLES
.PP
This shows how to make a simple general command that applies a transformation
to each element of a list.
.PP
.CS
proc map {lambda list} {
    set result {}
    foreach item $list {
        lappend result [\fBapply\fR $lambda $item]
    }
    return $result
}
map {x {return [string length $x]:$x}} {a bb ccc dddd}
      \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
.CE
.PP
The \fBapply\fR command is also useful for defining callbacks for use in the
\fBtrace\fR command:
.PP
.CS
set vbl "123abc"
trace add variable vbl write {\fBapply\fR {{v1 v2 op} {
    upvar 1 $v1 v
    puts "updated variable to \e"$v\e""
}}}
set vbl 123
set vbl abc
.CE
.SH "SEE ALSO"
proc(n), uplevel(n)
.SH KEYWORDS
anonymous function, argument, lambda, procedure, 
'\" Local Variables:
'\" mode: nroff
'\" End: