{"action":"created","issue":{"url":"https://api.github.com/repos/IonoclastBrigham/firth/issues/1","labels_url":"https://api.github.com/repos/IonoclastBrigham/firth/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/IonoclastBrigham/firth/issues/1/comments","events_url":"https://api.github.com/repos/IonoclastBrigham/firth/issues/1/events","html_url":"https://github.com/IonoclastBrigham/firth/issues/1","id":72480727,"number":1,"title":"Code (especially stack) too complex","user":{"login":"SoniEx2","id":1779619,"avatar_url":"https://avatars.githubusercontent.com/u/1779619?v=3","gravatar_id":"","url":"https://api.github.com/users/SoniEx2","html_url":"https://github.com/SoniEx2","followers_url":"https://api.github.com/users/SoniEx2/followers","following_url":"https://api.github.com/users/SoniEx2/following{/other_user}","gists_url":"https://api.github.com/users/SoniEx2/gists{/gist_id}","starred_url":"https://api.github.com/users/SoniEx2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SoniEx2/subscriptions","organizations_url":"https://api.github.com/users/SoniEx2/orgs","repos_url":"https://api.github.com/users/SoniEx2/repos","events_url":"https://api.github.com/users/SoniEx2/events{/privacy}","received_events_url":"https://api.github.com/users/SoniEx2/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-01T17:34:17Z","updated_at":"2015-05-02T03:38:21Z","closed_at":null,"body":"See https://github.com/SoniEx2/Stuff/tree/master/lua/Forth for a much simpler stack, exploiting language features (the call stack and the varargs)\r\n\r\n(I'd think varargs are more efficiently JITted, idk)"},"comment":{"url":"https://api.github.com/repos/IonoclastBrigham/firth/issues/comments/98295913","html_url":"https://github.com/IonoclastBrigham/firth/issues/1#issuecomment-98295913","issue_url":"https://api.github.com/repos/IonoclastBrigham/firth/issues/1","id":98295913,"user":{"login":"SoniEx2","id":1779619,"avatar_url":"https://avatars.githubusercontent.com/u/1779619?v=3","gravatar_id":"","url":"https://api.github.com/users/SoniEx2","html_url":"https://github.com/SoniEx2","followers_url":"https://api.github.com/users/SoniEx2/followers","following_url":"https://api.github.com/users/SoniEx2/following{/other_user}","gists_url":"https://api.github.com/users/SoniEx2/gists{/gist_id}","starred_url":"https://api.github.com/users/SoniEx2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SoniEx2/subscriptions","organizations_url":"https://api.github.com/users/SoniEx2/orgs","repos_url":"https://api.github.com/users/SoniEx2/repos","events_url":"https://api.github.com/users/SoniEx2/events{/privacy}","received_events_url":"https://api.github.com/users/SoniEx2/received_events","type":"User","site_admin":false},"created_at":"2015-05-02T03:38:21Z","updated_at":"2015-05-02T03:38:21Z","body":"The varargs have the same semantics as a stack, when combined with select() and recursive calls. Combined with coroutines they give you a very simple stack implementation:\r\n\r\n```lua\r\nlocal function Stack(x, v, ...)\r\n  if x == \"push\" then\r\n    local nx, nv = coroutine.yield()\r\n    return Stack(nx, nv, v, ...)\r\n  elseif x == \"pop\" then\r\n    local nx, nv = coroutine.yield((...))\r\n    return Stack(nx, nv, select(2, ...))\r\n  elseif x == \"peek\" then\r\n    local nx, nv = coroutine.yield((...))\r\n    return Stack(nx, nv, ...)\r\n  end\r\n  local nx, nv = coroutine.yield() -- or error()? altho that'd kill the stack, essentially deleting all values\r\n  return Stack(nx, nv, ...)\r\nend\r\n\r\nfunction makestack(...)\r\n  local stack = coroutine.wrap(Stack)\r\n  stack(nil, nil, ...)\r\n  return stack\r\nend\r\n\r\n-- push wish stack(\"push\", v)\r\n-- pop with v = stack(\"pop\")\r\n```\r\n\r\nThe Lua call stack has the same semantics as the Forth return stack, when used like this: https://github.com/SoniEx2/Stuff/blob/master/lua/Forth/Words.lua#L108-L187 (I use the \"data stack\" (varargs) when manipulating it, but properly written code never sees that - the spec only says accessing stuff you didn't push and pushing stuff without popping = undefined (or rather forbidden, but that's basically the same thing))\r\n\r\nIdk, just wanted to talk about how you can (ab)use language features like this..."}}