transchan(3tcl)
β¨ transchan β bestie edition β¨
okay so you want to know about transchan, the Tcl built-in command page for the command handler API for channel transforms implemented in Tcl code. it's from the 3tcl manual, and it's genuinely iconic once it clicks. let's go π
π NAME π
transchan β the command handler API for channel transforms implemented in Tcl code. that's it, that's the whole vibe. π¦
πΈ SYNOPSIS πΈ
chan push channel cmdPrefix
cmdPrefix clear handle
cmdPrefix drain handle
cmdPrefix finalize handle
cmdPrefix flush handle
cmdPrefix initialize handle mode
cmdPrefix limit? handle
cmdPrefix read handle buffer
cmdPrefix write handle buffer
π DESCRIPTION π
so the Tcl-level handler for a channel transformation has to be a command with subcommands. the manpage calls it an ensemble β but lowkey don't panic, that does not mean it has to be made with namespace ensemble create. this mechanism is not tied to namespace ensemble in any way, fr fr. they're just using the word. π
cmdPrefix is literally whatever you passed in the call to chan push, and bestie, it may consist of multiple arguments β it all gets expanded into multiple words in place of the prefix. so don't @ me when your prefix is three words long.
of all the possible subcommands, the handler must support initialize and finalize. that's the non-negotiable core. then:
- transformations for writable channels must also support
write - transformations for readable channels must also support
read
heads up: in everything below,cmdPrefixmight be more than one word, andhandleis the value returned by thechan pushcall you used to create the transformation. don't lose that handle. she's your main character. π
π GENERIC SUBCOMMANDS π
these ones are relevant to all types of channel. everyone's invited to this party. π«Ά
cmdPrefix clear handleβ this optional subcommand gets called to tell the transformation that any data stored in internal buffers β incoming or outgoing, both of them β must be cleared. it's called when achan seekis performed on the channel being transformed. so basically: wipe the slate, babe. π§ΉcmdPrefix finalize handleβ this one is mandatory. it's called last for the given handle, and then never again, periodt. its whole job is to let you clean up any Tcl-level data structures associated with the transformation.
β οΈ Warning! Any errors thrown by this subcommand will be ignored. and it is not guaranteed to be called if the interpreter is deleted. so don't put your hopes and dreams in there. π
cmdPrefix initialize handle modeβ this one is also mandatory. it's called first, and then never again for the given handle. its responsibility is to initialize all parts of the transformation at the Tcl level. themodeis a list containing any ofreadandwrite:writeimplies that the channel is writable.readimplies that the channel is readable.
the return value of the subcommand should be a list containing the names of all subcommands supported by this handler. and listen β any error thrown by the subcommand will prevent the creation of the transformation. that thrown error will appear as an error thrown by chan push. so if you fumble the initialize, the whole thing never gets born. no cap. π
π¦ READ-RELATED SUBCOMMANDS π¦
these are the ones for handling transformations applied to readable channels. technically read is optional, but β and this is the important part β it must be supported if any of the others is, or the channel will be made non-readable. choose wisely bestie. π
cmdPrefix drain handleβ optional subcommand, called whenever data in the transformation input (i.e. the read buffer) has to be forced upward β toward the user or script. the result returned by the method is taken as the binary data to push upward to the level above this transformation (the reader, or a higher-level transformation).
in other words: when this method gets called, the transformation cannot defer the actual transformation operation anymore. she has to transform all data waiting in her internal read buffers and return the result of that action. no more procrastinating. β¨
cmdPrefix limit? handleβ optional subcommand, called to let the Tcl I/O engine figure out how far ahead it should read. if it's present, it should return an integer number greater than zero which indicates how many bytes ahead should be read, or an integer less than zero to indicate that the I/O engine may read as far ahead as it likes. (yes the subcommand name has a?in it. we love a quirky queen. π )cmdPrefix read handle bufferβ this subcommand must be present if the transformation is going to work with readable channels. it's called whenever the base channel, or a transformation below this transformation, pushes data upward. thebuffercontains the binary data which has been given to us from below. it is the responsibility of this subcommand to actually transform the data. the result returned by the subcommand is taken as the binary data to push further upward to the transformation above this transformation. this can also be the user or script that originally read from the channel. π«Ά
and note β the result is allowed to be empty, or even less than the data we received. the transformation is not required to transform everything given to it right now. it's allowed to store incoming data in internal buffers and to defer the actual transformation until it has more data. so, y'know, hoarding is legal here. π
β WRITE-RELATED SUBCOMMANDS β
these are for handling transformations applied to writable channels. again, write is technically optional, but it must be supported if any of the others is, or the channel will be made non-writable. the stakes are real. π₯
cmdPrefix flush handleβ optional subcommand, called whenever data in the transformation'write'buffer has to be forced downward β toward the base channel. the result returned by the subcommand is taken as the binary data to write to the transformation below the current transformation. this can be the base channel as well.
in other words: when this subcommand is called, the transformation cannot defer the actual transformation operation anymore. she has to transform all data waiting in her internal write buffers and return the result of that action. clock's ticking, babe. β°
cmdPrefix write handle bufferβ this subcommand must be present if the transformation is going to work with writable channels. it's called whenever the user, or a transformation above this transformation, writes data downward. thebuffercontains the binary data which has been written to us. it is the responsibility of this subcommand to actually transform the data. πͺ
the result returned by the subcommand is taken as the binary data to write to the transformation below this transformation. this can be the base channel as well. and note β the result is allowed to be empty, or less than the data we got. the transformation is not required to transform everything which was written to it right now. it's allowed to store this data in internal buffers and to defer the actual transformation until it has more data. iconic behaviour honestly. π
π SEE ALSO π
chan(3tcl), refchan(3tcl) β go read your sisters, bestie, they're part of the same friend group. π
π KEYWORDS π
API, channel, ensemble, prefix, transformation
and that's the whole page, bestie!! you ate this. πβ¨ππ¦πΈπ π«Ά
sign-off time π₯° β this is from Tcl, version 8.6, and the manual section is transchan(3tcl). go transform some channels, queen. π
π
π¦ where this page comes from
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 2008 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms