lua-users home
lua-l archive

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

It was thus said that the Great Soni L. once stated:
> On 06/08/16 06:19 AM, Tim Hill wrote:
> >
> >A more interesting question .. why do you need this? And, for your 
> >need, have you explored other ways to solve the problem within the 
> >existing Lua language?
> I've used recursive pseudo-anonymous functions before. _SELF would make 
> them easier to use.
> f((function()
>   local function inside_anonymous(args, I, should, take)
>   end
>   return inside_anonymous
> end)())

  You just need a Y-combinator:

	function Y(f)
	  local function g(...) return f(g,...) end
	  return g

	print(Y(function(rec, x) 
			if x < 2 then 
				return 1 
				return x * rec(x-1) 

  That will allow you to call an anonymous function recurively from within
the anonymous function.  No need for _SELF in this case.

  -spc (Now, about that _SUPER ...  )