Sujet : Re: add additional subcommand for the "chan" tcl command?
De : aotto1968 (at) *nospam* t-online.de (aotto1968)
Groupes : comp.lang.tclDate : 17. Jun 2024, 20:21:18
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4q2be$sq8k$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
thanks … the technology to add my own ensemble-command into an existing ensemble should be more used.
On 17.06.24 16:11, Schelte wrote:
On 17/06/2024 15:20, aotto1968 wrote:
I would like to add "chan exists str" just to signal a boolean return on exists and I want to do this
*without* to touch the tcl distribution.
>
there is already a feature like "::tcl:mathfunc::????" to add an additional function to "expr" and I
ask me now it is possible to do such a kind of "addition" to the "chan" command as well ?
>
The chan command is an ensemble, so you can add your own subcommands. It is a bit more work than adding a math function, but not too much:
proc chanexists {fd} {
return [expr {$fd in [chan names]}]
}
namespace ensemble configure chan -map [dict replace \
[namespace ensemble configure chan -map] exists ::chanexists]
After that, you get the following results:
% chan help
unknown or ambiguous subcommand "help": must be blocked, close, configure, copy, create, eof, event, exists, flush, gets, names, pending, pipe, pop, postevent, push, puts, read, seek, tell, or truncate
% chan exists stdin
1
% chan exists nosuchchan
0
Schelte.