<div class="gmail_quote">On Tue, Jan 27, 2009 at 10:46 AM, Matthew Woehlke <span dir="ltr"><<a href="mailto:mw_triad@users.sourceforge.net">mw_triad@users.sourceforge.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">James Bigler wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have the following code in a script:<br>
<br>
function(set_var var)<br>
message("var = ${var}")<br>
message("${var} = ${${var}}")<br>
set(${var} "new_val")<br>
message("${var} = ${${var}}\n")<br>
endfunction()<br>
<br>
set(myvar 10)<br>
set_var(myvar)<br>
<br>
# Empty variable<br>
set_var(myvar2)<br>
<br>
set_var(var)<br>
<br>
# Set variable<br>
set(var 11)<br>
set_var(var)<br>
<br>
When I run it I get the following output:<br>
<br>
var = myvar<br>
myvar = 10<br>
myvar = new_val<br>
<br>
var = myvar2<br>
myvar2 =<br>
myvar2 = new_val<br>
<br>
var = var<br>
var = var<br>
new_val =<br>
<br>
var = var<br>
var = var<br>
new_val =<br>
<br>
I get expected output when the name of the variable I pass in isn't the same<br>
as the one used in the function parameter list.<br>
<br>
Is this the desired behavior of the language? I would argue that it isn't,<br>
because you get different behavior based on the name of the variable passed<br>
in.<br>
</blockquote>
<br></div></div>
Um... and how would you claim it is supposed to work? You've got a classic case of variable shadowing here. If you think about it, CMake is doing exactly what you told it to do.<br>
<br>
IOW, don't do that ;-).<br>
</blockquote></div><br>Grrrr....I see that now.<br><br>${var} evaluates to var and there's no way to know if that's the function's var or the global scope's var.<br><br>I know you could probably mangle the parameter names to decrease the probability of collisions, but is there any assured method to avoid collisions?<br>
<br>James<br>