Crates.io | lazyk-rust |
lib.rs | lazyk-rust |
version | 0.1.0 |
source | src |
created_at | 2023-02-27 05:31:46.121486 |
updated_at | 2023-02-27 05:31:46.121486 |
description | Interpreter for Lazy K programming language |
homepage | https://github.com/fedimser/LazyK-rust |
repository | https://github.com/fedimser/LazyK-rust |
max_upload_size | |
id | 795733 |
size | 89,043 |
Interpreter for Lazy K programming language, written in Rust.
Lazy K is an esoteric pure functional programming language designed by Ben Rudiak-Gould, based on the SKI combinator calculus.
To get the binary, clone this repository and run cargo build
.
The following command runs Lazy program from given source file, reading from the standard input and writing to the standard output:
lazyk-rust <path_to_source>
The following command runs Lazy program from given inline source, reading from the standard input and writing to the standard output:
lazyk-rust -e <source>
For example, lazyk-rust -e I
runs the identity function, it copies input to output (until EOF is reached).
See specification below for details on how I/O works.
Use the LazyKProgram
class. For example:
use lazyk_rust::LazyKProgram;
let source = "I";
let mut program = LazyKProgram::compile(source).unwrap();
assert_eq!(program.run_string("abcd").unwrap(), "abcd");
For more details, see tests and LazyKProgram
class documentation.
This interpreter fully implements the specification. It's also fully safe (it doesn't use unsafe Rust).
It uses generally the same approach as in the reference implementation (lazy_orig.cpp
), where all transformations are done in-place to avoid duplicating subtrees.
The reference imnplementation uses pointers and manual reference counting. Pointers in Rust are unsafe, so this implementation keeps all expressions in a vector which serves as an expression pool, and uses integer indices instead of pointers.
Instead of reference counting, this implementation uses garbage collection. Every now and then it finds all unreachable expressions and replaces them with special "Free" value.