diff options
Diffstat (limited to 'stdlib/source/lux.lux')
-rw-r--r-- | stdlib/source/lux.lux | 66 |
1 files changed, 1 insertions, 65 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 541b4bcdc..557992ba4 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -5591,36 +5591,6 @@ _ (fail "Wrong syntax for :!!"))) -(def: #hidden hack_Text/append - (-> Text Text Text) - Text/append) - -(def: get-cursor - (Lux Cursor) - (lambda [state] - (let [{#;info info #;source source #;modules modules #;scopes scopes - #;type-vars types #;host host #;seed seed - #;expected expected #;cursor cursor - #;scope-type-vars scope-type-vars} state] - (#;Right [state cursor])))) - -(macro: #export (with-cursor tokens) - {#;doc (doc "Given some text, appends to it a prefix for identifying where the text comes from." - "For example:" - (with-cursor (format "User: " user-id)) - "Would be the same as:" - (format "[the-module,the-line,the-column] " (format "User: " user-id)))} - (case tokens - (^ (list message)) - (do Monad<Lux> - [cursor get-cursor] - (let [[module line column] cursor - cursor-prefix ($_ hack_Text/append "[" module "," (Nat/encode line) "," (Nat/encode column) "] ")] - (wrap (list (` (hack_Text/append (~ (text$ cursor-prefix)) (~ message))))))) - - _ - (fail "Wrong syntax for @"))) - (macro: #export (undefined tokens) {#;doc (doc "Meant to be used as a stand-in for functions with undefined implementations." "Undefined expressions will type-check against everything, so they make good dummy implementations." @@ -5630,45 +5600,11 @@ "If an undefined expression is ever evaluated, it will raise an error.")} (case tokens #;Nil - (return (list (` (error! (with-cursor "Undefined behavior."))))) + (return (list (` (error! "Undefined behavior.")))) _ (fail "Wrong syntax for undefined"))) -(macro: #export (@pre tokens) - {#;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)))} - (case tokens - (^ (list test expr)) - (return (list (` (if (~ test) - (~ expr) - (error! (with-cursor (~ (text$ (Text/append "Pre-condition failed: " (ast-to-text test)))))))))) - - _ - (fail "Wrong syntax for @pre"))) - -(macro: #export (@post tokens) - {#;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 true, returns the value of the expression." - "Otherwise, an error is raised." - (@post i.even? - (i.+ 2 2)))} - (case tokens - (^ (list test expr)) - (do Monad<Lux> - [g!output (gensym "")] - (wrap (list (` (let [(~ g!output) (~ expr)] - (if ((~ test) (~ g!output)) - (~ g!output) - (error! (with-cursor (~ (text$ (Text/append "Post-condition failed: " (ast-to-text test)))))))))))) - - _ - (fail "Wrong syntax for @post"))) - (macro: #export (type-of tokens) {#;doc (doc "Generates the type corresponding to a given definition or variable." (let [my-num (: Int 123)] |