KSP-KOS / KOS

Fully programmable autopilot mod for KSP. Originally By Nivekk
Other
698 stars 230 forks source link

Make Lexicons iterable #1480

Open tomekpiotrowski opened 8 years ago

tomekpiotrowski commented 8 years ago

We could introduce a new structure - ENTRY (that would have 2 suffixes: KEY and VALUE) and make Lexicon enumerable with every iteration returning an instance of ENTRY.

gisikw commented 8 years ago

Would it be possible to handle implicit destructuring? Having to call cursor:key and cursor:value doesn't seem to add much benefit compared to simply iterating on lex:keys.

But if we could have for key, value in lex { }, that'd be huge.

Dunbaratu commented 8 years ago

for argslist in expression Would be a parser and compiler change. It's definitely doable though. What it requires though, to be a properly generic language construct and not just hardcoded to work only with lexicon, is a means for a Structure like lexicon to specify "these are my suffixes to use by default in an arglist context" (and who knows, maybe even a way for the user to change that in a script with syntax something like: for n, bod, ap in myListOfVessels suffixes "name", "body", "apoapsis" { } ) And then that might even open up constructs like : set n, bod, ap to myListOfVessels suffixes "name", "body", "apopasis". or myFunc:call( myListOfVessels suffixes "name", "body", "apoapsis" ).