OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [doc/] [ensemble.n] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1993-1998  Lucent Technologies, Inc.
3
'\"
4
'\" See the file "license.terms" for information on usage and redistribution
5
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6
'\"
7
'\" RCS: $Id: ensemble.n,v 1.1.1.1 2002-01-16 10:24:46 markom Exp $
8
'\"
9
.so man.macros
10
.TH ensemble n 3.0 itcl "[incr\ Tcl]"
11
.BS
12
'\" Note:  do not modify the .SH NAME line immediately below!
13
.SH NAME
14
ensemble \- create or modify a composite command
15
.SH SYNOPSIS
16
\fBensemble \fIensName\fR ?\fIcommand arg arg...\fR?
17
.br
18
or
19
.br
20
\fBensemble \fIensName\fR {
21
.br
22
    \fBpart \fIpartName args body\fR
23
.br
24
    \fI...\fR
25
.br
26
    \fBensemble \fIpartName\fR {
27
.br
28
        \fBpart \fIsubPartName args body\fR
29
.br
30
        \fBpart \fIsubPartName args body\fR
31
.br
32
    \fI...\fR
33
    }
34
.br
35
}
36
.BE
37
 
38
.SH DESCRIPTION
39
.PP
40
The \fBensemble\fR command is used to create or modify a composite
41
command.  See the section \fBWHAT IS AN ENSEMBLE?\fR below for a
42
brief overview of ensembles.
43
.PP
44
If the \fBensemble\fR command finds an existing ensemble called
45
\fIensName\fR, it updates that ensemble.  Otherwise, it creates an
46
ensemble called \fIensName\fR.  If the \fIensName\fR is a simple name
47
like "foo", then an ensemble command named "foo" is added to the
48
current namespace context.  If a command named "foo" already exists
49
in that context, then it is deleted.  If the \fIensName\fR contains
50
namespace qualifiers like "a::b::foo", then the namespace path is
51
resolved, and the ensemble command is added that namespace context.
52
Parent namespaces like "a" and "b" are created automatically, as needed.
53
.PP
54
If the \fIensName\fR contains spaces like "a::b::foo bar baz", then
55
additional words like "bar" and "baz" are treated as sub-ensembles.
56
Sub-ensembles are merely parts within an ensemble; they do not have
57
a Tcl command associated with them.  An ensemble like "foo" can
58
have a sub-ensemble called "foo bar", which in turn can have a
59
sub-ensemble called "foo bar baz".  In this case, the sub-ensemble
60
"foo bar" must be created before the sub-ensemble "foo bar baz"
61
that resides within it.
62
.PP
63
If there are any arguments following \fIensName\fR, then they are
64
treated as commands, and they are executed to update the ensemble.
65
The following commands are recognized in this context:  \fBpart\fR
66
and \fBensemble\fR.
67
.PP
68
The \fBpart\fR command defines a new part for the ensemble.
69
Its syntax is identical to the usual \fBproc\fR command, but
70
it defines a part within an ensemble, instead of a Tcl command.
71
If a part called \fIpartName\fR already exists within the ensemble,
72
then the \fBpart\fR command returns an error.
73
.PP
74
The \fBensemble\fR command can be nested inside another \fBensemble\fR
75
command to define a sub-ensemble.
76
 
77
.SH "WHAT IS AN ENSEMBLE?"
78
The usual "info" command is a composite command--the command name
79
\fBinfo\fR must be followed by a sub-command like \fBbody\fR or \fBglobals\fR.
80
We will refer to a command like \fBinfo\fR as an \fIensemble\fR, and to
81
sub-commands like \fBbody\fR or \fBglobals\fR as its \fIparts\fR.
82
.PP
83
Ensembles can be nested.  For example, the \fBinfo\fR command has
84
an ensemble \fBinfo namespace\fR within it.  This ensemble has parts
85
like \fBinfo namespace all\fR and \fBinfo namespace children\fR.
86
.PP
87
With ensembles, composite commands can be created and extended
88
in an automatic way.  Any package can find an existing ensemble
89
and add new parts to it.  So extension writers can add their
90
own parts, for example, to the \fBinfo\fR command.
91
.PP
92
The ensemble facility manages all of the part names and keeps
93
track of unique abbreviations.  Normally, you can abbreviate
94
\fBinfo complete\fR to \fBinfo comp\fR.  But if an extension adds the
95
part \fBinfo complexity\fR, the minimum abbreviation for \fBinfo complete\fR
96
becomes \fBinfo complet\fR.
97
.PP
98
The ensemble facility not only automates the construction of
99
composite commands, but it automates the error handling as well.
100
If you invoke an ensemble command without specifying a part name,
101
you get an automatically generated error message that summarizes
102
the usage information.  For example, when the \fBinfo\fR command
103
is invoked without any arguments, it produces the following error
104
message:
105
.CS
106
wrong # args: should be one of...
107
  info args procname
108
  info body procname
109
  info cmdcount
110
  info commands ?pattern?
111
  info complete command
112
  info context
113
  info default procname arg varname
114
  info exists varName
115
  info globals ?pattern?
116
  info level ?number?
117
  info library
118
  info locals ?pattern?
119
  info namespace option ?arg arg ...?
120
  info patchlevel
121
  info procs ?pattern?
122
  info protection ?-command? ?-variable? name
123
  info script
124
  info tclversion
125
  info vars ?pattern?
126
  info which ?-command? ?-variable? ?-namespace? name\fR
127
.CE
128
You can also customize the way an ensemble responds to errors.
129
When an ensemble encounters an unspecified or ambiguous part
130
name, it looks for a part called \fB@error\fR.  If it exists,
131
then it is used to handle the error.  This part will receive all
132
of the arguments on the command line starting with the offending
133
part name.  It can find another way of resolving the command,
134
or generate its own error message.
135
 
136
.SH EXAMPLE
137
We could use an ensemble to clean up the syntax of the various
138
"wait" commands in Tcl/Tk.  Instead of using a series of
139
strange commands like this:
140
.CS
141
vwait x
142
tkwait visibility .top
143
tkwait window .
144
.CE
145
we could use commands with a uniform syntax, like this:
146
.CS
147
wait variable x
148
wait visibility .top
149
wait window .
150
.CE
151
The Tcl package could define the following ensemble:
152
.CS
153
ensemble wait part variable {name} {
154
    uplevel vwait $name
155
}
156
.CE
157
The Tk package could add some options to this ensemble, with a
158
command like this:
159
.CS
160
ensemble wait {
161
    part visibility {name} {
162
        tkwait visibility $name
163
    }
164
    part window {name} {
165
        tkwait window $name
166
    }
167
}
168
.CE
169
Other extensions could add their own parts to the \fBwait\fR command
170
too.
171
 
172
.SH KEYWORDS
173
ensemble, part, info

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.