Lone lisp program examples
Lone Lisp is a standalone, zero-dependency Lisp dialect specifically designed for Linux systems programming. It focuses on "Linux maximalism," allowing programmers to interact directly with Linux system calls like sendfile or signalfd with high performance and minimal overhead.Below are practical program examples and features of the Lone Lisp language.
1. Simple Environment
Printer
The env utility is a classic example of Lone's ability to interface with the Linux environment.
lisp(import (lone print) (linux environment))
(print environment)
Use code with caution.
Result: This prints a table of your current environment
variables.Self-Contained Binary: Using the lone-embed tool, you can package this script directly into the interpreter to create a single, portable executable file.
2. Data Structure as Application
Lone allows data structures like hash tables and vectors to be "applied" like functions, similar to Clojure.
lisp(import (lone quote print set))
(set point { x 10 y 20 })
(print (point 'x)) ;; Returns: 10 (point 'z 30) ;; Sets point['z'] to 30 (print (point 'z)) ;; Returns: 30 (print point) ;; Returns: { x 10 y 20 z 30 }
Use code with caution.
3. Delimited Continuations
Lone implements powerful control flow through delimited continuations, which allow programmers to implement features like generators or coroutines.
- Core Logic: Unlike many Lisps that implement if as a special case in the evaluator, Lone implements it as a FEXPR within an intrinsic module, keeping the core engine minimal.
Key and Technical Features
Standalone Linux Applications: Programs can be compiled into zero-dependency ELF binaries that carry no external library requirements.
Direct System Calls: The system call primitive allows any Linux system call to be issued by number, returning -ENOSYS if unsupported rather than crashing.
Minimalist Core: The evaluator focuses on self-evaluating values (numbers, booleans) and function application, with complex logic moved to modules.
Freestanding C Integration: The build system is designed so that the main function can be replaced with freestanding C for low-level testing and tool creation.