Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add (refute); opposite of (assert) #277

Merged
merged 3 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bass/bass.lock
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ memos: {
}
repository: "hello-world"
tag: "latest"
digest: "sha256:ffb13da98453e0f04d33a6eee5bb8e46ee50d08ebe17735fc0779d0349e889e9"
digest: "sha256:4e83453afed1b4fa1a3500525091dbfca6ce1e66903fd4c01ff015dbcb1ba33e"
}
}
}
Expand Down Expand Up @@ -500,7 +500,7 @@ memos: {
}
output: {
string: {
value: "6ca3f15d70b739a7929886e20b61dbc4cbdc4e22"
value: "cbcb3f550f1208f8804c9f4e52921bd868856cd5"
}
}
}
Expand All @@ -521,7 +521,7 @@ memos: {
}
output: {
string: {
value: "a6c8ee8f81531c08c5136feca23cc6cca0be3b24"
value: "a18944bec00bd72341909da8cf0147a1e59884d5"
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions std/root.bass
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,18 @@
(if (apply pred args)
null
(error (str "assertion failed: " [predicate & args])))))

; applies the predicate to its arguments and errors if it returns true
;
; By convention, the expected value should be passed as the first argument.
;
; => (refute = 4 (+ 2 2))
;
; => (refute = 5 (+ 2 2))
^:indent
(defop refute [predicate & args] scope
(let [pred (eval predicate scope)
args (map (fn [a] (eval a scope)) args)]
(if (apply pred args)
(error (str "refutation failed: " [predicate & args]))
null)))