
1991 – a server-side web framework written in Forth - ChrisArchitect
http://www.1-9-9-1.com/
======
nickcw
That is a masterpiece of Forth programming!

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!

~~~
james_s_tayler
I like the (maybe a bad idea?) comment.

~~~
GrumpyNl
Its the only distracting comment, the rest tels me what it does, this one
tells me how he feels.

~~~
macintux
Documenting potential security issues with your code is rarely a bad idea.

------
gmfawcett
This is charming. A microframework in a scant 480 lines of code, plus a
postmodern manifesto on historisity -- what's not to love!

I can't wait to read the slew of "Why we switched from <web-framework> to
1991" blog posts.

~~~
giancarlostoro
Maybe migrating from bashttpd:

[https://github.com/avleen/bashttpd](https://github.com/avleen/bashttpd)

~~~
nudpiedo
I can see that happening: "the deployment was a piece of cake".

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"

~~~
qbaqbaqba
Do you know what runs HN?

------
fouc
> Hence developers working on new projects while still coding in decades-old
> text editors. They write the future in the past and are made present in so
> doing.

Deep

~~~
hestefisk
Postmodern. Just like Perl.

------
stevejohnson
I really like the commitment to retro aesthetics. Last weekend I made an
"imaginary astronomy" web app with nearly pixel-perfect Windows 95 theming.
:-) [http://steveasleep.com/keplverse/](http://steveasleep.com/keplverse/)

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?

~~~
int_19h
That's a nice one, but why not use MS Sans Serif as a font where available,
for maximum effect?

~~~
stevejohnson
Because I'm on a Mac and wouldn't be able to test it. :-D

Patches accepted here:
[https://github.com/irskep/keplverse](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...](https://blog.steveasleep.com/using-data-from-the-kepler-mission-to-
scientifically-imagine-star-systems)

------
jdmoreira
Besides the framework itself the website is glorious. Kudos!

------
ithkuil
Cool. Any decent implementation for client side forth in the browser so I can
do some good old Asynchronous Forth And staX?

~~~
stefano
I wrote a Forth interpreter for WASM some time ago:
[https://github.com/stefano/wasm-forth](https://github.com/stefano/wasm-forth)

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.

------
pmarreck
Forth must be lightning fast albeit single-threaded... has there been any work
on a multithreaded Forth? Compiling to BEAM VM might be an option for (not
fast) implementation...

~~~
rwmj
A naive (ie. threaded[1]) Forth implementation will be slow because the jump
between each instruction is a very effective way to defeat branch prediction.
Of course this doesn't apply to "real Forth" which is compiled into machine
code or even less naive Forths which can do inlining, but there are many
hobbyist Forth implementations (because they're so easy to write) where this
will still be true.

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.S)
[http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth...](http://git.annexia.org/?p=jonesforth.git;a=blob;f=jonesforth.f)

[1] "Threaded" in this sense means
[https://en.wikipedia.org/wiki/Threaded_code](https://en.wikipedia.org/wiki/Threaded_code)
not multithreading.

~~~
gmfawcett
I've always meant to thank you for publishing jonesforth. I learned so much
from it. (I can't believe it's been nearly ten years now!)

It's a beautiful example of literate programming. Knuth would be proud, I
think!

------
lichenwarp
And I thought I was horrible at choosing domain names lol

~~~
andrelaszlo
It would have been cool to serve this from the raw ip like
[https://1.9.9.1](https://1.9.9.1) :P It's actually responding to pings, seems
to be in Malaysia.

------
vvpan
1991 - the year punk broke.

------
quickthrower2
Nice. I wonder what the threading model is? Process per request? Thread per
request? NodeJS style?

~~~
RodgerTheGreat
One process, one HTTP request at a time, buffering excess requests in a queue
of up to 255 requests. Here's the main "event loop":

    
    
        : 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.

------
oneplane
Why hasn't someone made a Go and Forth combination yet?

~~~
fouc
What makes you think Go and Forth go well together?

~~~
kstrauser
Everyone knows you Go Forth and multiply.

~~~
MaxBarraclough
Strictly speaking, you're meant to GO FORTH AND MULTIPLY.

~~~
stefano
MULTIPLY FORTH GO AND

~~~
lonk
GORTH!

------
jholloway7
Can this recreate trying to figure out a way to host a web server in 1991?

------
numbers
Love the note at the end, rings true with me.

------
kstrauser
That's beautiful. Well done!

------
mempko
I love postmodern software

~~~
hestefisk
To stay true to this claim it should’ve been written in Perl.

~~~
brlewis
Even people who love Perl don't love 1991 Perl.

------
justaaron
cool!

