-
Notifications
You must be signed in to change notification settings - Fork 7
/
eval.clj
76 lines (39 loc) · 1.24 KB
/
eval.clj
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(ns convex.eval
"Quick helpers for evaluating Convex Lisp code.
Systematically forks the used context before any operation so that it remains intact.
Notably useful when writing tests."
(:refer-clojure :exclude [true?])
(:require [convex.cvm :as $.cvm]
[convex.std :as $.std]))
;;;;;;;;;;
(defn ctx
"Evaluates the given `cell` and the resulting `ctx`."
[ctx cell]
($.cvm/eval ($.cvm/fork ctx)
cell))
;;;;;;;;;;
(defn exception
"Evaluates the given `cell` and returns the resulting CVM exception.
Or nil."
[ctx cell]
(-> (convex.eval/ctx ctx
cell)
$.cvm/exception))
(defn exception-code
"Evaluates the given `cell` and returns the resulting CVM exception code.
Or nil."
[ctx cell]
(some-> (exception ctx
cell)
($.cvm/exception-code)))
(defn result
"Evaluates the given `cell` and returns the result."
[ctx cell]
($.cvm/result (convex.eval/ctx ctx
cell)))
(defn true?
"Evaluates the given `cell` and returns JVM `true` if the result is CVM `true`.
Notably useful for test assertions."
[ctx cell]
($.std/true? (result ctx
cell)))