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.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)