An Erlang/OTP implementation of the Forthic stack-based concatenative programming language.
Forthic is a stack-based, concatenative language designed for composable transformations. This is the official Erlang runtime implementation, providing full compatibility with other Forthic runtimes and leveraging the power of OTP for distributed computing.
- ✅ Complete Forthic language implementation
- ✅ All 8 standard library modules
- ✅ OTP behaviors (gen_server, supervisor)
- ✅ gRPC support for multi-runtime execution
- ✅ Hot code reloading
- ✅ Distributed erlang integration
- ✅ Escript CLI tool
- ✅ Comprehensive EUnit test suite
rebar3 compile%% Start the application
application:start(forthic).
%% Create an interpreter
{ok, Interp} = forthic_interpreter:new().
%% Run Forthic code
{ok, Result} = forthic_interpreter:run(Interp, "[1 2 3] \"2 *\" MAP").
%% Get result from stack
Value = forthic_interpreter:stack_pop(Interp).
%% Value = [2, 4, 6]# REPL mode
./forthic repl
# Execute a script
./forthic run script.forthic
# Eval mode (one-liner)
./forthic eval "[1 2 3] LENGTH"# Compile
rebar3 compile
# Run tests
rebar3 eunit
# Run specific test
rebar3 eunit --module=forthic_interpreter_test
# Run with property-based testing
rebar3 proper
# Start shell with application loaded
rebar3 shellforthic-erl/
├── src/
│ ├── forthic.app.src # OTP application
│ ├── forthic_app.erl # Application behavior
│ ├── forthic_sup.erl # Supervisor
│ ├── forthic_interpreter.erl # Core interpreter
│ ├── forthic_tokenizer.erl # Lexical analysis
│ ├── forthic_module.erl # Module system
│ └── modules/standard/ # Standard library (8 modules)
├── test/ # EUnit tests
└── priv/ # Resources
- core: Stack operations, variables, control flow
- array: Data transformation (MAP, SELECT, SORT, etc.)
- record: Dictionary operations
- string: Text processing
- math: Arithmetic operations
- boolean: Logical operations
- datetime: Date/time manipulation
- json: JSON serialization (using jsx)
The Forthic runtime is a proper OTP application with supervision:
%% Supervised interpreter process
{ok, Pid} = forthic_interpreter:start_link().
%% Execute in process
gen_server:call(Pid, {run, "[1 2 3] REVERSE"}).Leverage distributed erlang for multi-node Forthic execution:
%% Execute on remote node
rpc:call('node@host', forthic_interpreter, run, [Interp, Code]).This runtime supports calling words from other Forthic runtimes via gRPC:
%% Call a Java word from Erlang
{ok, Result} = forthic_grpc_client:execute_word(
"java-runtime", "MY-WORD", Args
).BSD 2-CLAUSE
- forthix.com - Learn about Forthic and Categorical Coding
- Category Theory for Coders - Understand the foundations
- Forthic Language Specification
- TypeScript Runtime (reference implementation)
- Documentation