I am just going to use Perl as a comparison here:
$foo = 5;
print $foo;
sets the variable $foo
to 5, and then prints the contents of the variable (notice that $foo
is always accessed as $foo
).
In Tcl:
set foo 5
puts $foo
does the same thing as the Perl counterpart.
Why doesn't Tcl set variables with the "$", but need a "$" to access a variable?
Why is this true for procedures too (e.g.proc bar {spam eggs} {...}
)?
To me, the Tcl code looks like this (in pseudocode):
"foo" = 5 # Setting a string?
puts $foo # "$foo" is not defined.
(my comments only reflect what appears to be happening, not what is happening).
Another point I want to add is the clarity of this:
set foo foo
Yeah, I could always do set foo "foo"
, but isn't set $foo foo
more consistent?
From what I know, "foo" can be a variable or a string, depending on the situation, as seen in my last example (set foo foo
= set var string
), but I don't get this syntax (maybe because I'm used to Python...)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…