lua-users home
lua-l archive

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


Thomas Hafner <thomas@hafner.NL.EU.ORG> wrote/schrieb <20061222124105.2531B38874CA@faun.hafner.NL.EU.ORG>:

> function foo (start)
>    for i=start,9 do
>       if i>=3 and i<=7 then return foo(i + 1) end  --exclude i= 3,4,5,6,7
>       print(i)
>    end
> end
> foo(0)
> 
> Hmm, this solution is one line longer than yours. But if your code
> example is just a snippet out of an already existing function, it may
> have the same amount of lines in total.

By the way, in Scheme ``named let'' would do it elegantly. May be this
would be a template for extending Lua with regard to continue
capabilities?

A ``named let'' is a syntactical form wich provides both at the same
time: define a function *and* call it. Just a proposal how it could
look like in a future version of Lua (I invented a new keyword
``label''):

label foo(start=0)
   for i=start,9 do
      if i>=3 and i<=7 then return foo(i + 1) end  --exclude i= 3,4,5,6,7
      print(i)
   end
end

For more than one variable the syntax could look like this:
label foo(start=0,tmp=5)
....

Regards
  Thomas