Expand description
§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.
§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
§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, vec![]).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::{self, embedded};
use num_bigint::BigInt;
#[embedded]
fn add_four_ints(a: BigInt, b: (BigInt, BigInt), c: Option<BigInt>) -> Result<BigInt, String> {
let mut result = a + b.0 + b.1;
if let Some(n) = c {
result += n;
}
Ok(result)
}
let code = "
(export call_add_four_ints (n)
(IO (-> ((Option Int)) (Result Int String)))
(add_four_ints 1 [2 3] n))"; // call `add_four_ints` in Rust here.
let exprs = blisp::init(code, vec![Box::new(AddFourInts)]).unwrap(); // extern `add_four_ints`
let ctx = blisp::typing(exprs).unwrap();
let result = blisp::eval("(call_add_four_ints (Some 4))", &ctx).unwrap();
let front = result.front().unwrap().as_ref().unwrap();
assert_eq!(front, "(Ok 10)");
§Expressions
"Hello, World!" ; string
(+ 0x10 0x20) ; 48
(+ 0b111 0b101) ; 12
(+ 0o777 0o444) ; 803
(car '(1 2 3)) ; (Some 1)
(cdr '(1 2 3)) ; '(2 3)
(map (lambda (x) (* x 2)) '(8 9 10)) ; '(16 18 20)
(fold + 0 '(1 2 3 4 5 6 7 8 9)) ; 45
(reverse '(1 2 3 4 5 6 7 8 9)) ; '(9 8 7 6 5 4 3 2 1)
(filter (lambda (x) (= (% x 2) 0)) '(1 2 3 4 5 6 7 8 9)) ; '(2 4 6 8)
Modules§
Structs§
- LispErr
- error message
- Pos
- indicate a position of file
- Typing
Context
Enums§
Functions§
- eval
- evaluate an expression
- init
- initialize BLisp with code
- transpile
- typing
- perform type checking and inference