core: add const-assert

This commit is contained in:
hellerve 2019-05-22 20:01:03 +02:00
parent cb5d3cecf7
commit 3768c42d23
2 changed files with 12 additions and 0 deletions

View File

@ -304,3 +304,10 @@
(doc defproject "Define a project configuration.")
(defmacro defproject [:rest bindings]
(project-config bindings))
(doc const-assert "asserts that the expression `expr` is true at compile time.
Otherwise it will fail with the message `msg`.
The expression must be evaluable at compile time.")
(defndynamic const-assert [expr msg]
(if expr () (macro-error msg)))

View File

@ -1,6 +1,11 @@
(load "Test.carp")
(use Test)
; this wont show up in the test output, sadly
(const-assert true "const-assert works I")
(const-assert (= 1 1) "const-assert works II")
(const-assert (= false (= 1 2)) "const-assert works III")
(defn test-let-do []
(let-do [x 1]
(set! x (+ x 1))