Bill Allombert on Tue, 23 Feb 2010 14:18:40 +0100

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Getting the variable number of a lexical local variable

On Mon, Feb 22, 2010 at 04:08:18PM -0500, Charles Greathouse wrote:
> I see, thanks for the explanation.  So it's not possible to know what
> variable number is used; 

Actually, it is possible: just use the code 'n', not 'V='.

> maybe I should just change the format to
> sumformal(1, n, x^3 + 3)
> rather than
> sumformal(x=1, n, x^3 + 3)
> since I don't want to make users think they can control what variable is used.

Well, you can use
sumformal(x,1, n, x^3 + 3)
instead. The only difference is the use of a comma instead of =.

> But wait:
> x=10;y=100;for(x=1,2,print(x^2*y))
> and
> x=10;y=100;for(y=1,2,print(x^2*y))
> give different results.  How can they tell?

They do not: they simply use the code 'I' to evaluate the expression
'print(x^2*y)' while setting the loop variable to 1 and 2. They do not
know what is the name of the loop variable, and there is no polynomial
variables associated to that name. And in any case 'print(x^2*y)' is
not a polynomial expression.