oforth.com - Oforth Programming Language

What is Oforth ?

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

Oforth is a Forth dialect (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

Binary installation :

  • 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 or read manual.

Build Oforth :
  • Oforth is open source : you can download the sources and build a binary (see Oforth manual).
  • Then you can change the binary provided by one of the releases.

07/05/2018 : Oforth V1.1 is released

Oforth V1.1 supports Mac OS systems

Some changes and fixes (see change log for more information)

- Franck -

25/03/2018 : Oforth V1.0 is released

At last, Oforth V1.0 is now released.

Oforth sources are now available for download : you can now build Oforth (with various options).

Oforth V1.0 comes with lots of changes. See change log for more information.

- 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 ;



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
;