Lurker News
In a popular post today[1] the title claims "VM in Google Sheets", but it's actually in Google Script, which is basically Javascript and not an interesting technical accomplishment (definitely a useful educational tool, though).

Disappointed, I set out to fix it. Voila!
https://docs.google.com/spreadsheets/d/1g3-FZBnkDuLqFYOmk457...
A Brainfk interpreter in pure Google Sheets formulas. The hard part was parentheses matching, so I think other VMs would be even easier.
[1] https://news.ycombinator.com/item?id=14701460

Comments (37) 9 threads

Earlier comments
artursapek1 reply#
This is why I come to HN.
SonOfLilit1 reply#
Wait, did you use to work for Codecademy? Can we chat a while? As a former competitor, I am really curious why you did some stuff this way and not that, and would really like to be able to recommend you to all the people asking me how to learn programming now that I don't actively teach anymore.
sattoshi1 reply#
This probably wasn't why he came to HN..
_ao789#
Lol, truestory
thriftwy1 reply#
Next step is emulating a more fulfilling instruction set using formulas only?
SonOfLilit#
Not sure what you mean by "more fulfilling", but I don't think any new techniques would be required. I encourage you to try! Maybe build a Forth? That would be extremely cool!
kronos292962 replies#
You made my day. Though an explanation would help understanding it. For the commonfolk like me.
SonOfLilit#
I suggest you first try to follow it yourself, maybe copy and play with A1 and see what happens, maybe copy aside parts of the formulas and see what they output.

Then you can read the writeup I wrote in response to another commenter (the guy who wrote the original Apps Script VM).

eatonphil1 reply#
Brainfuck is a stack-based language with only 6-8? syntactic elements for manipulating the stack. + increments the current stack element, - decrements it. > increases the stack pointer and < decreases it. [ and ] have to with conditional jumping I believe. And it is common to convert the elements in the stack to ascii characters to display a result.

So if you go to the orange section of the sheet you see where the program state is displayed. Each row represents the state of the program at that point. The "Out" column is the stack represented as ASCII characters. The "Cursor" column is the stack pointer. The "IP" column is the instruction pointer (which instruction you're currently looking at). The "Instruction" column is the instruction being done at that point in time. The "Cells" column is the stack displayed from left to right.
I may be a little off but that is the general idea.

SonOfLilit1 reply#
You got it basically right, a few small corrections:

Replace the word "stack" with "memory buffer" or "tape" everywhere. "Out" represents STDOUT, there is the "." command for printing (and "," for reading from STDIN).
Thanks!

eatonphil2 replies#
Ah. I thought "." must be printing (as it's something similar to that in Forth [guess it's ".s" though not "."]), but I was confused by the comma because I didn't understand how you'd be reading from stdin here. Actually I'm still confused. What are you reading in?

Continue this thread — 2 replies

Load more comments