1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
open Ast

(*
--# Check if a value is an Error
--#
--# Returns true if the value is an Error object, false otherwise.
--#
--# @name is_error
--# @param x :: Any The value to check.
--# @return :: Bool True if x is an Error.
--# @example
--#   is_error(error("Something went wrong"))
--#   -- Returns = true
--# @family core
--# @export
*)
let register env =
  Env.add "is_error"
    (make_builtin ~name:"is_error" 1 (fun args _env ->
      match args with
      | [VError _] -> VBool true
      | [_] -> VBool false
      | _ -> Error.arity_error_named "is_error" 1 (List.length args)
    ))
    env