lua-users home
lua-l archive

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




On 17/04/15 05:47 AM, Sean Conner wrote:
It was thus said that the Great Soni L. once stated:
Conclusion: By making a function like:

local function stackmanager(action, value, ...)
   if action == "push" then
     local _action, _value = coroutine.yield()
     return stackmanager(_action, _value, value, ...)
   elseif action == "pop" then
     local _action, _value = coroutine.yield((...)) -- yield only stack top
     return stackmanager(_action, _value, select(2, ...))
   end
end

You can use coroutines as a revolutionary data structure! With this, Lua
doesn't have 1, but 2 data structures. (One could argue strings are also
a data structure, and then you'd have 3.)
   Ah yes.  Closures are a poor man's object.

	http://c2.com/cgi/wiki?ClosuresAndObjectsAreEquivalent
	http://stackoverflow.com/questions/2497801/closures-are-poor-mans-objects-and-vice-versa-what-does-this-mean

   -spc (seems a bit less obvious and slower than table.insert() and
	table.remove() ... )
Yes, but it can store nil without breaking.

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.