What is Oforth ?

Oforth is an imperative, dynamic typed, stack-based language.

Oforth is for Object + Forth : it keeps Forth mecanisms while implementing a full object model.

Oforth has been designed to provide :

  • A dynamic, fast, concise language.
  • An object oriented programming support and object metamodel (classes, methods, ...)
  • Automatic garbage collection with an incremental mark and sweep garbage collector.
  • Althought imperative, support of functional programming features (and closures using blocks).
  • Support for parallelism using light-weight tasks and communication between tasks using channels.

Getting started

  • Download oforth release corresponding to your platform here
  • Oforth release is an archive with an oforth directory. Copy this directory at a location of your choice.
  • Set OFORTH_PATH environnement variable value to this directory (see INSTALL.TXT file for details).
  • Launch oforth interpreter using oforth --i command line : you are ready to begin tutorials here

20/12/2016 : Oforth V0.9.26 released

One more release is needed before Oforth V1.0

Changes are mainly internal.

Now outer intepreter is almost fully written in Oforth. If interested, you can see asm.of and prelude.of files.

- Franck -

24/09/2016 : Oforth V0.9.25 released

This is the last version before Oforth V1.0

First version of Oforth manual is now available. (see documentation).

This version stabilizes the language in order to prepare Oforth V1.0.

Warning : some features are no more compatible with previous versions (see change log).

- Franck -

Some examples (from tutorials).

You can find lots of examples here

Factorial (imperative)

: fact( n -- n1 )
| i | 1 n loop: i [ i * ] ;

or (recursive)

: fact( n -- n1 )
 n ifZero: [ 1 ] else: [ n dup 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 .
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
   #[ pong(n, ch1, ch2) ] &
   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" . ])
   e emit($foo)
   e onEventParallel($foo, #[ "bar" . ])
   e emit($foo)
   e close ;