Add print/println primitive
This commit is contained in:
parent
1784f83887
commit
de0d7bc009
2 changed files with 21 additions and 0 deletions
20
eval.ml
20
eval.ml
|
@ -204,6 +204,24 @@ module External = struct
|
||||||
|> (fun a -> String (Parser.assoc_to_string a))
|
|> (fun a -> String (Parser.assoc_to_string a))
|
||||||
| _ -> failwith "get_op_assoc"
|
| _ -> failwith "get_op_assoc"
|
||||||
|
|
||||||
|
let print args =
|
||||||
|
let to_string = function
|
||||||
|
| Int n -> string_of_int n
|
||||||
|
| Float n -> string_of_float n
|
||||||
|
| Bool b -> string_of_bool b
|
||||||
|
| String s -> s
|
||||||
|
| Symbol s -> s
|
||||||
|
| _ -> failwith "print"
|
||||||
|
in
|
||||||
|
List.map to_string args
|
||||||
|
|> List.iter (Printf.printf "%s");
|
||||||
|
Nop
|
||||||
|
|
||||||
|
let println args =
|
||||||
|
ignore @@ print args;
|
||||||
|
Printf.printf "\n";
|
||||||
|
Nop
|
||||||
|
|
||||||
let apply f args =
|
let apply f args =
|
||||||
let f = match f with
|
let f = match f with
|
||||||
| "sin" -> floatfun Float.sin
|
| "sin" -> floatfun Float.sin
|
||||||
|
@ -215,6 +233,8 @@ module External = struct
|
||||||
| "get_op_pre" -> get_op_pre
|
| "get_op_pre" -> get_op_pre
|
||||||
| "set_op_assoc" -> set_op_assoc
|
| "set_op_assoc" -> set_op_assoc
|
||||||
| "get_op_assoc" -> get_op_assoc
|
| "get_op_assoc" -> get_op_assoc
|
||||||
|
| "print" -> print
|
||||||
|
| "println" -> println
|
||||||
| _ -> raise @@ Invalid f
|
| _ -> raise @@ Invalid f
|
||||||
in
|
in
|
||||||
f args
|
f args
|
||||||
|
|
1
main.ml
1
main.ml
|
@ -29,6 +29,7 @@ let stdlib = [
|
||||||
"deg"; "rad";
|
"deg"; "rad";
|
||||||
"get_op_pre"; "set_op_pre";
|
"get_op_pre"; "set_op_pre";
|
||||||
"get_op_assoc"; "set_op_assoc";
|
"get_op_assoc"; "set_op_assoc";
|
||||||
|
"print"; "println";
|
||||||
]
|
]
|
||||||
|> List.to_seq
|
|> List.to_seq
|
||||||
|> Seq.map (fun v -> v, External v)
|
|> Seq.map (fun v -> v, External v)
|
||||||
|
|
Loading…
Add table
Reference in a new issue