Deutsch   English   Français   Italiano  
<nnd$5800c649$6c7c9ec6@3c4b42606e7ba6bb>

View for Bookmarking (what is this?)
Look up another Usenet article

Date: Mon, 17 Jun 2024 16:11:14 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: add additional subcommand for the "chan" tcl command?
Newsgroups: comp.lang.tcl
References: <v4pd73$m2ov$1@dont-email.me>
Content-Language: en-US
From: Schelte <nospam@wanadoo.nl>
In-Reply-To: <v4pd73$m2ov$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <nnd$5800c649$6c7c9ec6@3c4b42606e7ba6bb>
Organization: KPN B.V.
Path: ...!weretis.net!feeder9.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe004.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 33
Injection-Date: Mon, 17 Jun 2024 16:11:16 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
Bytes: 1946

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.