A C#/.NET implementation of the Forthic stack-based concatenative programming language.
Forthic is a stack-based, concatenative language designed for composable transformations. This is the official .NET runtime implementation, providing full compatibility with other Forthic runtimes while leveraging .NET's rich ecosystem and LINQ.
- ✅ Complete Forthic language implementation
- ✅ All 8 standard library modules
- ✅ Attribute-based decorators with reflection
- ✅ LINQ integration for functional operations
- ✅ NodaTime for robust temporal types
- ✅ gRPC support for multi-runtime execution
- ✅ CLI with REPL, script execution, and eval modes
- ✅ Comprehensive xUnit test suite
dotnet add package Forthicusing Forthic;
var interp = new StandardInterpreter();
await interp.RunAsync("[1 2 3] \"2 *\" MAP");
var result = interp.StackPop();
// result is [2, 4, 6]# REPL mode
dotnet forthic repl
# Execute a script
dotnet forthic run script.forthic
# Eval mode (one-liner)
dotnet forthic eval "[1 2 3] LENGTH"# Restore packages
dotnet restore
# Build
dotnet build
# Run tests
dotnet test
# Run specific test
dotnet test --filter "FullyQualifiedName~InterpreterTests"
# Build for release
dotnet build -c Releaseforthic-dotnet/
├── src/
│ ├── Forthic/ # Core library
│ │ ├── Interpreter.cs
│ │ ├── Tokenizer.cs
│ │ ├── Module.cs
│ │ ├── Decorators/ # Attribute system
│ │ └── Modules/Standard/ # Standard library (8 modules)
│ ├── Forthic.Grpc/ # gRPC support
│ └── Forthic.Cli/ # CLI tool
└── tests/
└── Forthic.Tests/ # xUnit tests
- 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 (using NodaTime)
- json: JSON serialization (using System.Text.Json)
Define Forthic words using C# attributes:
public class ArrayModule : DecoratedModule
{
[ForthicWord("( array word -- result )", "Maps a word over an array")]
public async Task<object> MAP(List<object> array, IWord word)
{
var results = new List<object>();
foreach (var item in array)
{
var result = await word.ExecuteAsync(interp);
results.Add(result);
}
return results;
}
}Leverage LINQ for functional operations:
[ForthicWord("( array predicate -- result )", "Filters array")]
public async Task<object> SELECT(List<object> array, IWord predicate)
{
return array.Where(item => {
/* evaluate predicate */
return true;
}).ToList();
}This runtime supports calling words from other Forthic runtimes via gRPC:
// Call a Python word from .NET
var result = await interp.ExecuteRemoteWordAsync(
"python-runtime", "MY-WORD", args
);Robust date/time handling with NodaTime:
var zonedDateTime = ZonedDateTime.FromDateTimeOffset(
DateTimeOffset.Now, DateTimeZone.Utc
);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)
- NuGet Package
- Documentation