Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Doc: description of command "variable" incomplete

Closed / Invalidf8a20dff9c1b3259c08f3b8b7539c199a5b8a0eeCreated 183 days agoUpdated 182 days ago
Descriptionwiki2026-06-03 13:51:49
The description of the command "variable" https://www.tcl-lang.org/man/tcl9.0/TclCmd/variable.html gives the synopsis:
variable name
variable ?name value...?

I don't know what this means.

The described form is:

variable name ?value?

Unfortunately, the command accepts 0 to infinite arguments. Only 1 or 2 arguments do something:

% namespace eval test {variable v1 c1 c2 c3}
% set test::v1
c1

What is this for:

% namespace eval test {variable}

This is probably due to the fact, that in OO context, the command has a totally different syntax (Ashoks book, page 394):

variable ?SLOTOPERATION? ?VARNAME ...?

The same command "variable v1 c1" means different things:

  • in namespaces, a namespace variable v1 is set to c1
  • in OO, the variables v1 and c1 are defined as class variables.

Great !

I would love, if the command:

  • would give a propper error message, if used in the different contextes.
  • the documentation would document all this strange stuff.

Sorry for my OO unskill level, it is all strange.

Take care, Harald

oehhar Ticket [f8a20dff9c]: 3 changes [History diff]2026-06-03 13:54:01
apnadkarnimarkdown2026-06-04 05:25:12

The use of variable within a class definition (oo::define) has different syntax and is described in the oo::define manpage. (It is also not a "class variable" as that term has a different meaning.)

I agree it is confusing to have a different syntax for commands of the same name and with similar, but not identical function, even though in different scopes but not sure much can be done about it now.

sbronmarkdown2026-06-04 12:30:32

I frequently use the variable command with more than 2 arguments. I'm not sure why you claim that "[o]nly 1 or 2 arguments do something". Here's proof to the contrary:

% namespace eval test {variable v1 c1 v2 c2}
% set test::v1
c1
% set test::v2
c2
oehharwiki2026-06-04 12:41:18

A, thanks. That makes sense.

That is what the syntax in the man page eans:

variable ?name value...?

arbitrary number of variable name and value.

If that is the interpretation, why does this not raise an error:

namespace eval test {variable v1 c1 v2}

This would be the syntax:

variable ?name value...? ?name?

Anyway, thanks for all, noise for nothing but a big dump stupid user...

Sorry, bug closed.

THanks, Harald

Log in (anonymous is fine) to add a comment.