Slap: Functional Concatenative Language with a Borrow Checker?
8 hours ago
- #systems-programming
- #functional-programming
- #programming-language
- Slap is a functional concatenative programming language with features like tacit programming, a strong linear type system, manual memory management, and managed effects.
- It is designed to be terse, safe, fast, small, and easy to use, combining elements from languages like APL, Rust, Lisp, C, Elm, and Forth.
- The language uses postfix syntax and stack-based operations, with optional glyphs for a more concise style, and supports both tacit and explicit coding patterns.
- Safety is enforced through parametric types to prevent data mismatches and linear types (similar to Rust's borrow checker) to manage memory, preventing issues like double-free or use-after-free.
- Linear types require explicit actions for pointers (boxes), such as lending, mutating, cloning, or freeing, ensuring memory safety and resource management.
- Slap's stacks are flexible, acting as tuples, closures, or functions, with automatic type inference and optional stack effect annotations for clarity.
- Performance is achieved without garbage collection, relying on stack allocation and manual heap management via boxes, with fast execution demonstrated on Project Euler problems.
- The implementation is compact, with a core codebase of around 2,000 lines of C99, and includes features for graphics and system interaction via managed effects.
- Examples include building games like Game of Life, Dots, and Snake, using a simple canvas and event handlers for interactive applications.
- Slap supports cross-compilation for native and web environments, with a low-fi aesthetic inspired by Uxn, and encourages exploration through provided examples.