Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Removing a proc (by renaming it to "")

49 views
Skip to first unread message

Kenny McCormack

unread,
Jun 28, 2021, 11:40:22 AM6/28/21
to
I found that the way to remove a proc definition is to rename it to "",
like this:

% proc foo {} { puts "Foo!" }
% foo
Foo!
% rename foo ""
% foo
invalid command name "foo"

My question is: Does this really remove it or does it just rename it to
some inaccessible name? I.e., is it still out there somewhere, taking up
space (not that that would really matter much; I'm just curious).

I note that you can't rename it back (rename "" foo fails), so it does
seems like it really does just disappear, but I'm still curious about it -
hence this post.

Does the rename command recognize "" as a magic string, that causes the
proc to be really deallocated?

--
I love the poorly educated.

Harald Oehlmann

unread,
Jun 28, 2021, 11:59:54 AM6/28/21
to
Yes, "" is the magic string to drop a function.

Rich

unread,
Jun 28, 2021, 1:13:02 PM6/28/21
to
Kenny McCormack <gaz...@shell.xmission.com> wrote:
> I found that the way to remove a proc definition is to rename it to "",

This is the documented way to delete a command:

man rename:

... If newName is an empty string then oldName is deleted. ...

> My question is: Does this really remove it or does it just rename it to
> some inaccessible name?

The man page says "deleted". I consider "deleted" to mean it is really
gone.

> Does the rename command recognize "" as a magic string, that causes
> the proc to be really deallocated?

According to the documentation, yes.

Rolf Ade

unread,
Jun 28, 2021, 7:40:08 PM6/28/21
to

gaz...@shell.xmission.com (Kenny McCormack) writes:
> I found that the way to remove a proc definition is to rename it to "",
> like this:
> [...]
> I note that you can't rename it back (rename "" foo fails), so it does
> seems like it really does just disappear, but I'm still curious about it -
> hence this post.
>
> Does the rename command recognize "" as a magic string, that causes the
> proc to be really deallocated?

To entertain you aside the reference to the documentation you already
got:

It is possible in Tcl that the empty string is a command.

proc {} {} {
puts "Called"
}

Call it with

""

or

{}

If you rename this proc to the empty string ("") - the name it already
has - then it will of course vanish.

rename "" ""

Now you can't call "" anymore.

Another corollary: All other commands can be renamend - to replace them
with another one for a while, for example - and can later renamed back
to its original name. This is not possible for a command with the empty
string as name. If you rename it from it original name, you have to
redefine it with proc.

Kenny McCormack

unread,
Jun 29, 2021, 7:05:23 AM6/29/21
to
In article <877didh...@pointsman.de>, Rolf Ade <ro...@pointsman.de> wrote:
...
>To entertain you aside the reference to the documentation you already
>got:
>
>It is possible in Tcl that the empty string is a command.
>
>proc {} {} {
> puts "Called"
>}
>
>Call it with
>
>""
>
>or
>
>{}
>
>If you rename this proc to the empty string ("") - the name it already
>has - then it will of course vanish.
>
>rename "" ""
>
>Now you can't call "" anymore.
>
>Another corollary: All other commands can be renamend - to replace them
>with another one for a while, for example - and can later renamed back
>to its original name. This is not possible for a command with the empty
>string as name. If you rename it from it original name, you have to
>redefine it with proc.

Thanks. This is very interesting stuff.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Snicker

Harald Oehlmann

unread,
Jun 29, 2021, 7:24:03 AM6/29/21
to

Am 29.06.2021 um 01:40 schrieb Rolf Ade:
> Another corollary: All other commands can be renamend - to replace them
> with another one for a while, for example - and can later renamed back
> to its original name. This is not possible for a command with the empty
> string as name. If you rename it from it original name, you have to
> redefine it with proc.
>

Rolf,

I am realy impressed by your deep knowledge of all those edge-cases.

Thank you,
Harald

Mike Griffiths

unread,
Jun 29, 2021, 7:43:44 PM6/29/21
to
This is actually not completely true:

> proc {} {} {puts foo}
> ""
foo
> rename {} bar
> bar
foo
> rename bar ::
> ""
foo

Because you're using a namespace qualifier, your arg isn't an empty string (so doesn't trigger the 'destroy command' variant of 'rename') but you're still referring to a command with an empty string name.

Rolf Ade

unread,
Jun 29, 2021, 7:51:02 PM6/29/21
to
You're right. Neat.
0 new messages