1991 – a server-side web framework written in Forth
1-9-9-1.com
1-9-9-1.com
I particularly enjoyed this section from the template renderer which made me think... Return stack manipulation - that's playing with fire. And also - wow Forth is not much higher level than assembly, and gosh, I don't think I could have written that without writing some stack diagrams!
2dup s" $>" search if \ Check to see if there's a closing tag $>.
2 - \ Add the close tag to the search result.
nip \ Save the end position of $>.
dup >r
- \ Reduce the string to <$ ... $>.
evaluate \ Run user's code (maybe a bad idea?).
r> \ Retrieve our saved end position of $>.
r> r> \ Retrive the addr u from start of loop iter.
rot \ Bring end $> to stack top.
over >r \ Store the real string's length.
- \ Subtract end $> from u to get the pos from top
r> swap \ that we'd like to strip away. Restore saved u.
/string \ Drop top of the string until the end of $>.
0 \ Keep looping.
Thanks for the trip down memory lane!Usually I'm more tense about code that uses rot/-rot; a little harder to keep track of in my head.
I can't wait to read the slew of "Why we switched from <web-framework> to 1991" blog posts.
What says the project about security? "Only rudimentary input handling. We would not be running this on a public machine."
What will the hipsters say? "time to market"
https://www.shodan.io/search?query=http+200+server+slash+bin...
Deep
Forth still seems like a language worth learning, not for practical reasons, but for technohistorical context. Maybe my first project should be a sqlite library?
Patches accepted here: https://github.com/irskep/keplverse
I also blogged about the algorithm, if that's of interest: https://blog.steveasleep.com/using-data-from-the-kepler-miss...
It's not production ready and it's missing a good JS interface, but you can use it to run Forth code in the browser with a basic console interface.
If you're interested I wrote a naive literate Forth implementation which can do inlining: http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth... http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth...
[1] "Threaded" in this sense means https://en.wikipedia.org/wiki/Threaded_code not multithreading.
It's a beautiful example of literate programming. Knuth would be proud, I think!
Also of interest - Chuck Moore's* current work is on such a parallel architecture ASIC that uses FORTH: http://www.greenarraychips.com/
*Chuck Moore is the creator of FORTH
However, it was Go pre-1.0, so it won't work now. For a while, it was maintained by Charles Childers - the original retroForth author - but I do not think the Go version is still available.
If you want to give it a try (making it work with the latest Go version shouldn't be difficult), have a look at:
: start-server { server client }
begin
server 255 listen
server accept-socket to client
client read-request prepare-response client send-response
again ;
I think this word's definition should be fairly easy to follow even if you aren't familiar with Forth.As I said in another comment, it won't work now because Go had not yet reached 1.0 at that time, but it should be easy to get it working again.
https://github.com/boomlinde/acidforth
I think entirely procedural languages are a nice fit for this domain since they make order of operations apparent. Going for something Forth-like was obvious, since it's terse, trivial to implement and makes factoring easy.
That said, I think the documentation of this project is a bit out of date, that the overall architecture is flawed and that stack juggling can be a bit distracting when working with more complex algorithms. I intend to rewrite it some day.
I have a couple of forth-implementations in golang bookmarked. As a quick example take this one:
$ go get github.com/unixdj/forego
$ echo '3 4 + dup * . ' | forego 2>/dev/null
49 okSounds like it isn't that good if it took them four tries.