aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/function/contract.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/control/function/contract.lux28
1 files changed, 17 insertions, 11 deletions
diff --git a/stdlib/source/lux/control/function/contract.lux b/stdlib/source/lux/control/function/contract.lux
index 3d1359fdf..1c9236877 100644
--- a/stdlib/source/lux/control/function/contract.lux
+++ b/stdlib/source/lux/control/function/contract.lux
@@ -1,20 +1,26 @@
(.module:
[lux #*
- [abstract
- monad]
[control
- [parser
- ["s" code]]]
+ ["." exception (#+ exception:)]]
[data
[number
["i" int]]
[text
["%" format (#+ format)]]]
[macro (#+ with-gensyms)
- ["." code]
- [syntax (#+ syntax:)]]])
+ [syntax (#+ syntax:)]
+ ["." code]]])
-(def: #export (assert! message test)
+(template [<name>]
+ [(exception: (<name> {condition Code})
+ (exception.report
+ ["Condition" (%.code condition)]))]
+
+ [pre-condition-failed]
+ [post-condition-failed]
+ )
+
+(def: (assert! message test)
(-> Text Bit [])
(if test
[]
@@ -26,8 +32,8 @@
"Otherwise, an error is raised."
(pre (i.= +4 (i.+ +2 +2))
(foo +123 +456 +789)))}
- (wrap (list (` (exec (assert! (~ (code.text (format "Pre-condition failed: " (%.code test))))
- (~ test))
+ (wrap (list (` (exec ((~! ..assert!) (~ (code.text (exception.construct ..pre-condition-failed test)))
+ (~ test))
(~ expr))))))
(syntax: #export (post test expr)
@@ -39,6 +45,6 @@
(i.+ +2 +2)))}
(with-gensyms [g!output]
(wrap (list (` (let [(~ g!output) (~ expr)]
- (exec (assert! (~ (code.text (format "Post-condition failed: " (%.code test))))
- ((~ test) (~ g!output)))
+ (exec ((~! ..assert!) (~ (code.text (exception.construct ..post-condition-failed test)))
+ ((~ test) (~ g!output)))
(~ g!output))))))))