Shimomura Ikkei

lua-users home
wiki

Showing revision 3

I am thinking to write FunctionalTutorial? :) Here is for a scrap, before make new pages. I did not research exists informations, yet.

Current Interest and Ideas for lua

Functional programming in Lua, Iterator, Generator, Combinator. and Lazy evaluation by coroutine.

Lua's VM and bytecodes stuff. for example, as implementation of bind2, inject the binding value on the function's code(maybe bytecode, and constants field) instead of changing argument orders by wrapped anonymous function.

Current problems

I had copied all elements, but I need is a reference.
assume it as constants, I will not change the table.

           -- Lua sais: attempt to call global `fact' (a nil value)
          local fact = function(num) if (num > 1) return n*fact(n-1) else return 1 end end
          

           -- this is ok. calls global 'fact'
           fact = function(num) if (num > 1) return n*fact(n-1) else return 1 end end
          

           -- but since the closure depend to global, see code below
           temp = fact
           fact = function (num) return num end
           print(temp(10)) -- temp(10) returns 90
          

This is not so much serious problems for everyone,
since we seldom change the recursive call function's name.
you can just make local rule *do not change the function* as gentleman's agreement.

The point is, the function name is looked up in global scope at the runtime.
and that is the space allow effect from outer scopes.

two solutions as I know,
Y-Combinator, provide the function self as the first argument of the function.
or like Perl6, provide special variable which reference to the function self.

Code samples


RecentChanges · preferences
edit · history · current revision
Edited May 20, 2005 10:15 am GMT (diff)