Re: add additional subcommand for the "chan" tcl command?

Liste des GroupesRevenir à cl tcl 
Sujet : Re: add additional subcommand for the "chan" tcl command?
De : nospam (at) *nospam* wanadoo.nl (Schelte)
Groupes : comp.lang.tcl
Date : 17. Jun 2024, 15:11:14
Autres entêtes
Organisation : KPN B.V.
Message-ID : <nnd$5800c649$6c7c9ec6@3c4b42606e7ba6bb>
References : 1
User-Agent : Mozilla Thunderbird
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.

Date Sujet#  Auteur
17 Jun 24 * add additional subcommand for the "chan" tcl command?5aotto1968
17 Jun 24 `* Re: add additional subcommand for the "chan" tcl command?4Schelte
17 Jun 24  +- Re: add additional subcommand for the "chan" tcl command?1aotto1968
17 Jun 24  `* Re: add additional subcommand for the "chan" tcl command?2aotto1968
18 Jun 24   `- Re: add additional subcommand for the "chan" tcl command?1aotto1968

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal