r/Basic • u/CharlieJV13 • Aug 21 '22
BASIC and support for "metaprogramming"
Here's a a ridiculous example of something we can do in BASIC Anywhere Machine, and I wonder if this is something unique to BASIC Anywhere Machine or if it is something that can be done in any other BASIC dialects:

BASIC Anywhere Machine's interpreter currently knows nothing about PI.
In a "traditional" approach, we could define a constant for PI and use that constant throughout the program.
Here, I've instead embedded some TiddlyWiki syntax in the BASIC program, which TiddlyWiki processes (preprocessing phase?) just before passing the BASIC program to the interpreter.
During pre-processing, every occurence of <<pi>> will get replace by the literal value assigned to "pi" via the TiddlyWiki "$let" widget.
(In the image above, We see how the source gets manipulated by TiddlyWiki.)
I'm thinking this is pretty cool, kind of injecting an interesting twist to an old programming language. (Well, I'm not sure about the "readability" of the program for we human folk.)
I'm trying to cobble together some documentation for this. If you know of any good online references where I can find the right "lingo" for what I've shown here, please let me know.
Cheers !
View all comments
Show parent comment
1
u/zxdunny Aug 22 '22
I think you underestimate the value of CONST in an interpreted environment ;)
It can indeed save a huge amount of CPU time in a tight loop, not having to locate and query the value of a variable. Yours is indeed much more powerful; you can define blocks of code that equate to a symbol which is expanded when run - SpecBAS can't do that (unless you EXECUTE with a string const... hrmmmm interesting).
Macros are awesome. I wish all languages had them.