TLDR: Used Sonnet 3.5 to explore Forth, and it was amazing..

Taking a break from pytorch, I spent the weekend learning Forth.

Stack languages incited confusion and fear in me, but now.. I have Sonnet 3.5 haha!

The prompt was simple "i want to learn forth, i understand the basic stack ops, but teach me more, loops and words and more complicated things" and so it started.. loops, allot, cells, return stack, custom types, recursion etc.

I just kept asking it, every word, every symbol that confused me, asking about the same thing from different angles, from writing a tiny interpreter to 'macro expanding', breaking down expressions and rewriting them in various ways.

I set 1 hour intervals, and don't do anything else besides switching between emacs and sonnet, blasting Cyberpunk 2077 Radio, and playing in gforth, 5 minutes break, and then go again.

Now I can make tic-tac-toe :)

I understand now why http://collapseos.org/ is a Forth operating system, the language allows for such sophisticated constructs, and yet it is so small and elegant, I regret not diving into it earlier.

What kind of teacher would the Opus 3.5 be? or GPT5?

I CAN'T WAIT!

I think it is important to learn different languages, like LISP vs C vs Forth, it is amazing when a language twists your point of view, makes you question everything, and see the world differently, inspire new ideas and have new thoughts.

Just like subject-object-verb (japanese - cows grass eat) vs subject-verb-object (english - cows eat grass), or object-subject-verb (warao - grass cows eat), each forces you to think differently.

I wish they thought some SOV or SVO languages daughter's school, instead of 4 SVO languages, dutch, german, english and french, though.. 96 quatre-vingt-seize (4*20+16) is quite funny.

There is nothing stopping you now, open Sonnet and just start typing.



tic-tac-toe:
create board 9 allot
: board[] board + ;

: reset-board ( -- )
  9 0 do
    '-' i board[] c!
  loop
;

: print ( -- )
  3 0 do   \ j
    3 0 do \ i
      j 3 * i + board[] c@ emit
    loop
    cr
  loop
;

: check-line ( a b c -- flag )
  board[] c@ rot board[] c@ rot board[] c@
  dup '-' = if
    drop drop drop 0
  else
    over    \ a b c -> a b c b
    =       \ a b c==b
    rot rot \ c==b a b
    =       \ c==b a==b
    and     \ c==b && a==b
  then
;
: check-win (  -- )
  0 1 2 check-line if 1 exit then
  3 4 5 check-line if 1 exit then
  6 7 8 check-line if 1 exit then
  0 3 6 check-line if 1 exit then
  1 4 7 check-line if 1 exit then
  2 5 8 check-line if 1 exit then
  0 4 8 check-line if 1 exit then
  2 4 6 check-line if 1 exit then
  0
;

: play ( -- )
  'X' 'O'
  begin
    over emit ." 's turn" cr
    print
    over key '0' - board[] c!
    swap
    1 check-win = if
        print cr emit ."  wins" cr
        exit
    then
  again
;

reset-board play bye
      

hangman:
create w 50 allot
create g 50 allot
s" hello" w place
: d ." Stack: " .s cr ;

: print ( addr -- )
  dup c@ 0 do
    dup 1+ i + c@ emit
  loop
  drop
;

: setup ( -- )
  w g w c@ move
  g 1+ w c@ '-' fill
;

: play
  10 \ lives
  begin

    g print cr
    dup . ." lives left, guess a character: " 
    key cr
    false
    w c@ 0 do
      over w 1+ i + c@ = if
        w 1+ i + c@ g 1+ i + c!
        drop true
      then
    loop
    nip
    0 = if
      1 -
      dup 0 = if
        ." you lose " cr exit
      then
    then
    w 1+ w c@ g 1+ w c@ compare 0 = if
      ." you win " cr exit
    then
  again
;

setup play bye