Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

<wiggy> bwah, vodka in my mouse


devel / comp.lang.tcl / how to discover proc and ensemble subcommands AKA a better tcl introspection

SubjectAuthor
* how to discover proc and ensemble subcommands AKA a better tcl introspectionpd
+- Re: how to discover proc and ensemble subcommands AKA a better tcl introspectionArjen Markus
`- Re: how to discover proc and ensemble subcommands AKA a better tclet99

1
how to discover proc and ensemble subcommands AKA a better tcl introspection

<9bcb060b-c06d-4a54-a908-34c7eea4e50en@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22486&group=comp.lang.tcl#22486

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:622a:506:b0:403:b6b0:bdb5 with SMTP id l6-20020a05622a050600b00403b6b0bdb5mr11572qtx.7.1690445350811;
Thu, 27 Jul 2023 01:09:10 -0700 (PDT)
X-Received: by 2002:a05:6808:191a:b0:3a1:a15b:ef9f with SMTP id
bf26-20020a056808191a00b003a1a15bef9fmr4351533oib.0.1690445350578; Thu, 27
Jul 2023 01:09:10 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 27 Jul 2023 01:09:10 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=213.177.216.159; posting-account=fwjo5QoAAAAcS9TSqEAQL1VEl7b8nCOq
NNTP-Posting-Host: 213.177.216.159
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9bcb060b-c06d-4a54-a908-34c7eea4e50en@googlegroups.com>
Subject: how to discover proc and ensemble subcommands AKA a better tcl introspection
From: eukelade@gmail.com (pd)
Injection-Date: Thu, 27 Jul 2023 08:09:10 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4376
 by: pd - Thu, 27 Jul 2023 08:09 UTC

When I get into tcl introspection I always feel uncomfortable because there's a plethora of methods to get things done (info, package, namespace, array...) and sometimes you need some king of scripting or it's not possible to get it at all .

This time I was wondering how I can discover the subcommands a command (proc) or ensemble provides. Of course there's no direct way. You have to do some scripting but the problem is it is not the same scripting.

Following this stackoverflow question [1] if you want to know what subcommands a command or proc provide you should guess by failing, you call the command with a "not used subcommand for sure" and interpret the message saying there no such subcommand and providing the available commands. Something like:

proc listOptions args {
try {
{*}$args -!
} on error msg {
if {[regexp {should be one of (.*)} $msg -> items]} {
return [string map {{, or } { } , {}} $items]
}
}
error "no option list from $args"
}

puts [listOptions chan configure stdout]

The problem is this doesn't work as a general solution because parsing the output fail when output displays a subtle different error message for different things (subcommands, options...) so parsing should be adapted for every case:

% chan k
unknown or ambiguous subcommand "k": must be blocked, close, configure, copy, create, eof, event, flush, gets, names, pending, pipe, pop, postevent, push, puts, read, seek, tell, or truncate

% chan configure stdout k
bad option "k": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation

% array k
unknown or ambiguous subcommand "k": must be anymore, donesearch, exists, get, names, nextelement, set, size, startsearch, statistics, or unset

On the other hand ensembles also requires scripting but a different one, ensemble have a "discovering command" to list all subcommands available, so to list the subcommands of ensemble string you can do:

dict keys [namespace ensemble configure $cmd -map]

So this is a real mess, and there's no a unified way to do introspection

It would be great to have a common introspection command, for example info, to gather all kind of info relating variables, commands, namespaces, packages, etc

Or at least, wouldn't be great if every command have a subcommand just to list all subcommands available, and even every subcommand a subcommand to list the options accepted ?

Maybe something like:

% chan help
blocked, close, configure, copy, create, eof, event, flush, gets, names, pending, pipe, pop, postevent, push, puts, read, seek, tell, truncate

% chan configure stdout help
-blocking, -buffering, -buffersize, -encoding, -eofchar, -translation

% array help
anymore, donesearch, exists, get, names, nextelement, set, size, startsearch, statistics, unset

% string help
bytelength, cat, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, toupper, totitle, trim, trimleft, trimright, wordend, wordstart

regards

[1] https://stackoverflow.com/questions/75076109/tcl-how-to-get-the-list-of-all-possible-sub-commands-switches-for-a-given-tcl

Re: how to discover proc and ensemble subcommands AKA a better tcl introspection

<2861fb24-d0ed-48de-b94d-ba7ff039bf27n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22531&group=comp.lang.tcl#22531

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:4f02:0:b0:63c:f952:2d0e with SMTP id fb2-20020ad44f02000000b0063cf9522d0emr28216qvb.2.1691564104619;
Tue, 08 Aug 2023 23:55:04 -0700 (PDT)
X-Received: by 2002:aca:1318:0:b0:3a4:1484:b3db with SMTP id
e24-20020aca1318000000b003a41484b3dbmr17001473oii.5.1691564104310; Tue, 08
Aug 2023 23:55:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 8 Aug 2023 23:55:03 -0700 (PDT)
In-Reply-To: <9bcb060b-c06d-4a54-a908-34c7eea4e50en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=136.231.213.2; posting-account=A91wAAoAAADgBUxBX6QqsrSD26GLhVp8
NNTP-Posting-Host: 136.231.213.2
References: <9bcb060b-c06d-4a54-a908-34c7eea4e50en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2861fb24-d0ed-48de-b94d-ba7ff039bf27n@googlegroups.com>
Subject: Re: how to discover proc and ensemble subcommands AKA a better tcl introspection
From: arjen.markus895@gmail.com (Arjen Markus)
Injection-Date: Wed, 09 Aug 2023 06:55:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Arjen Markus - Wed, 9 Aug 2023 06:55 UTC

On Thursday, July 27, 2023 at 10:09:13 AM UTC+2, pd wrote:
> When I get into tcl introspection I always feel uncomfortable because there's a plethora of methods to get things done (info, package, namespace, array...) and sometimes you need some king of scripting or it's not possible to get it at all .
>
....

Probably not quite what you are looking for, but the Nextcl project (https://wiki.tcl-lang.org/page/The+NexTcl+Project) seems useful in that respect. Stephan mentioned that he wants to work on a language server for Tcl. (See also his posts about the project)

Regards,

Arjen

Re: how to discover proc and ensemble subcommands AKA a better tcl introspection

<ub6p16$164dn$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22537&group=comp.lang.tcl#22537

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: how to discover proc and ensemble subcommands AKA a better tcl
introspection
Date: Fri, 11 Aug 2023 18:59:00 -0700
Organization: A noiseless patient Spider
Lines: 76
Message-ID: <ub6p16$164dn$1@dont-email.me>
References: <9bcb060b-c06d-4a54-a908-34c7eea4e50en@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 12 Aug 2023 01:59:03 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c3585be224b778c2e1d51a3cd3189b26";
logging-data="1249719"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yVyOU9i7mz8fLkRSZM/8T"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:P6xFM5zS11TKdesxksETSVdEDGM=
Content-Language: en-US
In-Reply-To: <9bcb060b-c06d-4a54-a908-34c7eea4e50en@googlegroups.com>
 by: et99 - Sat, 12 Aug 2023 01:59 UTC

On 7/27/2023 1:09 AM, pd wrote:
> When I get into tcl introspection I always feel uncomfortable because there's a plethora of methods to get things done (info, package, namespace, array...) and sometimes you need some king of scripting or it's not possible to get it at all .
>
> This time I was wondering how I can discover the subcommands a command (proc) or ensemble provides. Of course there's no direct way. You have to do some scripting but the problem is it is not the same scripting.
>
> Following this stackoverflow question [1] if you want to know what subcommands a command or proc provide you should guess by failing, you call the command with a "not used subcommand for sure" and interpret the message saying there no such subcommand and providing the available commands. Something like:
>
> proc listOptions args {
> try {
> {*}$args -!
> } on error msg {
> if {[regexp {should be one of (.*)} $msg -> items]} {
> return [string map {{, or } { } , {}} $items]
> }
> }
> error "no option list from $args"
> }
>
> puts [listOptions chan configure stdout]
>
> The problem is this doesn't work as a general solution because parsing the output fail when output displays a subtle different error message for different things (subcommands, options...) so parsing should be adapted for every case:
>
> % chan k
> unknown or ambiguous subcommand "k": must be blocked, close, configure, copy, create, eof, event, flush, gets, names, pending, pipe, pop, postevent, push, puts, read, seek, tell, or truncate
>
> % chan configure stdout k
> bad option "k": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -translation
>
> % array k
> unknown or ambiguous subcommand "k": must be anymore, donesearch, exists, get, names, nextelement, set, size, startsearch, statistics, or unset
>
> On the other hand ensembles also requires scripting but a different one, ensemble have a "discovering command" to list all subcommands available, so to list the subcommands of ensemble string you can do:
>
> dict keys [namespace ensemble configure $cmd -map]
>
> So this is a real mess, and there's no a unified way to do introspection
>
> It would be great to have a common introspection command, for example info, to gather all kind of info relating variables, commands, namespaces, packages, etc
>
> Or at least, wouldn't be great if every command have a subcommand just to list all subcommands available, and even every subcommand a subcommand to list the options accepted ?
>
> Maybe something like:
>
> % chan help
> blocked, close, configure, copy, create, eof, event, flush, gets, names, pending, pipe, pop, postevent, push, puts, read, seek, tell, truncate
>
> % chan configure stdout help
> -blocking, -buffering, -buffersize, -encoding, -eofchar, -translation
>
> % array help
> anymore, donesearch, exists, get, names, nextelement, set, size, startsearch, statistics, unset
>
> % string help
> bytelength, cat, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, toupper, totitle, trim, trimleft, trimright, wordend, wordstart
>
> regards
>
>
>
> [1] https://stackoverflow.com/questions/75076109/tcl-how-to-get-the-list-of-all-possible-sub-commands-switches-for-a-given-tcl

You might find this website, by Ashok useful.

https://www.magicsplat.com/tcl-docs/docindex.html

This is especially handy if you can launch the url with a parameter using ?search= as shown on that page. If the parameter is unique, it will load the appropriate page, otherwise it will provide clickable choices. Try this one:

https://www.magicsplat.com/tcl-docs/docindex.html?search=chan

The first choice, chan tcl, gives you the full man page.


devel / comp.lang.tcl / how to discover proc and ensemble subcommands AKA a better tcl introspection

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor