Oforth Documentation

I - Reference

  • Oforth manual (V0.9.26) : here
  • Memory management and garbage collector : here

II - Tutorials

  • Oforth basics : here
  • Oforth syntax : here
  • Writing Oforth programs : here
  • Packages and namespaces : here
  • Oforth classes : here
  • Oforth parallelism : here
  • Oforth node : Work in progress...

Some examples (from tutorials).

You can find lots of examples here

Factorial

: fact( n -- n1 )
   n ifZero: [ 1 ] else: [ n n 1- fact * ] ;



Fibonacci sequence

: fib( n -- n1 )
   0 1 n #[ tuck + ] times drop ;



Sum of square roots of all even integers between 1 and 10000

seq(10000) filter(#isEven) map(#sqrt) sum println 333383.040171148



A ping pong between 2 tasks running concurrently and using channels to communicate

: pong(n ch1 ch2 -- )
   | i | n loop: i [ ch1 receive ch2 send drop ] ;

: pingpong( n -- )
| ch1 ch2 i |

   Channel new ->ch1
   Channel new ->ch2
   #[ n ch1 ch2 pong ] &
   n loop: i [ i ch1 send drop ch2 receive . ] ;



An emitter that launches event listeners into parallel tasks running concurrently

: myemitter
| e |
   Emitter new(null) ->e
   e onEventParallel($foo, #[ "foo" println ])
   e emit($foo)
   e onEventParallel($foo, #[ "bar" println ])
   e emit($foo)
   e close ;