From adf8aeaa2a52760e294e08618e7aca5fc371fc0f Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 5 Apr 2017 18:05:23 -0400 Subject: - Moved lux/lexer and lux/lexer/regex to lux/data/text/lexer and lux/data/text/regex. - Moved lux/pipe to lux/control/pipe. - Moved the @pre and @post macros to lux/control/contract. - Improved error reporting for lux/type/auto. - Added a test for third-order type-checking for lux/type/auto. - Fixed a bug in the tests for lux/data/coll/vector. --- stdlib/source/lux.lux | 66 +-------------------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) (limited to 'stdlib/source/lux.lux') 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 - [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 - [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)] -- cgit v1.2.3