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
2
u/CharlieJV13 Aug 22 '22
For sure BASIC Anywhere Machine has CONST for constants.
Like I said, that was just "a ridiculous example" to get help from folk to point me to any resources with the vocabulary that matches, and helps me describe, what BASIC Anywhere Machine is capable of.
I think what I've got BASIC Anywhere Machine capable of doing is the same as the "#define" directive in C, and other macro/metaprogramming stuff.
I'm not familiar enough with C to understand the value of these things. But I figure if C has these things, they must have some value in C, and maybe also have some value in BASIC Anywhere Machine.
Still figuring it out.
Back to the example, it isn't much of an advantage to spare the interpreter from the work involved with maintaining a constant. But then, it could give ideas on how to move some of the work to TiddlyWiki (as a preprocessor), and trim down the interpreter. If an extralight interpreter was a goal.