Crates.io | tulisp |
lib.rs | tulisp |
version | 0.17.0 |
source | src |
created_at | 2022-10-02 01:26:07.979884 |
updated_at | 2024-02-25 16:57:27.553952 |
description | An embeddable lisp interpreter. |
homepage | |
repository | https://github.com/shsms/tulisp |
max_upload_size | |
id | 678106 |
size | 255,758 |
Tulisp is a Lisp interpreter that can be embedded into Rust programs. The syntax tries to closely match that of Emacs Lisp. It was primarily designed to be a configuration language, but it also works well as a general purpose embedded scripting language.
One of the many benefits of using the Emacs Lisp syntax is that we can reuse its documentation for the builtin functions and macros. And for people who are already familiar with Emacs Lisp, there's no need to learn an extra language.
Tulisp requires rustc
version 1.70 or higher.
It is very easy to get started. Here's an example:
use tulisp::{TulispContext, tulisp_fn, Error};
fn main() -> Result<(), Error> {
// Create a new Tulisp execution context.
let mut ctx = TulispContext::new();
// Add a function called `add_nums` to `ctx`.
#[tulisp_fn(add_func = "ctx")]
fn add_nums(num1: i64, num2: i64) -> i64 {
num1 + num2
}
// Write a lisp program that calls `add_nums`
let program = "(add_nums 10 20)";
// Evaluate the program, and save the result.
let sum: i64 = ctx.eval_string(program)?.try_into()?;
assert_eq!(sum, 30);
Ok(())
}
defun
s, defmacro
s and lambda
sintern
to find/create symbols dynamically`(answer . ,(+ 2 3))
)thread-first
and thread-last
)Tulisp has a light-weight tree-walking interpreter with very low startup times and sufficient speed for many config/simulation needs.
A list of currently available builtin functions can be found here.