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 They/Them L. once stated:
> 
> On 2021-06-17 7:12 p.m., Petite Abeille wrote:
> >
> > > On Jun 17, 2021, at 23:57, Soni They/Them L. <fakedme@gmail.com> wrote:
> > > 
> > > We guess there's no way to make safe self-referential functions in Lua?
> >
> > debug.getinfo( 1, 'f' ).func perhaps?
> >
> Gross, altho it does work :p
> 
> Still, that's not something you'd wanna use in public. Would be nice if
> you could just const a local function, but eh, maybe in the future. ^^

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

local y <const> = Y(function(r,x)
  print(x)
  if x > 0 then
    return r(x-1)
  end
end)

y(3)

 -spc