Re: Difference between $foo and [set foo]



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.
.



Relevant Pages

  • Re: Barcode Email
    ... Anonymous via Panta Rhei schrieb: ... Substitution is dynamic and ... >>randomly generated over millions of characters most of which you have never ... > There is a set of rules that standardizes the transformation. ...
    (sci.crypt)
  • Re: script help
    ... if B is via1 then will need to be changed to MET1 ... substitution. ... Post a few lines of actual sample input and expected output for ... characters of the last field when "" is found otherwise just ...
    (comp.unix.shell)
  • Re: Barcode Email
    ... On 27 Jul 2005 19:51:35 GMT, Juergen Nieveler wrote: ... >> and randomly generated over millions of characters most of which you ... >> How's your hieroglyphics? ... > And if your substitution would be truly random when encrypting, ...
    (sci.crypt)
  • Re: Escaping escape characters in variables (in regexs)
    ... applying quotemeta to the first part of the substitution ... I've got to replace some characters in Base64 encoded data in a text ...
    (comp.lang.perl.misc)
  • Re: Barcode Email
    ... On 27 Jul 2005 19:51:35 GMT, Juergen Nieveler wrote: ... >> and randomly generated over millions of characters most of which you ... >> How's your hieroglyphics? ... > And if your substitution would be truly random when encrypting, ...
    (comp.security.misc)