Skip to content

Commit

Permalink
Add interactive.bool.
Browse files Browse the repository at this point in the history
  • Loading branch information
smimram committed Mar 5, 2013
1 parent aa78505 commit 03503f3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lang/lang_builtins.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,26 @@ let () =
(s ^ " is not a float")));
Lang.val_fun [] ~ret_t:Lang.float_t (fun p _ -> Lang.float !v))

let () =
add_builtin "interactive.bool" ~cat:Interaction
~descr:"Read a boolean from an interactive input."
["",Lang.string_t,None,None; "",Lang.bool_t,None,None ]
(Lang.fun_t [] Lang.bool_t)
(fun p ->
let name = Lang.to_string (Lang.assoc "" 1 p) in
let v = Lang.to_bool (Lang.assoc "" 2 p) in
let v = ref v in
Var.add
name
Lang.float_t
~get:(fun () -> Printf.sprintf "%B" !v)
~set:(fun s -> v := s = "true")
~validate:
(fun s ->
if s <> "true" && s <> "false" then
raise (Var.Invalid_value (s ^ " is not a boolean")));
Lang.val_fun [] ~ret_t:Lang.bool_t (fun p _ -> Lang.bool !v))

let () =
add_builtin "print" ~cat:Interaction ~descr:"Print on standard output."
["newline",Lang.bool_t,Some (Lang.bool true),
Expand Down

0 comments on commit 03503f3

Please sign in to comment.