On Thu, 11 Feb 2010, Szak�ts Viktor wrote:

Hi,

> IMO it would be more consistent behavior to create a private 
> variable in such case, since with regular FOR/NEXT it also 
> works without declaring the variable:
> --- OK
> FOR tmp := 1 TO Len( a )
> NEXT

Because you have explicit assignment ':=' which creates new memvar
variable if it does not exists just like use as standalone operator
without FOR statement.

> --- Not OK
> FOR EACH tmp IN a
> NEXT
> ---
> 'tmp' is a written variable in both cases.

tmp in FOR EACH is only reference.
Why we should create variable for such reference in FOR EACH
but not in function call?, i.e.:

   func( @tmp )
   ? tmp

'tmp' is also "a written variable" like in above both cases.

Of course if most of Harbour users prefer to create new memvar
variable in FOR EACH then I'll implement it but I do not like it.

But do not forget that FOR EACH does not store dummy references
after iteration but restores original variable value.

   proc main()
      x := 10
      ? x
      for each x in "ABC"
         ? x
      next
      ? x
   return

Personally I even think that FOR EACH should use their own temporary
variables instead of declared ones. It will be much cleaner and faster.

best regards,
Przemek
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to