📄 ensemble.n
字号:
'\"'\" Copyright (c) 1993-1998 Lucent Technologies, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: $Id: ensemble.n,v 1.1 2003/02/05 10:53:53 mdejong Exp $'\" .so man.macros.TH ensemble n 3.0 itcl "[incr\ Tcl]".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEensemble \- create or modify a composite command.SH SYNOPSIS\fBensemble \fIensName\fR ?\fIcommand arg arg...\fR?.bror.br\fBensemble \fIensName\fR {.br \fBpart \fIpartName args body\fR.br \fI...\fR.br \fBensemble \fIpartName\fR {.br \fBpart \fIsubPartName args body\fR.br \fBpart \fIsubPartName args body\fR.br \fI...\fR }.br}.BE.SH DESCRIPTION.PPThe \fBensemble\fR command is used to create or modify a compositecommand. See the section \fBWHAT IS AN ENSEMBLE?\fR below for abrief overview of ensembles..PPIf the \fBensemble\fR command finds an existing ensemble called\fIensName\fR, it updates that ensemble. Otherwise, it creates anensemble called \fIensName\fR. If the \fIensName\fR is a simple namelike "foo", then an ensemble command named "foo" is added to thecurrent namespace context. If a command named "foo" already existsin that context, then it is deleted. If the \fIensName\fR containsnamespace qualifiers like "a::b::foo", then the namespace path isresolved, and the ensemble command is added that namespace context.Parent namespaces like "a" and "b" are created automatically, as needed..PPIf the \fIensName\fR contains spaces like "a::b::foo bar baz", thenadditional words like "bar" and "baz" are treated as sub-ensembles.Sub-ensembles are merely parts within an ensemble; they do not havea Tcl command associated with them. An ensemble like "foo" canhave a sub-ensemble called "foo bar", which in turn can have asub-ensemble called "foo bar baz". In this case, the sub-ensemble"foo bar" must be created before the sub-ensemble "foo bar baz"that resides within it..PPIf there are any arguments following \fIensName\fR, then they aretreated as commands, and they are executed to update the ensemble.The following commands are recognized in this context: \fBpart\fRand \fBensemble\fR..PPThe \fBpart\fR command defines a new part for the ensemble.Its syntax is identical to the usual \fBproc\fR command, butit defines a part within an ensemble, instead of a Tcl command.If a part called \fIpartName\fR already exists within the ensemble,then the \fBpart\fR command returns an error..PPThe \fBensemble\fR command can be nested inside another \fBensemble\fRcommand to define a sub-ensemble..SH "WHAT IS AN ENSEMBLE?"The usual "info" command is a composite command--the command name\fBinfo\fR must be followed by a sub-command like \fBbody\fR or \fBglobals\fR.We will refer to a command like \fBinfo\fR as an \fIensemble\fR, and tosub-commands like \fBbody\fR or \fBglobals\fR as its \fIparts\fR..PPEnsembles can be nested. For example, the \fBinfo\fR command hasan ensemble \fBinfo namespace\fR within it. This ensemble has partslike \fBinfo namespace all\fR and \fBinfo namespace children\fR..PPWith ensembles, composite commands can be created and extendedin an automatic way. Any package can find an existing ensembleand add new parts to it. So extension writers can add theirown parts, for example, to the \fBinfo\fR command..PPThe ensemble facility manages all of the part names and keepstrack of unique abbreviations. Normally, you can abbreviate\fBinfo complete\fR to \fBinfo comp\fR. But if an extension adds thepart \fBinfo complexity\fR, the minimum abbreviation for \fBinfo complete\fRbecomes \fBinfo complet\fR..PPThe ensemble facility not only automates the construction ofcomposite commands, but it automates the error handling as well.If you invoke an ensemble command without specifying a part name,you get an automatically generated error message that summarizesthe usage information. For example, when the \fBinfo\fR commandis invoked without any arguments, it produces the following errormessage:.CSwrong # args: should be one of... info args procname info body procname info cmdcount info commands ?pattern? info complete command info context info default procname arg varname info exists varName info globals ?pattern? info level ?number? info library info locals ?pattern? info namespace option ?arg arg ...? info patchlevel info procs ?pattern? info protection ?-command? ?-variable? name info script info tclversion info vars ?pattern? info which ?-command? ?-variable? ?-namespace? name\fR.CEYou can also customize the way an ensemble responds to errors.When an ensemble encounters an unspecified or ambiguous partname, it looks for a part called \fB@error\fR. If it exists,then it is used to handle the error. This part will receive allof the arguments on the command line starting with the offendingpart name. It can find another way of resolving the command,or generate its own error message..SH EXAMPLEWe could use an ensemble to clean up the syntax of the various"wait" commands in Tcl/Tk. Instead of using a series ofstrange commands like this:.CSvwait xtkwait visibility .toptkwait window ..CEwe could use commands with a uniform syntax, like this:.CSwait variable xwait visibility .topwait window ..CEThe Tcl package could define the following ensemble:.CSensemble wait part variable {name} { uplevel vwait $name}.CEThe Tk package could add some options to this ensemble, with acommand like this:.CSensemble wait { part visibility {name} { tkwait visibility $name } part window {name} { tkwait window $name }}.CEOther extensions could add their own parts to the \fBwait\fR commandtoo..SH KEYWORDSensemble, part, info
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -