View Single Post
  #2 (permalink)  
Old 07-12-2012, 07:23 PM
Eugene
Guest
 
Posts: n/a
Default Re: Question understanding variable expansion

On 12.07.2012 23:02, bmburstein@gmail.com wrote:
> Why does something crazy like this work
>
> set $x pu
> set $y ts
> $x$y hello
>
> outputs "hello", but neither of these work:
>
> set $x {puts hello}
> $x
>
> or
>
> set $x[list puts hello]
> $x
>
> I would think the variable substitution phase (as evident in the first example) would just replace the line `$x` with `puts hello`, and then run that line.

First of all - 'set $x pu' doesn't work, and no wonder - there's no x
defined. There's no need to use $ when you assign a value to a variable.
Second - if you want to put some command into a variable and then run
it, expand it first:
set cmd {puts hello!}
{*}$cmd

--
WBR, Eugene.
Reply With Quote