Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : BASIC stack
Author | Message | ||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
You know, I've often wondered why BASIC didn't have any user accessible stack. Commands like: PUSH(var1, var2,...) POP(var1, var2,...) could be invaluable. The BASIC interpreter which came with the Microbee computer (Microworld basic) had the ability to add variables to the GOSUB command: GOSUB (var1, var2,...) line_number then the command VAR was used to retrieve the variables: VAR (var1, var2,...) Possibly a stack could be implemented in BASIC; hmm, thinking cap on.... Thoughts? Regards, Bob Devries Dalby, QLD, Australia |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3210 |
I was planning user defined functions and subroutines. For example: 100 FUNCTION MyFun(var1, var2) 200 MyFun = var1 + var2 300 RETURN You could then us it in your program: 10 x = MyFun(3, 6) And x should contain 9. Also a similar thing for subroutines (except they do not return a value). I am about half way there on this one. Is it what you were looking for? Geoff Geoff Graham - http://geoffg.net |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
Geoff: Does adding more and more commands and functions have a penalty in code execution of the BASIC interpreter? With so many suggestions coming in, are we redefining the BASIC into a convoluted language? |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3210 |
No, it does not affect the speed or any other aspect (memory usage, etc). This is because the interpreter turns each keyword into a single byte token when the program is loaded. When the program runs the interpreter just uses the value of the token to index to the C code for that particular keyword - this is economical with memory, very fast and allows many keywords without affecting speed. This is also why the interpreter lists keywords in upper case, it is expanding the keyword back to ordinary text. Yes, this is a worry. User defined functions are part of the ANSI standard for BASIC so I am not inventing anything new with them but other features (such as PIN() and SETPIN) are new and only make it harder for someone to transfer his/her experience to the Maximite. For this reason I try to resist adding something that is not in Microsoft BASIC or the ANSI standard. A good example is implementing a stack in BASIC, that runs against how the language works and is not part of a standard. However, if the requirement is important enough, there is often no other choice other than inventing something new. Geoff Geoff Graham - http://geoffg.net |
||||
Nick Guru Joined: 09/06/2011 Location: AustraliaPosts: 512 |
I guess we should be looking at commands that actually give the MM new functions and features. There are quite a few suggestions being made that are just for convenience that basically just take what can be achieved with 2 or 3 commands into 1. Or a duplication such as the PSET and PIXEL. |
||||
Print this page |