Forth überall

Carsten Strotmann, linuxkistchen.de

März 2013

Forth

Forth ist

Demo

SUN/Oracle SPARC Server

One Laptop Per Child OLPC XO-1

Wikireader

FreeBSD

Planungssoftware für Grossprojekte

energieeffiziente Multicore CPU Chips

Funktionsmodellbau

Getränkeautomaten

Raumfahrt

Überwachung :(

Ozeanboden-Seismometer

Tsunami Warnsystem

Forth Netzwerkprotokoll

net2o Beispiel

s” http” protocol s” foo.com” host
  data-window
  command-window
open-port

net2o Beispiel 2

:? expand-preload BEGIN dup list-len >r
dup s” preload” get-attribute-list append
uniquify-list dup list-len r> = UNTIL ;
[[ s” bar/url.wiki” ]] expand-preload
’ send-mime-file map-list

99 bottles of beer

:noname   dup . ." bottles" ;
:noname       ." 1 bottle"  ;
:noname ." no more bottles" ;
create bottles , , ,

: .bottles  dup 2 min cells bottles + @ execute ;
: .beer     .bottles ."  of beer" ;
: .wall     .beer ."  on the wall" ;
: .take     ." Take one down, pass it around" ;
: .verse    .wall cr .beer cr
         1- .take cr .wall cr ;
: verses    begin cr .verse ?dup 0= until ;

99 verses

Demo

Was ist das gute an Forth?

Mini-OOF

\ Mini-OOF 12apr98py
: method ( m v "name" -- m' v ) Create over , swap cell+ swap
  DOES> ( ... o -- ... ) @ over @ + @ execute ;
: var ( m v size "name" -- m v' ) Create over , +
  DOES> ( o -- addr ) @ + ;
: class ( class -- class methods vars ) dup 2@ ;
: end-class ( class methods vars "name" -- )
  Create here >r , dup , 2 cells ?DO ['] noop , 1 cells +LOOP
  cell+ dup cell+ r> rot @ 2 cells /string move ;
: defines ( xt class "name" -- ) ' >body @ + ! ;
: new ( class -- o ) here over @ allot swap over ! ;
: :: ( class "name" -- ) ' >body @ + @ compile, ;
Create object 1 cells , 2 cells ,

Infos