Charles Greathouse on Tue, 23 Feb 2010 15:03:56 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Getting the variable number of a lexical local variable |
> Actually, it is possible: just use the code 'n', not 'V='. I mean that it's not (apparently) possible to get it from the existing signature. > Well, you can use > sumformal(x,1, n, x^3 + 3) > instead. The only difference is the use of a comma instead of =. I guess that's not too bad. I don't suppose there's a way to overload it so that I can have it called with V=GGG or nGGG? Charles Greathouse Analyst/Programmer Case Western Reserve University On Tue, Feb 23, 2010 at 8:11 AM, Bill Allombert <Bill.Allombert@math.u-bordeaux1.fr> wrote: > 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. > > Cheers, > Bill.