40 lines
690 B
OCaml
40 lines
690 B
OCaml
open Interp
|
|
|
|
let println vs =
|
|
let pp ppf vs =
|
|
List.iteri
|
|
(fun i v ->
|
|
if i > 0 then Fmt.pf ppf " ";
|
|
Value.pp ppf v)
|
|
vs
|
|
in
|
|
Fmt.pr "%a\n" pp vs;
|
|
Value.Nil
|
|
|
|
let min = function
|
|
| [] -> runtime_error "zero arguments to min()"
|
|
| [ v ] -> v
|
|
| v :: vs ->
|
|
List.fold_left
|
|
(fun v1 v2 ->
|
|
if Value.truthy (Prim.lst v1 v2) then v1 else v2)
|
|
v
|
|
vs
|
|
|
|
let max = function
|
|
| [] -> runtime_error "zero arguments to max()"
|
|
| [ v ] -> v
|
|
| v :: vs ->
|
|
List.fold_left
|
|
(fun v1 v2 ->
|
|
if Value.truthy (Prim.grt v1 v2) then v1 else v2)
|
|
v
|
|
vs
|
|
|
|
let lib = [
|
|
"println", println;
|
|
"min", min;
|
|
"max", max;
|
|
]
|
|
|