Crate blisp[−][src]
BLisp
BLisp is a well typed Lisp like programming language which adopts effect system for no_std environments. BLisp supports higher order RPCs like higher order functions of functional programing languages.
This repository provides only a library crate. Please see blisp-repl to use BLisp, or baremetalisp which is a toy OS.
Homepage is here.
Examples
Simple Eval
let code = " (export factorial (n) (Pure (-> (Int) Int)) (factorial' n 1)) (defun factorial' (n total) (Pure (-> (Int Int) Int)) (if (<= n 0) total (factorial' (- n 1) (* n total))))"; let exprs = blisp::init(code).unwrap(); let ctx = blisp::typing(&exprs).unwrap(); let expr = "(factorial 10)"; for result in blisp::eval(expr, &ctx).unwrap() { println!("{}", result.unwrap()); }
Foreign Function Interface
use blisp; use num_bigint::BigInt; let expr = " (export callback (x y z) (IO (-> (Int Int Int) (Option Int))) (call-rust x y z))"; let exprs = blisp::init(expr).unwrap(); let mut ctx = blisp::typing(&exprs).unwrap(); let fun = |x: &BigInt, y: &BigInt, z: &BigInt| { let n = x * y * z; println!("n = {}", n); Some(n) }; ctx.set_callback(Box::new(fun)); let e = "(callback 100 2000 30000)"; blisp::eval(e, &ctx);
Features
- Algebraic data type
- Generics
- Hindley–Milner based type inference
- Effect system to separate side effects from pure functions
- Big integer
- Supporting no_std environments
Modules
parser | |
runtime | |
semantics |
Structs
LispErr | error message |
Pos | indicate a position of file |
Functions
eval | evaluate an expression |
init | initialize BLisp with code |
typing | perform type checking and inference |