[moving this over from users to devel]
I guess what I mean is:
in a 'loop for i=1..10' expression, the index i obviously takes on
integer values, and it is clear that you have to do some type conversion
to get strings out of that. Hence in that case $i is perfectly intuitive.
However, in a 'loop foreach i peach pear plum' expression it...
(a) either looks as if i takes on the names of the series. Then why on
earth do I need to use $i instead of just plain i? Or...
(b) the index i really must be thought as looking up the id numbers of
the involved series, and hence is a number. But if series 'peach' has
id#2, then I would expect $i to give the string representation of "2".
In that case, to get back the name of 'peach' through the loop index i
in the first iteration, I would rather have a syntax like 'name(i)', or
some other prefix like '§i' or whatever. Otherwise IMHO it clashes with
the use in the standard for loops, see above, and that's what I find
confusing.
Was that understandable know, or have I maybe got it all wrong?
thanks for the patience,
sven
On 30.01.2009 02:22, Allin Cottrell wrote:
On Thu, 29 Jan 2009, Sven Schreiber wrote:
>> In a "foreach" loop the '$i' construction
works by lookup: it
>> indexes into the relevant array of strings or variable names and
>> returns entry i at iteration i.
>>
>> In other sorts of loops, '$i' just gives the string representation
>> of the current index value, as if you had done
>>
>> sprintf foo "%d", i
> See I guess it's exactly this double, context-dependent, meaning
> that I find confusing. I associate $i with string
> representation, and then I'm all baffled why that (in a foreach
> loop context) won't give me a string with a series name, but
> some totally different thing.
Er, sorry, but what totally different thing? "A string with a
series name" is exactly what it gives you, no?
For example, in
<script>
open data4-1
list L = 1 2 3
loop foreach i L
print $i
endloop
</script>
the loop part is equivalent to typing
print price
print sqft
print bedrms
and in
<script>
open data4-1
list L = 1 2 3
loop foreach i L
print "$i"
endloop
</script>
the loop is equivalent to typing
print "price"
print "sqft"
print "bedrms"
I don't mean to be unhelpful, but I don't yet understand the
problem. It seems totally transparent to me ;-) (who wrote it!).
Allin.
_______________________________________________
Gretl-users mailing list
Gretl-users(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users