ensemble(n)
β¨ ensemble(n) β itcl's lil' composite-command glow-up β¨
okay bestie, sit down, grab a strawberry π, because we're talking about itcl::ensemble β the command that creates or modifies a composite command. that's the whole vibe. π
π SYNOPSIS π
itcl::ensemble ensName ?command arg arg...?
or
ensemble ensName {
part partName args body
...
ensemble partName {
part subPartName args body
part subPartName args body
...
}
}
π DESCRIPTION π
so the ensemble command is here to create or modify a composite command. if you wanna know what an ensemble even is, there's a whole section below called WHAT IS AN ENSEMBLE? β go peek, it's giving tutorial energy. β¨
here's the tea: if ensemble finds an existing ensemble called ensName, it updates it. no ensemble by that name? then it creates one called ensName. iconic, right?
if the ensName is a simple name like "foo", then an ensemble command named "foo" gets added to the current namespace context. and bestie, listen β if a command named "foo" already exists in that context, it gets deleted. not renamed, not archived, deleted. π
if the ensName has namespace qualifiers like "a::b::foo", then the namespace path is resolved and the ensemble command is added to that namespace context. parent namespaces like "a" and "b" are created automatically, as needed. she's self-sufficient, we love that. π
now if the ensName contains spaces like "a::b::foo bar baz", then those extra words like "bar" and "baz" are treated as sub-ensembles. and no cap: sub-ensembles are merely parts within an ensemble β they do not have a Tcl command associated with them. so an ensemble like "foo" can have a sub-ensemble called "foo bar", which in turn can have a sub-ensemble called "foo bar baz". but β οΈ in this case, the sub-ensemble "foo bar" must be created before the sub-ensemble "foo bar baz" that resides within it. order matters, bestie, don't skip steps. π«Ά
if there are any arguments following ensName, then they're treated as commands, and they get executed to update the ensemble. the following commands are recognized in this context: part and ensemble.
the part command defines a new part for the ensemble. its syntax is identical to the usual proc command β literally twins β but it defines a part within an ensemble instead of a Tcl command. and if a part called partName already exists within the ensemble, then the part command returns an error. no duplicates allowed, periodt. π
ββοΈ
the ensemble command can also be nested inside another ensemble command to define a sub-ensemble. inception vibes. π
π¦ WHAT IS AN ENSEMBLE? π¦
okay so. the usual "info" command? that's a composite command β the command name info must be followed by a sub-command like body or globals. we're gonna call a command like info an ensemble, and sub-commands like body or globals its parts. iykyk. π
ensembles can be nested. for example, the info command has an ensemble info namespace within it. this ensemble has parts like info namespace all and info namespace children. it's ensembles all the way down, babe. π
with ensembles, composite commands can be created and extended in an automatic way. any package can find an existing ensemble and add new parts to it. so extension writers can add their own parts, for example, to the info command. collab era. π€
the ensemble facility manages all of the part names and keeps track of unique abbreviations. normally, you can abbreviate info complete to info comp. but if an extension adds the part info complexity, the minimum abbreviation for info complete becomes info complet. she adapts, she's smart, main character energy. π
and it's not just construction β the ensemble facility automates the error handling too. if you invoke an ensemble command without specifying a part name, you get an automatically generated error message that summarizes the usage information. for example, when the info command is invoked without any arguments, it produces the following error message:
wrong # 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
you can also customize the way an ensemble responds to errors. when an ensemble encounters an unspecified or ambiguous part name, it looks for a part called @error. if it exists, then it's used to handle the error. this part will receive all of the arguments on the command line starting with the offending part name. it can find another way of resolving the command, or generate its own error message. she handles her own drama. π
πΈ EXAMPLE πΈ
we could use an ensemble to clean up the syntax of the various "wait" commands in Tcl/Tk. instead of using a series of strange commands like this:
vwait x
tkwait visibility .top
tkwait window .
we could use commands with a uniform syntax, like this:
wait variable x
wait visibility .top
wait window .
the Tcl package could define the following ensemble:
itcl::ensemble wait part variable {name} {
uplevel vwait $name
}
the Tk package could add some options to this ensemble, with a command like this:
itcl::ensemble wait {
part visibility {name} {
tkwait visibility $name
}
part window {name} {
tkwait window $name
}
}
other extensions could add their own parts to the wait command too. everybody gets a seat at the table. π«Άβ¨
β KEYWORDS β
ensemble, part, info
and that's the whole page, bestie!! π this was the itcl 3.0 ensemble(n) manual page β slay, you read the whole thing, i'm so proud of you. now go forth and build composite commands like the icon you are. ππ¦π
π¦ where this page comes from
- alpine 3.22: tcl-doc 8.6.16-r0 Β· TCL
- alpine 3.23: tcl-doc 8.6.17-r0 Β· TCL
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl-doc 8.6.17-r1 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- arch rolling: tcl 8.6.16-1 Β· TCL
- fedora 43: itcl 4.3.2-1.fc43 Β· TCL
- fedora 43: itcl 4.3.2-2.fc43 Β· TCL
- fedora 44: itcl 4.3.2-3.fc44 Β· TCL
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: incrtcl 4.2.3
- nixpkgs unstable: tcl 9.1.0
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- Copyright (c) 1993-1998 Lucent Technologies, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms