Re: Variable naming




mjanssen wrote:
Dario D. wrote:
Hello all,

Is slash (/) allowed in variable names? I'm reading a tutorial on the
NS2 simulator, and it appears to be using slashes in class names:

set tcp [new Agent/TCP]

I tried to run the following example through tclsh, but as you can see
it didn't work out well:

% set test/blah 5
5
% puts $test/blah
can't read "test": no such variable


Yes / is allowed in variable names. However, you do have to take a bit
care when getting the value with $. Not all the values that are valid
in a variable name, are valid in a $ expansion without braces. For the
exact rules see the Dodekalogue (http://wiki.tcl.tk/10259) rule 8.


For 8.4, I should of course have refered to the Endekalogue included in
the Tcl man page (http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm) rule 7.

Mark

.



Relevant Pages

  • Re: Variable naming
    ... I'm reading a tutorial on the ... NS2 simulator, and it appears to be using slashes in class names: ... % set test/blah 5 ... % puts $test/blah ...
    (comp.lang.tcl)
  • Re: Variable naming
    ... I'm reading a tutorial on the NS2 simulator, and it appears to be using slashes in class names: ... % set test/blah 5 ... % puts $test/blah ... Bear in mind that, although any character is valid for a variable name, the parsing for $ only looks for a subset of all possible characters. ...
    (comp.lang.tcl)