lua-users home
lua-l archive

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


On Wed, May 13, 2020 at 4:22 PM Andrea wrote:
> Now forgive me for asking this, even if I am a programmer I am not a Computer Science Engineer. My question is: why are new scopes created by "if", "for" and other statements and not only by function definitions and do...end statements? If one wanted a new scope one could easily type "do" (as in other languages we just open a curly brace). So why this is done implicitly? What is the advantage or the theoretical reason? Again forgive me for this maybe silly question - remember my background is not in computer science.

If you do not start a scope in a `if` block it means that a `local`
inside it will make something visible after its `end`. Or you have to
forbid the use of `local` in such blocks. Or you have to find some
complex rule to handle such cases.

Overall, the global-by-default + scope at every block is just the most
"Conceptually simple" solution. And I think lua succeeded to give you
a way to handle any issues that can arise from such setup
(metatable+_ENV).
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org