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);

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)

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