Forth programming language

Presentations

Forth programming language

The weirdest language ever?

Beginning of Forth

microFORTH

How the Forth look like?

Data stack

10 20 + .
10 20 * 30 + .
1 2 swap . . cr
1 dup . . cr
1 2 drop . cr
1 2 over . . . cr

Words

: print . cr ;
: square dup * ;

10 square . cr
10 square print

Conditions and loops

condition
if
  commands
then

10 1 do loop

: my-loop
   10 1 do
     i . cr
   loop
;

Variables

1 one !
2 two !

1 1 + two !

: store ! ;

1 one store

one @ . cr
two @ . cr

a @ .
a ? // the same

Interested?

GCD computation

[a=]P?[b=]P?[dSarLa%d0<a]dsax+[GCD:]Pp

Factorial computation

?[q]sQ[d1=Qd1-lFx*]dsFxp

Printing all prime numbers

2p3p[dl!d2+s!%0=@l!l^!<#]s#[s/0ds^]s@[p]s&[ddvs^3s!l#x0<&2+l.x]ds.x