From ab268d6fce40fac9c5029e39db927542facea201 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 7 Sep 2019 20:58:21 -0400 Subject: Re-named "lux/control/contract" to "lux/control/function/contract". --- stdlib/source/lux/control/contract.lux | 44 ------------------------- stdlib/source/lux/control/function/contract.lux | 44 +++++++++++++++++++++++++ stdlib/source/test/lux.lux | 3 +- 3 files changed, 46 insertions(+), 45 deletions(-) delete mode 100644 stdlib/source/lux/control/contract.lux create mode 100644 stdlib/source/lux/control/function/contract.lux (limited to 'stdlib') diff --git a/stdlib/source/lux/control/contract.lux b/stdlib/source/lux/control/contract.lux deleted file mode 100644 index 3d1359fdf..000000000 --- a/stdlib/source/lux/control/contract.lux +++ /dev/null @@ -1,44 +0,0 @@ -(.module: - [lux #* - [abstract - monad] - [control - [parser - ["s" code]]] - [data - [number - ["i" int]] - [text - ["%" format (#+ format)]]] - [macro (#+ with-gensyms) - ["." code] - [syntax (#+ syntax:)]]]) - -(def: #export (assert! message test) - (-> Text Bit []) - (if test - [] - (error! message))) - -(syntax: #export (pre test expr) - {#.doc (doc "Pre-conditions." - "Given a test and an expression to run, only runs the expression if the test passes." - "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)) - (~ expr)))))) - -(syntax: #export (post test expr) - {#.doc (doc "Post-conditions." - "Given a predicate and an expression to run, evaluates the expression and then tests the output with the predicate." - "If the predicate returns #1, returns the value of the expression." - "Otherwise, an error is raised." - (post i.even? - (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))) - (~ g!output)))))))) diff --git a/stdlib/source/lux/control/function/contract.lux b/stdlib/source/lux/control/function/contract.lux new file mode 100644 index 000000000..3d1359fdf --- /dev/null +++ b/stdlib/source/lux/control/function/contract.lux @@ -0,0 +1,44 @@ +(.module: + [lux #* + [abstract + monad] + [control + [parser + ["s" code]]] + [data + [number + ["i" int]] + [text + ["%" format (#+ format)]]] + [macro (#+ with-gensyms) + ["." code] + [syntax (#+ syntax:)]]]) + +(def: #export (assert! message test) + (-> Text Bit []) + (if test + [] + (error! message))) + +(syntax: #export (pre test expr) + {#.doc (doc "Pre-conditions." + "Given a test and an expression to run, only runs the expression if the test passes." + "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)) + (~ expr)))))) + +(syntax: #export (post test expr) + {#.doc (doc "Post-conditions." + "Given a predicate and an expression to run, evaluates the expression and then tests the output with the predicate." + "If the predicate returns #1, returns the value of the expression." + "Otherwise, an error is raised." + (post i.even? + (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))) + (~ g!output)))))))) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index c293985a4..db3a84ce7 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -69,9 +69,10 @@ [scheme (#+) ]]]]] ## [control - ## ["._" contract] ## ["._" concatenative] ## ["._" predicate] + ## [function + ## ["._" contract]] ## [monad ## ["._" free]] ## [parser -- cgit v1.2.3