top | item 42533260

(no title)

romforth | 1 year ago

I have ported Forth to a dozen small microcontrollers and my experience writing much of the bootstrap code in Forth tells me that you are better off coding Forth in a "vertical" style (ie one word per line with stack picture comments), rather than the terse "horizontal" code of "everything on one line" that many of the folks using Forth (including @yosefk, the author) seem to prefer.

Given how close Forth is to assembly (seen from an implementer's point of view) it makes sense to write Forth in a "vertical" style which reflects the "vertical" style in which assembly code is written. This has the advantage that the "stack picture comments" on each line of code can stand in for Hoare triplets so that the code and its - I'll call it - "proof" can be written hand in hand at the same time.

This is how all of the Forth code that I've written in https://github.com/romforth/romforth is structured.

It does make the code appear less compact though so you are not going to win any code golf prizes.

discuss

order

Lerc|1 year ago

Is there any editor/IDE support for stack state visualisation?

A text display with an auto pretty printed view would serve people who like both code styles well.

A newline per stack reducing operation with the next line indented by stack depth would make it close to your style and could be quite automatic.

romforth|1 year ago

Something like an automated proof assistant to help annotate the stack while coding would be awesome, but I'm not aware of any.

These might be famous last words, but if switching between compile/interpret modes is ignored, I think it shouldn't be too hard to implement it though.

volemo|1 year ago

We removed explicit arguments from the language so you can write comments with arguments after every function call. :D