KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
691 stars 229 forks source link

LOCAL vars don't persist in the interpreter #2855

Open Dunbaratu opened 3 years ago

Dunbaratu commented 3 years ago

Declaring a LOCAL variable at the interpreter makes a variable that is local to the line of text, not to the interpeter context itself. This means that this happens:

local foo is "aaa". print foo.
aaa
local bar is "bbb".
print bar.
Undefined variable name 'bar'.

Which makes no sense because a line of text shouldn't be getting treated like it was a local scope context (but it is being treated that way, apparently.)

mgalyean commented 3 years ago

Many environments provide the exact same environment for interactive use as for script consumption not because it is a richer feature but because it is simpler and easier to code and maintain than not. Interactive use becomes the exact same thing as providing the lines of a 'script' one line at at time. Some command to "clear the decks" is typically provided to clean out anything declared, or short of that you just quit the cli and come back in. I could definitely see how kOS with its requisite trigger levels and asynchronous relationship to KSP/Unity could end up with wrinkles that make this model harder though

nuggreat commented 3 years ago

In defense of the way kOS is functioning right now is that by not letting LOCALs persist makes it harder to accidentally mask something important with a local and not realize you did that leading to issues when trying to use kOS in CLI mode

mgalyean commented 3 years ago

That makes a sort of sense. But it is fairly standard when dealing with a 'stale' CLI that its state will be unknown unless you clear it out. On the other hand, if the CLI that remains after a script crashes still has a lot of the declarations in memory it can be a godsend for debugging. A mixed-bag, but there is that silver lining

nuggreat commented 3 years ago

That can still be done if stuff is global other wise the collapse of the script closes it's local scope which would remove any local vars as the terminal and a script are different scopes. And with kOS we get a lot of people new to programing so what is "standard" is completely unknown to them and so there are concessions to that in the language.

mgalyean commented 3 years ago

Well, yes and no. If a crash happens in the middle of a deep nested call in many environments a lot of useful info can be found in the autopsy because the scopes that were open at the time of crash are still there. In fact, a lot of interpreted languages CLIs have a lot of capabilities that are the interpreter version of a debugger for compiled languages