Something went wrong. Try again.
a scheme notebook; emacs meets obsidian; probably never finished
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839open Factotum_commonopen Factotum_eval
let fresh name = Binding.Brand.brand (Symbol.of_string name)let int n = Expr.Literal (Value.Integer n)let nil = Expr.Literal Value.Nillet symbol s = Expr.Literal (Value.Symbol (Symbol.of_string s))let bool b = Expr.Literal (Value.Bool b)let var binding = Expr.Variable (Expr.VarBound binding)let missing name = Expr.Variable (Expr.VarFree (Symbol.of_string name))let lambda params body = Expr.Lambda { params; body }let call procedure arguments = Expr.Apply { procedure; arguments }let scope mode bindings body = Expr.Scope { mode; bindings; body }let prompt tag handler body = Expr.Prompt { prompt = tag; handler; body }let make_effect arity = Expr.Literal (Eval.make_effect arity)let expr_effect eff = Expr.Literal (Value.Runtime (Eval.Effect eff))
let binary operation a b = let procedure = Eval.make_procedure (fun args _ -> match args with | [Value.Integer a; Value.Integer b] -> Ok (Value.Integer (operation a b)) | _ -> Error "expected two integers") in call (Expr.Literal procedure) [a; b]
let add = binary ( + )let subtract = binary ( - )let multiply = binary ( * )
(* --- *)
let seq' values = Expr.Sequence valueslet cond' tests ~otherwise = Expr.Cond { tests; otherwise }
let let' bindings body = Expr.Scope { mode = Expr.ScopeParallel; bindings; body } let letplus' bindings body = Expr.Scope { mode = Expr.ScopeSequential; bindings; body }let letrec' bindings body = Expr.Scope { mode = Expr.ScopeRecursive; bindings; body }
let match' discriminant patterns ~otherwise = Expr.Match { discriminant; patterns; otherwise }