←back to thread

226 points JoeDaDude | 2 comments | | HN request time: 0.411s | source
Show context
tombert ◴[] No.42207795[source]
Forth has been something I've wanted to learn for years now. It seems weird to me that for most stuff in old computers, you have the option of "assembly" if you want your program to be fast, and "BASIC" if you want your program to be slow, but Forth lingers along as the "medium speed" language, despite at least looking pretty high-level.
replies(7): >>42207863 #>>42207931 #>>42208026 #>>42209557 #>>42210559 #>>42213720 #>>42213966 #
zabzonk ◴[] No.42208026[source]
Very fast (faster than naive assembler) but not at all high-level; having to look after the stack is a bit of a pain. Writing your own FORTH is fun - it doesn't need to be in assembler - I once wrote a FORTH-like scripting language in C++.
replies(3): >>42208089 #>>42212501 #>>42215623 #
1. MaxBarraclough ◴[] No.42215623[source]
> Very fast (faster than naive assembler)

Every Forth that uses conventional threaded-code interpretation pays a considerable performance penalty, execution times are likely to be very roughly quadruple the equivalent assembly. [0]

Forth's runtime performance can be competitive with C if 'proper' compilation is performed, though. [1]

[0] https://benhoyt.com/writings/count-words/

[1] (.fth file with their results in comments) http://www.mpeforth.com/arena/benchmrk.fth

replies(1): >>42217250 #
2. PittleyDunkin ◴[] No.42217250[source]
This is true. It's not terribly difficult to bootstrap an (inlining) compiler from a threaded interpreter, though, including eliding a lot of stack operations.

I'm curious if anyone has tried using futamura projections to do this in stages. I hadn't known about them when I last built a forth and it may yield more satisfying, incremental results than the last time.