Shimomura Ikkei

lua-users home
wiki

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.

MEMO: Range, Slice object that have the reference to original data,
and index informations. find the item when the data is required.
but since table is mutable data, how to notify the original data is updated.
'Self' might have papers on such topics, though ...

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

        -- this is ok. calls global 'fact'
        fact = function(num) if (num > 1) return n*fact(num-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.

The solutions I know are,
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.

        -- the 'a' in table is nil.
        local a = { a }

        -- what the function f returns ? ... 
        local f = function() return f end 
        

the 'f' in the function is the f when the function is made.
it seem correct as local/static scope behavior.
pharps, I think is "let-rec" for binding recursive function.

Code samples


RecentChanges · preferences
edit · history
Last edited May 20, 2005 3:41 pm GMT (diff)