Get the latest tech news
Easy Forth (2015)
by Nick Morgan This small ebook is here to teach you a programming language called Forth. Forth is a language unlike most others.
; : check-apple snake-x-head @ apple-x @ = snake-y-head @ apple-y @ = and if move-apple grow-snake then ; : check-collision ( -- flag ) \ get current x/y position snake-x-head @ snake-y-head @ \ get color at current position convert-x-y graphics + @ \ leave boolean flag on stack 0 = ; : draw-snake length @ 0 do i snake-x @ i snake-y @ draw-black loop length @ snake-x @ length @ snake-y @ draw-white ; : draw-apple apple-x @ apple-y @ draw-black ; : game-loop ( -- ) begin draw-snake draw-apple 100 sleep check-input move-snake-tail move-snake-head check-apple check-collision until ." If the coordinates are the same, we call move-apple to move the apple to a new position and grow-snake to make the snake 1 segment longer. A great resource for learning the full power of Forth is the short book “Starting Forth” by Leo Brodie.
Or read this on Hacker News