[Sharing] [gen~] Absurd Friday: interpeter-calculator in gen~

Graham Wakefield's icon

Today’s absurd contribution is an interpreter in gen~.

Roughly based on the style of early digital calculators, and the language Forth. Yes, I mean you can send a message “3 4 +” to the gen~ (via atoi and Timo’s great idea of using click~), and the gen~ outputs 7; or send "1 2 3 + *" or "1 2 + 3 *" and get 9.

Why on earth would this ever be useful? Well, apart from the learning exercise of seeing how relatively simple a basic interpreter can be, it also opens up the path for doing things like parsing serial byte streams encoded in signals (which, for example, could include parsing MIDI byte streams), as well as interpreting structural things for generative grammars, fractal-types of recursive schedulers, and so forth. (Ha.)

Do something amazing with it if you can!

Max Patch
Copy patch and select New From Clipboard in Max.

Jean-Francois Charles's icon

Beautiful! Love that you are also keeping the most recent result in memory, so you can give a simple '3 +' instruction. Reminds me of the HP-48...

Graham Wakefield's icon

It's the beauty of concatenative languages. They have some really amazing properties in fact -- for example, you can pretty much cut them anywhere and join them up again, and they will likely still run.

OK, yes you might run out of stack, but you could make it even more robust by treating the stack as a ringbuffer, so it never runs out of data (simply use boundmode="wrap" on all peeks & pokes).

But the syntax is almost always valid. Every sentence is a sentence, even if what it says is kind of nonsense. I imagine that would be a really interesting space for doing evolutionary programming.