r/Basic • • Feb 15 '23

BAM Update: For one dimension arrays: 🆕 Array initialisation 🆕 Constant Arrays

https://basicanywheremachine-news.blogspot.com/2023/02/for-one-dimension-arrays-array.html
3 Upvotes

12 comments sorted by

View all comments

Show parent comment

2

u/CharlieJV13 Feb 15 '23

I suppose we could try some performance tests and evaluate the results.

1

u/zxdunny Feb 15 '23

It would be interesting to see. As I said, the value of consts in SpecBAS are not so much that they can't change - it's that they don't have to be looked up at runtime. SpecBAS has a pre-runtime system that injects const variable values into the bytecode when run, and not having to compare several hundred strings to find the variable in the var space is a huge saving.

That said, I have added var caching so that lookup is only ever done once, but consts are still very much faster as they're a single push rather than an offset/read/push which a variable is in the very best case.

2

u/CharlieJV13 Feb 15 '23

If performance were really bad, then I'd use meta-programming instead of constants.

<$let GREETING="Howdy, buddy.">

PRINT "<<GREETING>>"

</$let>

The preprocessor, before the BASIC programming gets passed to wwwBASIC.js, would replace every occurrence of <<GREETING>> with the literal value.

1

u/zxdunny Feb 15 '23

Sounds like that would be a great way to handle CONST :D

2

u/CharlieJV13 Feb 15 '23

For folk who enjoy the power of TiddlyWiki scripting, and intermingling BASIC code and TiddlyWiki script: oh yeah!

For those who prefer to stick with "pristine" BASIC, suffer the performance of BAM's implementation of constants. If there is anything to suffer.

Being a speed demon will never be in BAM's DNA. (NASA won't be using it in the next Mars mission.) But for the few performance tests I've done, BAM seems to do good enough compared to other interpreters.