1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 17:00:27 +00:00

Address #765. Make assert into a macro.

This commit is contained in:
Calvin Rose 2021-08-21 12:27:21 -05:00
parent bd71e1cd02
commit 685d2b460c
2 changed files with 10 additions and 5 deletions

View File

@ -149,10 +149,15 @@
(defmacro /= "Shorthand for (set x (/ x n))." [x n] ~(set ,x (,/ ,x ,n)))
(defmacro %= "Shorthand for (set x (% x n))." [x n] ~(set ,x (,% ,x ,n)))
(defn assert
"Throw an error if x is not truthy."
(defmacro assert
"Throw an error if x is not truthy. Will not evaluate `err` if x is truthy."
[x &opt err]
(if x x (error (if err err "assert failure"))))
(def v (gensym))
~(do
(def ,v ,x)
(if ,v
,v
(,error ,(if err err "assert failure")))))
(defn errorf
"A combination of error and string/format. Equivalent to (error (string/format fmt ;args))"

View File

@ -6,8 +6,8 @@
#define JANET_VERSION_MAJOR 1
#define JANET_VERSION_MINOR 17
#define JANET_VERSION_PATCH 0
#define JANET_VERSION_EXTRA "dev"
#define JANET_VERSION "1.17.0-dev"
#define JANET_VERSION_EXTRA ""
#define JANET_VERSION "1.17.0"
/* #define JANET_BUILD "local" */