Re: Difference between $foo and [set foo]
- From: "Donal K. Fellows" <donal.k.fellows@xxxxxxxxxxxxxxxx>
- Date: Wed, 08 Jun 2005 09:49:12 +0100
Hans Herrmann wrote:
Why i must not do "$$pos" or "[eval puts $pos]" and for the seconde substitution "$pos".
Fundamentally, '$pos' and '[set pos]' do the same thing. However, they parse things a bit differently; the first form just swallows a selected subset of characters following the $ as the variable name (which does not include the $ character itself and which does the substitution immediately so double substitution doesn't work because the later bits have not been substituted yet), and the second form follows the standard Tcl word rules.
Parsing $$foo, Tcl does this: "I see $. Look at next char. Not a 'varname' char, so $ is literal." "I see $. Look at next char. Is a 'varname' char, so consume the varname and substitute the result of reading that variable." This gives the same thing as \$[set foo].
As it happens, the second form actually came first. The $ syntax was added a while later (long long ago) as limited (but useful) syntactic sugar. It took us a good number of years to iron out all the differences though; it wasn't until sometime in the early Tcl8 period that we finally drained that swamp. :^)
Does this help?
Donal. .
- References:
- Difference between $foo and [set foo]
- From: Hans Herrmann
- Difference between $foo and [set foo]
- Prev by Date: Re: Translation of an awk code
- Next by Date: Pgtcl library load with starkits.
- Previous by thread: Re: Difference between $foo and [set foo]
- Next by thread: BLT for acrivetcl8.5.0.0b3
- Index(es):
Relevant Pages
|