Range variables - is it just me that thinks they're different?
Update: Ian Griffiths has a more detailed blog post about this matter.
Range variables are the variables used in query expressions. For instance, consider the expression:
from name in names
let length = name.Length
select new { name, length }
Here, name and length are range variables. In C# in Depth, I claim that range variables aren't like any other type of variable. Eric commented that they're not unlike iteration variables in foreach - and since then, I've seen both Jamie King/Bruce Eckel's book, and now C# 3.0 in a Nutshell (which is very good, by the way), using "iteration variable" as the name for range variables. (Update as to the reason for this: they were called iteration variables until a reasonably recent version of the spec, apparently.)
Eric made the point that there are interesting restrictions on the use of iteration variables, just like there are restrictions on the use of range variables. However, that's not enough of a similarity from my point of view. I think of them very, very differently.
When I declare an iteration variable in a foreach loop, the variable really "exists" in that method. It's present in the IL for it as a local variable (or maybe a captured one). When I declare a range variable, it's never a variable in that method - it's just a parameter name in a lambda expression. It's the shadow/promise/ghost of a variable - a variable yet to live, one which will only have a value when I start executing the query.
I suppose in that respect it's closest to the parameter name given in a lambda expression or anonymous method - except that it's valid for multiple parts of a query expression, carrying the value from place to place, via different "normal" parameters.
So, am I crazy for looking at range variables as a different type of beast, or is the rest of the world "wrong" on this one? :)