From 54b28c1caeda08965c258411a32229be1766d47f Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 29 Jul 2021 19:23:23 -0400 Subject: Switched from the "from to" convention to the "minimum additional" convention. --- commands.md | 3 + .../book/the_lux_programming_language/chapter_3.md | 2 +- .../book/the_lux_programming_language/chapter_4.md | 175 +++++++++++++++++++ documentation/bookmark/floating_point.md | 4 + documentation/bookmark/inspiration.md | 4 + documentation/bookmark/platform.md | 4 + documentation/bookmark/polyglot_programming.md | 4 + stdlib/source/library/lux.lux | 153 +++++++++-------- stdlib/source/library/lux/abstract/comonad.lux | 2 +- stdlib/source/library/lux/abstract/monad.lux | 6 +- .../source/library/lux/control/concatenative.lux | 8 +- .../library/lux/control/concurrency/semaphore.lux | 2 +- stdlib/source/library/lux/control/parser.lux | 13 +- stdlib/source/library/lux/control/parser/text.lux | 20 ++- stdlib/source/library/lux/control/parser/tree.lux | 2 +- stdlib/source/library/lux/control/state.lux | 4 +- stdlib/source/library/lux/control/thread.lux | 9 +- stdlib/source/library/lux/control/try.lux | 18 +- stdlib/source/library/lux/control/writer.lux | 2 + .../source/library/lux/data/collection/array.lux | 41 +++-- stdlib/source/library/lux/data/collection/bits.lux | 4 +- .../lux/data/collection/dictionary/ordered.lux | 10 +- .../lux/data/collection/dictionary/plist.lux | 3 + stdlib/source/library/lux/data/collection/list.lux | 6 +- .../library/lux/data/collection/queue/priority.lux | 9 +- .../library/lux/data/collection/set/multi.lux | 5 + .../library/lux/data/collection/set/ordered.lux | 4 + .../library/lux/data/collection/tree/finger.lux | 7 + .../library/lux/data/collection/tree/zipper.lux | 15 +- stdlib/source/library/lux/data/format/css.lux | 4 +- .../library/lux/data/format/css/selector.lux | 6 +- .../source/library/lux/data/format/css/value.lux | 4 +- stdlib/source/library/lux/data/format/html.lux | 6 +- stdlib/source/library/lux/data/format/json.lux | 6 +- stdlib/source/library/lux/data/format/markdown.lux | 12 +- stdlib/source/library/lux/data/format/tar.lux | 54 +++--- stdlib/source/library/lux/data/text.lux | 10 +- stdlib/source/library/lux/data/text/format.lux | 2 +- stdlib/source/library/lux/data/text/regex.lux | 186 +++++++++++---------- stdlib/source/library/lux/debug.lux | 16 +- stdlib/source/library/lux/ffi.old.lux | 118 ++++++------- stdlib/source/library/lux/macro.lux | 39 ++--- .../source/library/lux/macro/syntax/definition.lux | 2 +- stdlib/source/library/lux/math/number/i16.lux | 3 +- stdlib/source/library/lux/math/number/i8.lux | 3 +- stdlib/source/library/lux/meta.lux | 6 +- stdlib/source/library/lux/target/common_lisp.lux | 4 +- stdlib/source/library/lux/target/js.lux | 17 +- .../library/lux/target/jvm/type/descriptor.lux | 4 +- .../library/lux/target/jvm/type/signature.lux | 10 +- stdlib/source/library/lux/target/lua.lux | 18 +- stdlib/source/library/lux/target/php.lux | 6 +- stdlib/source/library/lux/target/python.lux | 4 +- stdlib/source/library/lux/target/ruby.lux | 22 +-- stdlib/source/library/lux/target/scheme.lux | 6 +- stdlib/source/library/lux/time.lux | 16 +- stdlib/source/library/lux/time/date.lux | 10 +- stdlib/source/library/lux/time/instant.lux | 4 +- .../lux/tool/compiler/language/lux/analysis.lux | 10 +- .../language/lux/phase/analysis/case/coverage.lux | 6 +- .../language/lux/phase/extension/analysis.lux | 4 +- .../lux/phase/extension/generation/r/common.lux | 6 +- .../lux/phase/generation/common_lisp/loop.lux | 2 +- .../compiler/language/lux/phase/generation/js.lux | 4 +- .../language/lux/phase/generation/r/runtime.lux | 10 +- .../lux/tool/compiler/language/lux/program.lux | 14 +- .../lux/tool/compiler/language/lux/syntax.lux | 4 +- .../lux/tool/compiler/language/lux/synthesis.lux | 30 ++-- .../lux/tool/compiler/meta/packager/scheme.lux | 2 +- stdlib/source/library/lux/type.lux | 2 +- stdlib/source/library/lux/type/refinement.lux | 8 +- stdlib/source/library/lux/world/db/sql.lux | 144 ++++++++-------- .../source/library/lux/world/net/http/cookie.lux | 21 +-- stdlib/source/library/lux/world/net/http/query.lux | 8 +- stdlib/source/library/lux/world/net/http/route.lux | 10 +- .../library/lux/world/service/authentication.lux | 16 +- stdlib/source/library/lux/world/service/crud.lux | 24 +-- .../source/library/lux/world/service/inventory.lux | 24 +-- .../source/library/lux/world/service/journal.lux | 12 +- stdlib/source/library/lux/world/service/mail.lux | 12 +- stdlib/source/library/lux/world/shell.lux | 4 +- stdlib/source/program/scriptum.lux | 2 +- stdlib/source/test/lux.lux | 35 +++- .../test/lux/control/concurrency/semaphore.lux | 2 +- stdlib/source/test/lux/control/parser.lux | 4 +- stdlib/source/test/lux/control/parser/text.lux | 12 +- stdlib/source/test/lux/control/parser/tree.lux | 2 +- stdlib/source/test/lux/control/remember.lux | 8 +- stdlib/source/test/lux/data/collection/list.lux | 6 +- .../test/lux/data/collection/tree/zipper.lux | 64 +++---- stdlib/source/test/lux/data/text.lux | 8 +- stdlib/source/test/lux/debug.lux | 4 +- stdlib/source/test/lux/ffi.jvm.lux | 2 +- stdlib/source/test/lux/macro.lux | 32 ++-- stdlib/source/test/lux/macro/local.lux | 4 +- stdlib/source/test/lux/macro/template.lux | 2 +- stdlib/source/test/lux/math/number/int.lux | 6 +- stdlib/source/test/lux/math/number/nat.lux | 6 +- stdlib/source/test/lux/math/number/rev.lux | 6 +- stdlib/source/test/lux/type/abstract.lux | 2 +- stdlib/source/test/lux/type/refinement.lux | 12 +- stdlib/source/test/lux/type/resource.lux | 2 +- 102 files changed, 1027 insertions(+), 708 deletions(-) create mode 100644 documentation/book/the_lux_programming_language/chapter_4.md create mode 100644 documentation/bookmark/platform.md create mode 100644 documentation/bookmark/polyglot_programming.md diff --git a/commands.md b/commands.md index a94dee8a7..00c3e621a 100644 --- a/commands.md +++ b/commands.md @@ -2,6 +2,9 @@ ``` cd ~/lux/ && find . -name '*.lux' | xargs wc -l + +## Sorted by number of lines per file. +cd ~/lux/ && find . -name '*.lux' | xargs wc -l | sort -rn ``` --- diff --git a/documentation/book/the_lux_programming_language/chapter_3.md b/documentation/book/the_lux_programming_language/chapter_3.md index 33400b355..08187fdbe 100644 --- a/documentation/book/the_lux_programming_language/chapter_3.md +++ b/documentation/book/the_lux_programming_language/chapter_3.md @@ -219,5 +219,5 @@ Also, you might be wondering what's the difference between `List` and `list`. We Again, we haven't mentioned functions. But if you're impatient to learn about them, just click the link below. -See you in the next chapter! +See you in [the next chapter](chapter_4.md)! diff --git a/documentation/book/the_lux_programming_language/chapter_4.md b/documentation/book/the_lux_programming_language/chapter_4.md new file mode 100644 index 000000000..8af46ccfc --- /dev/null +++ b/documentation/book/the_lux_programming_language/chapter_4.md @@ -0,0 +1,175 @@ +# Chapter 4: Functions and Definitions + +_Where you will learn how to build your own Lux code._ + +--- + +OK, so you've seen several explanations and details so far, but you haven't really seen how to make use of all of this information. + +No worries. You're about to find out! + +First, let's talk about how to make your own functions. + +``` +(function (plus_two x) (inc (inc x))) +``` + +Here's the first example. +This humble function increases a `Nat` twice. + +What is it's type? + +Well, I'm glad you asked. + +``` +(: (-> Nat Nat) + (function (plus_two x) (inc (inc x)))) +``` + +That `->` thingie you see there is a macro for generating function types. +It works like this: + +``` +(-> arg1 arg2 ... argN return) +``` + +The types of the arguments and the return type can be any type you want (even other function types, but more on that later). + +How do we use our function? Just put it at the beginning for a form: + +``` +((function (plus_two x) (inc (inc x))) 5) +## => 7 +``` + +Cool, but... inconvenient. + +It would be awful to have to use functions that way. + +How do we use the `plus_two` function without having to inline its definition (like the `debug.log!` function we used previously)? + +Well, we just need to define it! + +``` +(def: plus_two + (: (-> Nat Nat) + (function (_ x) + (inc (inc x))))) +``` + +Or, alternatively: + +``` +(def: plus_two + (-> Nat Nat) + (function (_ x) + (inc (inc x)))) +``` + +Notice how the `def:` macro can take the type of its value before the value itself, so we don't need to wrap it in the type-annotation `:` macro. + +Now, we can use the square function more conveniently. + +``` +(plus_two 7) +## => 9 +``` + +Nice! + +Also, I forgot to mention another form of the `def:` macro which is even more convenient: + +``` +(def: (plus_two x) + (-> Nat Nat) + (inc (inc x))) +``` + +The `def:` macro is very versatile, and it allows us to define constants and functions. + +If you omit the type, the compiler will try to infer it for you, and you will get an error if there are any ambiguities. + +You will also get an error if you add the types but there's something funny with your code and things don't match up. + +Error messages keep improving on each release, but in general you'll be getting the **file, line and column** on which an error occurs, and if it's a type-checking error, you'll usually get the type that was expected and the actual type of the offending expression... in multiple levels, as the type-checker analyses things in several steps. That way, you can figure out what's going on by seeing the more localized error alongside the more general, larger-scope error. + +--- + +Functions, of course, can take more than one argument, and you can even refer to a function within its own body (also known as recursion). + +Check this one out: + +``` +(def: (factorial' acc n) + (-> Nat Nat Nat) + (if (n.= 0 n) + acc + (factorial' (n.* n acc) (dec n)))) + +(def: (factorial n) + (-> Nat Nat) + (factorial' 1 n)) +``` + +And if we just had the function expression itself, it would look like this: + +``` +(function (factorial' acc n) + (if (n.= 0 n) + acc + (factorial' (n.* n acc) (dec n)))) +``` + +Here, we're defining the `factorial` function by counting down on the input and multiplying some accumulated value on each step. We're using an intermediary function `factorial'` to have access to an accumulator for keeping the in-transit output value, and we're using an `if` expression (one of the many macros in the `library/lux` module) coupled with a recursive call to iterate until the input is 0 and we can just return the accumulated value. + +As it is (hopefully) easy to see, the `if` expression takes a _test_ expression as its first argument, a _"then"_ expression as its second argument, and an _"else"_ expression as its third argument. + +Both the `n.=` and the `n.*` functions operate on `Nat`s, and `dec` is a function for decreasing `Nat`s; that is, to subtract 1 from the `Nat`. + +You might be wondering what's up with that `n.` prefix. + +The reason it exists is that Lux's arithmetic functions are not polymorphic on the numeric types, and so there are similar functions for each type. + +If you import the module for `Nat` numbers, like so: + +``` +(.module + [library + [lux + [math + [number + ["n" nat]]]]]) +``` + +You can access all definitions in the "library/lux/math/number/nat" module by just using the "n." prefix. + + I know it looks annoying, but later in the book you'll discover a way to do math on any Lux number without having to worry about types and prefixes. + +Also, it might be good to explain that Lux functions can be partially applied. This means that if a function takes N arguments, and you give it M arguments, where M < N, then instead of getting a compilation error, you'll just get a new function that takes the remaining arguments and then runs as expected. + +That means, our factorial function could have been implemented like this: + +``` +(def: factorial + (-> Nat Nat) + (factorial' +1)) +``` + +Or, to make it shorter: + +``` +(def: factorial (factorial' +1)) +``` + +Nice, huh? + +--- + +We've seen how to make our own definitions, which are the fundamental components in Lux programs. + +We've also seen how to make functions, which is how you make your programs **do** things. + +Next, we'll make things more interesting, with _branching_, _loops_ and _pattern-matching_! + +See you in the next chapter! + diff --git a/documentation/bookmark/floating_point.md b/documentation/bookmark/floating_point.md index 5e212c08f..238112f51 100644 --- a/documentation/bookmark/floating_point.md +++ b/documentation/bookmark/floating_point.md @@ -1,3 +1,7 @@ +# Debugging + +1. [Keynote: William Kahan - Debugging Tools for Floating-Point Code](https://www.youtube.com/watch?v=qHddEkfQBrA) + # Comparison 1. [Approximate Equality for Floating Point](https://github.com/apple/swift-evolution/blob/master/proposals/0259-approximately-equal.md) diff --git a/documentation/bookmark/inspiration.md b/documentation/bookmark/inspiration.md index 576d73f99..7ae89147d 100644 --- a/documentation/bookmark/inspiration.md +++ b/documentation/bookmark/inspiration.md @@ -1,3 +1,7 @@ +# Feature + +1. [About Adding Features (part 1)](https://kele.codes/2021/07/about-adding-features-1/) + # Business 1. [Why Aren't There More Programming Languages Startups?](https://www.akitasoftware.com/blog-posts/why-arent-there-more-programming-languages-startups) diff --git a/documentation/bookmark/platform.md b/documentation/bookmark/platform.md new file mode 100644 index 000000000..a653d156b --- /dev/null +++ b/documentation/bookmark/platform.md @@ -0,0 +1,4 @@ +# Reference + +1. [fission](https://fission.codes/) + diff --git a/documentation/bookmark/polyglot_programming.md b/documentation/bookmark/polyglot_programming.md new file mode 100644 index 000000000..4f5e26c65 --- /dev/null +++ b/documentation/bookmark/polyglot_programming.md @@ -0,0 +1,4 @@ +# Language + +1. [morloc](https://github.com/morloc-project/morloc) + diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index 9f2b0a697..9bf50bba5 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -1400,11 +1400,11 @@ (failure "Wrong syntax for def:'''")} tokens)) -(def:''' (as_pairs xs) +(def:''' (pairs xs) #End (All [a] (-> ($' List a) ($' List (& a a)))) ({(#Item x (#Item y xs')) - (#Item [x y] (as_pairs xs')) + (#Item [x y] (pairs xs')) _ #End} @@ -1419,7 +1419,7 @@ (form$ (list (record$ (list [label body])) value))} binding))) body - (list\reverse (as_pairs bindings))))) + (list\reverse (pairs bindings))))) _ (failure "Wrong syntax for let'")} @@ -1587,7 +1587,7 @@ value))} var)))) body - (list\reverse (as_pairs bindings)))] + (list\reverse (pairs bindings)))] (return (list (form$ (list (record$ (list [(record$ (list [(tag$ ["library/lux" "in"]) g!in] [(tag$ ["library/lux" "bind"]) g!bind])) body'])) monad))))) @@ -1651,10 +1651,15 @@ (failure "Wrong syntax for if")} tokens)) +(def:''' PList + #End + Type + (All [a] ($' List (& Text a)))) + (def:''' (get k plist) #End (All [a] - (-> Text ($' List (& Text a)) ($' Maybe a))) + (-> Text ($' PList a) ($' Maybe a))) ({(#Item [[k' v] plist']) (if (text\= k k') (#Some v) @@ -1667,7 +1672,7 @@ (def:''' (put k v dict) #End (All [a] - (-> Text a ($' List (& Text a)) ($' List (& Text a)))) + (-> Text a ($' PList a) ($' PList a))) ({#End (list [k v]) @@ -1742,7 +1747,7 @@ (#Left ($_ text\compose "Unknown module: " module " @ " (name\encode full_name)))} (get module modules)))) -(def:''' (as_code_list expression) +(def:''' (code_list expression) #End (-> Code Code) (let' [type (form$ (list (tag$ ["library/lux" "Apply"]) @@ -1760,13 +1765,13 @@ (#Item lastI inits) (do meta_monad [lastO ({[_ (#Form (#Item [[_ (#Identifier ["" "~+"])] (#Item [spliced #End])]))] - (in (as_code_list spliced)) + (in (code_list spliced)) _ (do meta_monad [lastO (untemplate lastI)] - (in (as_code_list (form$ (list (tag$ ["library/lux" "Item"]) - (tuple$ (list lastO (tag$ ["library/lux" "End"]))))))))} + (in (code_list (form$ (list (tag$ ["library/lux" "Item"]) + (tuple$ (list lastO (tag$ ["library/lux" "End"]))))))))} lastI)] (monad\fold meta_monad (function' [leftI rightO] @@ -1774,7 +1779,7 @@ (let' [g!in-module (form$ (list (text$ "lux in-module") (text$ "library/lux") (identifier$ ["library/lux" "list\compose"])))] - (in (form$ (list g!in-module (as_code_list spliced) rightO)))) + (in (form$ (list g!in-module (code_list spliced) rightO)))) _ (do meta_monad @@ -2309,7 +2314,7 @@ #None)} ("lux type check" Global gdef)))) -(def:''' (normalize name) +(def:''' (normal name) #End (-> Name ($' Meta Name)) ({["" name] @@ -2340,7 +2345,7 @@ #End (-> Name ($' Meta Bit)) (do meta_monad - [name (normalize name) + [name (normal name) output (macro name)] (in ({(#Some _) #1 #None #0} @@ -2360,13 +2365,13 @@ (list& x sep (interpose sep xs'))} xs)) -(def:''' (macro_expand_once token) +(def:''' (single_expansion token) #End (-> Code ($' Meta ($' List Code))) - ({[_ (#Form (#Item [_ (#Identifier macro_name)] args))] + ({[_ (#Form (#Item [_ (#Identifier name)] args))] (do meta_monad - [macro_name' (normalize macro_name) - ?macro (macro macro_name')] + [name' (normal name) + ?macro (macro name')] ({(#Some macro) (("lux type as" Macro' macro) args) @@ -2378,18 +2383,18 @@ (return (list token))} token)) -(def:''' (macro_expand token) +(def:''' (expansion token) #End (-> Code ($' Meta ($' List Code))) - ({[_ (#Form (#Item [_ (#Identifier macro_name)] args))] + ({[_ (#Form (#Item [_ (#Identifier name)] args))] (do meta_monad - [macro_name' (normalize macro_name) - ?macro (macro macro_name')] + [name' (normal name) + ?macro (macro name')] ({(#Some macro) (do meta_monad - [expansion (("lux type as" Macro' macro) args) - expansion' (monad\map meta_monad macro_expand expansion)] - (in (list\join expansion'))) + [top_level_expansion (("lux type as" Macro' macro) args) + recursive_expansion (monad\map meta_monad expansion top_level_expansion)] + (in (list\join recursive_expansion))) #None (return (list token))} @@ -2399,33 +2404,33 @@ (return (list token))} token)) -(def:''' (macro_expand_all syntax) +(def:''' (full_expansion syntax) #End (-> Code ($' Meta ($' List Code))) - ({[_ (#Form (#Item [_ (#Identifier macro_name)] args))] + ({[_ (#Form (#Item [_ (#Identifier name)] args))] (do meta_monad - [macro_name' (normalize macro_name) - ?macro (macro macro_name')] + [name' (normal name) + ?macro (macro name')] ({(#Some macro) (do meta_monad [expansion (("lux type as" Macro' macro) args) - expansion' (monad\map meta_monad macro_expand_all expansion)] + expansion' (monad\map meta_monad full_expansion expansion)] (in (list\join expansion'))) #None (do meta_monad - [args' (monad\map meta_monad macro_expand_all args)] - (in (list (form$ (#Item (identifier$ macro_name) (list\join args'))))))} + [args' (monad\map meta_monad full_expansion args)] + (in (list (form$ (#Item (identifier$ name) (list\join args'))))))} ?macro)) [_ (#Form members)] (do meta_monad - [members' (monad\map meta_monad macro_expand_all members)] + [members' (monad\map meta_monad full_expansion members)] (in (list (form$ (list\join members'))))) [_ (#Tuple members)] (do meta_monad - [members' (monad\map meta_monad macro_expand_all members)] + [members' (monad\map meta_monad full_expansion members)] (in (list (tuple$ (list\join members'))))) [_ (#Record pairs)] @@ -2434,7 +2439,7 @@ (function' [kv] (let' [[key val] kv] (do meta_monad - [val' (macro_expand_all val)] + [val' (full_expansion val)] ({(#Item val'' #End) (return [key val'']) @@ -2483,7 +2488,7 @@ "(type (All [a] (Maybe (List a))))"))]) ({(#Item type #End) (do meta_monad - [type+ (macro_expand_all type)] + [type+ (full_expansion type)] ({(#Item type' #End) (in (list (walk_type type'))) @@ -2751,18 +2756,18 @@ (def:' (expander branches) (-> (List Code) (Meta (List Code))) - ({(#Item [_ (#Form (#Item [_ (#Identifier macro_name)] macro_args))] + ({(#Item [_ (#Form (#Item [_ (#Identifier name)] args))] (#Item body branches')) (do meta_monad - [??? (macro? macro_name)] + [??? (macro? name)] (if ??? (do meta_monad - [init_expansion (macro_expand_once (form$ (list& (identifier$ macro_name) (form$ macro_args) body branches')))] + [init_expansion (single_expansion (form$ (list& (identifier$ name) (form$ args) body branches')))] (expander init_expansion)) (do meta_monad [sub_expansion (expander branches')] - (in (list& (form$ (list& (identifier$ macro_name) macro_args)) + (in (list& (form$ (list& (identifier$ name) args)) body sub_expansion))))) @@ -2795,7 +2800,7 @@ ({(#Item value branches) (do meta_monad [expansion (expander branches)] - (in (list (` ((~ (record$ (as_pairs expansion))) (~ value)))))) + (in (list (` ((~ (record$ (pairs expansion))) (~ value)))))) _ (failure "Wrong syntax for case")} @@ -2815,7 +2820,7 @@ (case tokens (#Item [_ (#Form (#Item pattern #End))] (#Item body branches)) (do meta_monad - [pattern+ (macro_expand_all pattern)] + [pattern+ (full_expansion pattern)] (case pattern+ (#Item pattern' #End) (in (list& pattern' body branches)) @@ -2875,7 +2880,7 @@ (case tokens (^ (list [_ (#Tuple bindings)] body)) (if (multiple? 2 (list\size bindings)) - (|> bindings as_pairs list\reverse + (|> bindings pairs list\reverse (list\fold (: (-> [Code Code] Code Code) (function' [lr body'] (let' [[l r] lr] @@ -3173,8 +3178,8 @@ (case ?parts (#Some name args meta sigs) (do meta_monad - [name+ (normalize name) - sigs' (monad\map meta_monad macro_expand sigs) + [name+ (normal name) + sigs' (monad\map meta_monad expansion sigs) members (: (Meta (List [Text Code])) (monad\map meta_monad (: (-> Code (Meta [Text Code])) @@ -3236,7 +3241,7 @@ [and (if (~ pre) (~ post) #0) "'and' requires >=1 clauses." "Short-circuiting 'and': (and #1 #0 #1) ## => #0"] [or (if (~ pre) #1 (~ post)) "'or' requires >=1 clauses." "Short-circuiting 'or': (or #1 #0 #1) ## => #1"]) -(def: (index_of part text) +(def: (index part text) (-> Text Text (Maybe Nat)) ("lux text index" 0 part text)) @@ -3271,7 +3276,7 @@ (def: (text\split_all_with splitter input) (-> Text Text (List Text)) - (case (..index_of splitter input) + (case (..index splitter input) #None (list input) @@ -3494,7 +3499,7 @@ (macro: #export (implementation tokens) {#.doc "Not meant to be used directly. Prefer 'implementation:'."} (do meta_monad - [tokens' (monad\map meta_monad macro_expand tokens) + [tokens' (monad\map meta_monad expansion tokens) struct_type get_expected_type tags+type (resolve_type_tags struct_type) tags (: (Meta (List Name)) @@ -3777,7 +3782,7 @@ (def: (text\split_with token sample) (-> Text Text (Maybe [Text Text])) (do ..maybe_monad - [index (..index_of token sample) + [index (..index token sample) #let [[pre post'] (text\split! index sample) [_ post] (text\split! ("lux text size" token) post')]] (in [pre post]))) @@ -4235,9 +4240,9 @@ {#.doc (text$ ($_ "lux text concat" "## Same as the 'open' macro, but meant to be used as a pattern-matching macro for generating local bindings." ..\n "## Takes an 'alias' text for the generated local bindings." ..\n - "(def: #export (range (^open ''.'') from to)" ..\n + "(def: #export (range (^open ''.'') minimum additional)" ..\n " (All [a] (-> (Enum a) a a (List a)))" ..\n - " (range' <= succ from to))"))} + " (range' <= succ minimum additional))"))} (case tokens (^ (list& [_ (#Form (list [_ (#Text alias)]))] body branches)) (do meta_monad @@ -4299,7 +4304,7 @@ (let [[right left] branch] (` (if (~ left) (~ right) (~ else)))))) else - (as_pairs branches')))) + (pairs branches')))) _ (failure "Wrong syntax for cond")))) @@ -4331,7 +4336,7 @@ (case tokens (^ (list [_ (#Tag slot')] record)) (do meta_monad - [slot (normalize slot') + [slot (normal slot') output (resolve_tag slot) #let [[idx tags exported? type] output] g!_ (gensym "_") @@ -4546,7 +4551,7 @@ _ (failure "Wrong syntax for refer"))) -(def: (refer_to_code module_name module_alias' [r_defs r_opens]) +(def: (refer_code module_name module_alias' [r_defs r_opens]) (-> Text (Maybe Text) Refer Code) (let [module_alias (..default module_name module_alias') localizations (: (List Code) @@ -4608,7 +4613,7 @@ tuple$) =refers (list\map (: (-> Importation Code) (function (_ [m_name m_alias =refer]) - (refer_to_code m_name m_alias =refer))) + (refer_code m_name m_alias =refer))) imports) =module (` ("lux def module" [(~ location_code) (#.Record (~ (process_def_meta _meta)))] @@ -4646,7 +4651,7 @@ (case tokens (^ (list [_ (#Tag slot')] value record)) (do meta_monad - [slot (normalize slot') + [slot (normal slot') output (resolve_tag slot) #let [[idx tags exported? type] output]] (case (resolve_struct_type type) @@ -4735,7 +4740,7 @@ (case tokens (^ (list [_ (#Tag slot')] fun record)) (do meta_monad - [slot (normalize slot') + [slot (normal slot') output (resolve_tag slot) #let [[idx tags exported? type] output]] (case (resolve_struct_type type) @@ -5031,15 +5036,15 @@ (#Item y ys') (list& x y (interleave xs' ys'))))) -(def: (type_to_code type) +(def: (type_code type) (-> Type Code) (case type (#Primitive name params) - (` (#.Primitive (~ (text$ name)) (~ (untemplated_list (list\map type_to_code params))))) + (` (#.Primitive (~ (text$ name)) (~ (untemplated_list (list\map type_code params))))) (^template [] [( left right) - (` ( (~ (type_to_code left)) (~ (type_to_code right))))]) + (` ( (~ (type_code left)) (~ (type_code right))))]) ([#.Sum] [#.Product] [#.Function] [#.Apply]) @@ -5051,15 +5056,15 @@ (^template [] [( env type) - (let [env' (untemplated_list (list\map type_to_code env))] - (` ( (~ env') (~ (type_to_code type)))))]) + (let [env' (untemplated_list (list\map type_code env))] + (` ( (~ env') (~ (type_code type)))))]) ([#.UnivQ] [#.ExQ]) (#Named [module name] anonymous) ## TODO: Generate the explicit type definition instead of using ## the "identifier$" shortcut below. ## (` (#.Named [(~ (text$ module)) (~ (text$ name))] - ## (~ (type_to_code anonymous)))) + ## (~ (type_code anonymous)))) (identifier$ [module name]))) (macro: #export (loop tokens) @@ -5089,7 +5094,7 @@ #.None)] (case ?params (#.Some [name bindings body]) - (let [pairs (as_pairs bindings) + (let [pairs (pairs bindings) vars (list\map first pairs) inits (list\map second pairs)] (if (every? identifier? inits) @@ -5101,8 +5106,8 @@ init_types (monad\map meta_monad type_definition inits') expected get_expected_type] (return (list (` (("lux type check" - (-> (~+ (list\map type_to_code init_types)) - (~ (type_to_code expected))) + (-> (~+ (list\map type_code init_types)) + (~ (type_code expected))) (function ((~ name) (~+ vars)) (~ body))) (~+ inits)))))) @@ -5139,8 +5144,8 @@ #None (failure "Wrong syntax for ^slots"))) #let [[hslot tslots] slots] - hslot (normalize hslot) - tslots (monad\map meta_monad normalize tslots) + hslot (..normal hslot) + tslots (monad\map meta_monad ..normal tslots) output (resolve_tag hslot) g!_ (gensym "_") #let [[idx tags exported? type] output @@ -5221,9 +5226,9 @@ (case tokens (^ (list& [_ (#Tuple bindings)] bodies)) (case bindings - (^ (list& [_ (#Identifier ["" var_name])] macro_expr bindings')) + (^ (list& [_ (#Identifier ["" var_name])] expr bindings')) (do meta_monad - [expansion (macro_expand_once macro_expr)] + [expansion (single_expansion expr)] (case (place_tokens var_name expansion (` (.with_expansions [(~+ bindings')] (~+ bodies)))) @@ -5409,7 +5414,7 @@ #None (case (~ g!temp) (~+ next_branches))} - ("lux type check" (#.Apply (~ (type_to_code expected)) Maybe) + ("lux type check" (#.Apply (~ (type_code expected)) Maybe) (case (~ g!temp) (~+ (multi_level_case$ g!temp [mlc body])) @@ -5526,7 +5531,7 @@ (^ (list expr)) (do meta_monad [type get_expected_type] - (in (list (` ("lux type as" (~ (type_to_code type)) (~ expr)))))) + (in (list (` ("lux type as" (~ (type_code type)) (~ expr)))))) _ (failure (..wrong_syntax_error (name_of ..:assume))))) @@ -5572,7 +5577,7 @@ (^ (list [_ (#Identifier var_name)])) (do meta_monad [var_type (type_definition var_name)] - (in (list (type_to_code var_type)))) + (in (list (type_code var_type)))) (^ (list expression)) (do meta_monad @@ -5717,7 +5722,7 @@ _ (failure ($_ text\compose "Invalid target platform (must be a value of type Text): " (name\encode identifier) - " : " (..code\encode (..type_to_code type)))))) + " : " (..code\encode (..type_code type)))))) _ (failure ($_ text\compose @@ -5919,7 +5924,7 @@ (^ (list [_ (#Tuple bindings)] bodyT)) (if (multiple? 2 (list\size bindings)) (return (list (` (..with_expansions [(~+ (|> bindings - ..as_pairs + ..pairs (list\map (function (_ [localT valueT]) (list localT (` (..as_is (~ valueT)))))) (list\fold list\compose (list))))] diff --git a/stdlib/source/library/lux/abstract/comonad.lux b/stdlib/source/library/lux/abstract/comonad.lux index 205958b26..2c1a731f3 100644 --- a/stdlib/source/library/lux/abstract/comonad.lux +++ b/stdlib/source/library/lux/abstract/comonad.lux @@ -59,7 +59,7 @@ (` (|> (~ value) (~ g!split) ((~ g!map) (function ((~ g!_) (~ var)) (~ body'))))) )))) body - (list.reverse (list.as_pairs bindings)))] + (list.reverse (list.pairs bindings)))] (#.Right [state (list (case ?name (#.Some name) (let [name [location.dummy (#.Identifier ["" name])]] diff --git a/stdlib/source/library/lux/abstract/monad.lux b/stdlib/source/library/lux/abstract/monad.lux index e4d739638..b1f9847e7 100644 --- a/stdlib/source/library/lux/abstract/monad.lux +++ b/stdlib/source/library/lux/abstract/monad.lux @@ -34,11 +34,11 @@ #.End xs)) -(def: (as_pairs xs) +(def: (pairs xs) (All [a] (-> (List a) (List [a a]))) (case xs (#.Item x1 (#.Item x2 xs')) - (#.Item [x1 x2] (as_pairs xs')) + (#.Item [x1 x2] (pairs xs')) _ #.End)) @@ -91,7 +91,7 @@ (` (|> (~ value) ((~ g!map) (function ((~ g!_) (~ var)) (~ body'))) (~ g!join))) )))) body - (reverse (as_pairs bindings)))] + (reverse (pairs bindings)))] (#.Right [state (list (case ?name (#.Some name) (let [name [location.dummy (#.Identifier ["" name])]] diff --git a/stdlib/source/library/lux/control/concatenative.lux b/stdlib/source/library/lux/control/concatenative.lux index 88ac4f0b9..9e3bfea18 100644 --- a/stdlib/source/library/lux/control/concatenative.lux +++ b/stdlib/source/library/lux/control/concatenative.lux @@ -90,16 +90,16 @@ (|> outputs (get@ #bottom) (maybe\map (|>> code.nat (~) #.Parameter (`))))] [(#.Some bottomI) (#.Some bottomO)] (monad.do meta.monad - [inputC (singleton (macro.expand_all (stack_fold (get@ #top inputs) bottomI))) - outputC (singleton (macro.expand_all (stack_fold (get@ #top outputs) bottomO)))] + [inputC (singleton (macro.full_expansion (stack_fold (get@ #top inputs) bottomI))) + outputC (singleton (macro.full_expansion (stack_fold (get@ #top outputs) bottomO)))] (in (list (` (-> (~ (de_alias inputC)) (~ (de_alias outputC))))))) [?bottomI ?bottomO] (with_gensyms [g!stack] (monad.do meta.monad - [inputC (singleton (macro.expand_all (stack_fold (get@ #top inputs) (maybe.default g!stack ?bottomI)))) - outputC (singleton (macro.expand_all (stack_fold (get@ #top outputs) (maybe.default g!stack ?bottomO))))] + [inputC (singleton (macro.full_expansion (stack_fold (get@ #top inputs) (maybe.default g!stack ?bottomI)))) + outputC (singleton (macro.full_expansion (stack_fold (get@ #top outputs) (maybe.default g!stack ?bottomO))))] (in (list (` (All [(~ g!stack)] (-> (~ (de_alias inputC)) (~ (de_alias outputC)))))))))))) diff --git a/stdlib/source/library/lux/control/concurrency/semaphore.lux b/stdlib/source/library/lux/control/concurrency/semaphore.lux index fc6f939c8..ea575915c 100644 --- a/stdlib/source/library/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/library/lux/control/concurrency/semaphore.lux @@ -161,7 +161,7 @@ [(def: ( (^:representation barrier)) (-> Barrier (Async Any)) (do async.monad - [#let [limit (refinement.un_refine (get@ #limit barrier)) + [#let [limit (refinement.value (get@ #limit barrier)) goal [_ count] (io.run (atom.update (get@ #count barrier))) reached? (n.= goal count)]] diff --git a/stdlib/source/library/lux/control/parser.lux b/stdlib/source/library/lux/control/parser.lux index d38044ec1..696ec7525 100644 --- a/stdlib/source/library/lux/control/parser.lux +++ b/stdlib/source/library/lux/control/parser.lux @@ -189,15 +189,14 @@ (at_most (dec amount) parser)) input'))))) -(def: #export (between from to parser) - {#.doc "Parse between N and M times."} +(def: #export (between minimum additional parser) (All [s a] (-> Nat Nat (Parser s a) (Parser s (List a)))) (do {! ..monad} - [minimum (..exactly from parser)] - (if (n.< to from) - (\ ! map (list\compose minimum) - (..at_most (n.- from to) parser)) - (in minimum)))) + [minimum (..exactly minimum parser)] + (case additional + 0 (in minimum) + _ (\ ! map (list\compose minimum) + (..at_most additional parser))))) (def: #export (separated_by separator parser) {#.doc "Parses instances of 'parser' that are separated by instances of 'separator'."} diff --git a/stdlib/source/library/lux/control/parser/text.lux b/stdlib/source/library/lux/control/parser/text.lux index aa4858f66..ce3aacdaf 100644 --- a/stdlib/source/library/lux/control/parser/text.lux +++ b/stdlib/source/library/lux/control/parser/text.lux @@ -322,7 +322,9 @@ [(def: #export ( amount parser) {#.doc (code.text ($_ /\compose "Yields " " N characters (as a slice)."))} (-> Nat (Parser Text) (Parser Text)) - (|> parser ( amount) (\ //.monad map /.concat)))] + (|> parser + ( amount) + (\ //.monad map /.concat)))] [exactly //.exactly "exactly"] [at_most //.at_most "at most"] @@ -333,22 +335,24 @@ [(def: #export ( amount parser) {#.doc (code.text ($_ /\compose "Yields " " N characters (as a slice)."))} (-> Nat (Parser Slice) (Parser Slice)) - (with_slices ( amount parser)))] + (with_slices + ( amount parser)))] [exactly! //.exactly "exactly"] [at_most! //.at_most "at most"] [at_least! //.at_least "at least"] ) -(def: #export (between from to parser) - {#.doc "Yields between N and M characters."} +(def: #export (between minimum additional parser) (-> Nat Nat (Parser Text) (Parser Text)) - (|> parser (//.between from to) (\ //.monad map /.concat))) + (|> parser + (//.between minimum additional) + (\ //.monad map /.concat))) -(def: #export (between! from to parser) - {#.doc "Yields between N and M characters (as a slice)."} +(def: #export (between! minimum additional parser) (-> Nat Nat (Parser Slice) (Parser Slice)) - (with_slices (//.between from to parser))) + (with_slices + (//.between minimum additional parser))) (def: #export (enclosed [start end] parser) (All [a] (-> [Text Text] (Parser a) (Parser a))) diff --git a/stdlib/source/library/lux/control/parser/tree.lux b/stdlib/source/library/lux/control/parser/tree.lux index 11673474c..ad2015624 100644 --- a/stdlib/source/library/lux/control/parser/tree.lux +++ b/stdlib/source/library/lux/control/parser/tree.lux @@ -26,7 +26,7 @@ (def: #export (run parser tree) {#.doc (doc "Applies the parser against a tree.")} (All [t a] (-> (Parser t a) (Tree t) (Try a))) - (run' parser (zipper.zip tree))) + (run' parser (zipper.zipper tree))) (def: #export value {#.doc (doc "Yields the value inside the current tree node.")} diff --git a/stdlib/source/library/lux/control/state.lux b/stdlib/source/library/lux/control/state.lux index 447b6428e..8d9d3116a 100644 --- a/stdlib/source/library/lux/control/state.lux +++ b/stdlib/source/library/lux/control/state.lux @@ -16,11 +16,11 @@ (function (_ state) [state state])) -(def: #export (put new-state) +(def: #export (put new_state) {#.doc "Set the new state."} (All [s] (-> s (State s Any))) (function (_ state) - [new-state []])) + [new_state []])) (def: #export (update change) {#.doc "Compute the new state."} diff --git a/stdlib/source/library/lux/control/thread.lux b/stdlib/source/library/lux/control/thread.lux index ec2e48153..236ded86b 100644 --- a/stdlib/source/library/lux/control/thread.lux +++ b/stdlib/source/library/lux/control/thread.lux @@ -15,6 +15,7 @@ abstract]]]) (type: #export (Thread ! a) + {#.doc (doc "An imperative process with access to mutable values.")} (-> ! a)) (abstract: #export (Box t v) @@ -23,6 +24,7 @@ {#.doc "A mutable box holding a value."} (def: #export (box init) + {#.doc (doc "A brand-new box initialized to the given value.")} (All [a] (-> a (All [!] (Thread ! (Box ! a))))) (function (_ !) (|> (array.new 1) @@ -30,6 +32,7 @@ :abstraction))) (def: #export (read box) + {#.doc (doc "Reads the current value in the box.")} (All [! a] (-> (Box ! a) (Thread ! a))) (function (_ !) (for {@.old @@ -51,18 +54,21 @@ @.scheme ("scheme array read" 0 (:representation box))}))) (def: #export (write value box) + {#.doc (doc "Mutates the value in the box.")} (All [a] (-> a (All [!] (-> (Box ! a) (Thread ! Any))))) (function (_ !) (|> box :representation (array.write! 0 value) :abstraction))) ) (def: #export (run thread) + {#.doc (doc "Executes the imperative thread in a self-contained way.")} (All [a] (-> (All [!] (Thread ! a)) a)) (thread [])) (def: #export io + {#.doc (doc "Transforms the imperative thread into an I/O computation.")} (All [a] (-> (All [!] (Thread ! a)) (IO a))) @@ -99,7 +105,8 @@ ((ffa !) !)))) (def: #export (update f box) - (All [a] (-> (-> a a) (All [!] (-> (Box ! a) (Thread ! a))))) + {#.doc (doc "Update a box's value by applying a function to it.")} + (All [a !] (-> (-> a a) (Box ! a) (Thread ! a))) (do ..monad [old (read box) _ (write (f old) box)] diff --git a/stdlib/source/library/lux/control/try.lux b/stdlib/source/library/lux/control/try.lux index 52f58495a..4a6a35678 100644 --- a/stdlib/source/library/lux/control/try.lux +++ b/stdlib/source/library/lux/control/try.lux @@ -10,6 +10,7 @@ ["." location]]]]) (type: #export (Try a) + {#.doc (doc "A computation that can fail with an error message.")} (#Failure Text) (#Success a)) @@ -59,12 +60,16 @@ ma))) (implementation: #export (with monad) - ## TODO: Replace (All [a] (M (Try a))) with (functor.Then M Try) - (All [M] (-> (Monad M) (Monad (All [a] (M (Try a)))))) + {#.doc (doc "Enhances a monad with error-handling functionality.")} + ## TODO: Replace (All [a] (! (Try a))) with (functor.Then ! Try) + (All [!] (-> (Monad !) (Monad (All [a] (! (Try a)))))) - (def: &functor (functor.compose (get@ #monad.&functor monad) ..functor)) + (def: &functor + (functor.compose (get@ #monad.&functor monad) ..functor)) - (def: in (|>> (\ ..monad in) (\ monad in))) + (def: in + (|>> (\ ..monad in) + (\ monad in))) (def: (join MeMea) (do monad @@ -77,7 +82,8 @@ Mea)))) (def: #export (lifted monad) - (All [M a] (-> (Monad M) (-> (M a) (M (Try a))))) + {#.doc (doc "Wraps a monadic value with error-handling machinery.")} + (All [! a] (-> (Monad !) (-> (! a) (! (Try a))))) (\ monad map (\ ..monad in))) (implementation: #export (equivalence (^open "_\.")) @@ -96,6 +102,8 @@ ))) (def: #export (assumed try) + {#.doc (doc "Assumes a Try value succeeded." + "If it didn't, raises the error as a runtime error.")} (All [a] (-> (Try a) a)) (case try (#Success value) diff --git a/stdlib/source/library/lux/control/writer.lux b/stdlib/source/library/lux/control/writer.lux index 8fd8e9492..066b4ef58 100644 --- a/stdlib/source/library/lux/control/writer.lux +++ b/stdlib/source/library/lux/control/writer.lux @@ -51,6 +51,7 @@ [(\ monoid compose log1 log2) a]))) (implementation: #export (with monoid monad) + {#.doc (doc "Enhances a monad with Writer functionality.")} (All [l M] (-> (Monoid l) (Monad M) (Monad (All [a] (M (Writer l a)))))) (def: &functor @@ -72,6 +73,7 @@ (in [(\ monoid compose l1 l2) a])))) (def: #export (lift monoid monad) + {#.doc (doc "Wraps a monadic value with Writer machinery.")} (All [l M a] (-> (Monoid l) (Monad M) (-> (M a) (M (Writer l a))))) diff --git a/stdlib/source/library/lux/data/collection/array.lux b/stdlib/source/library/lux/data/collection/array.lux index c1b5cd7bc..96b082211 100644 --- a/stdlib/source/library/lux/data/collection/array.lux +++ b/stdlib/source/library/lux/data/collection/array.lux @@ -36,6 +36,7 @@ (as_is)) (def: #export (new size) + {#.doc (doc "An empty array of the specified size.")} (All [a] (-> Nat (Array a))) (for {@.old (:assume ("jvm anewarray" "(java.lang.Object )" size)) @@ -108,6 +109,7 @@ #.None)) (def: #export (write! index value array) + {#.doc (doc "Mutate the array by writing a value to the specified index.")} (All [a] (-> Nat a (Array a) (Array a))) (for {@.old @@ -127,6 +129,7 @@ @.scheme ("scheme array write" index value array)})) (def: #export (delete! index array) + {#.doc (doc "Mutate the array by deleting the value at the specified index.")} (All [a] (-> Nat (Array a) (Array a))) (if (n.< (size array) index) @@ -156,6 +159,7 @@ false)) (def: #export (update! index transform array) + {#.doc (doc "Mutate the array by updating the value at the specified index.")} (All [a] (-> Nat (-> a a) (Array a) (Array a))) (case (read index array) @@ -166,6 +170,8 @@ (write! index (transform value) array))) (def: #export (upsert! index default transform array) + {#.doc (doc "Mutate the array by updating the value at the specified index." + "If there is no value, update and write the default value given.")} (All [a] (-> Nat a (-> a a) (Array a) (Array a))) (write! index @@ -173,6 +179,7 @@ array)) (def: #export (copy! length src_start src_array dest_start dest_array) + {#.doc (doc "Writes the contents of one array into the other.")} (All [a] (-> Nat Nat (Array a) Nat (Array a) (Array a))) @@ -207,6 +214,7 @@ (n.- (..occupancy array) (..size array))) (def: #export (filter! p xs) + {#.doc (doc "Delete every item of the array that fails to satisfy the predicate.")} (All [a] (-> (Predicate a) (Array a) (Array a))) (list\fold (function (_ idx xs') @@ -222,6 +230,7 @@ (list.indices (size xs)))) (def: #export (find p xs) + {#.doc (doc "Yields the first item in the array that satisfies the predicate.")} (All [a] (-> (Predicate a) (Array a) (Maybe a))) (let [arr_size (size xs)] @@ -255,6 +264,7 @@ #.None)))) (def: #export (clone xs) + {#.doc (doc "Yields a shallow clone of the array.")} (All [a] (-> (Array a) (Array a))) (let [arr_size (size xs)] (list\fold (function (_ idx ys) @@ -274,9 +284,12 @@ [0 (new (list.size xs))] xs))) -(def: underflow Nat (dec 0)) +(def: underflow + Nat + (dec 0)) (def: #export (to_list array) + {#.doc (doc "Yields a list with every non-empty item in the array.")} (All [a] (-> (Array a) (List a))) (loop [idx (dec (size array)) output #.End] @@ -291,6 +304,7 @@ output))))) (def: #export (to_list' default array) + {#.doc (doc "Like 'to_list', but uses the 'default' value when encountering an empty cell in the array.")} (All [a] (-> a (Array a) (List a))) (loop [idx (dec (size array)) output #.End] @@ -368,20 +382,21 @@ so_far))))) (template [ ] - [(def: #export ( predicate array) + [(def: #export ( predicate) (All [a] (-> (Predicate a) (Predicate (Array a)))) - (let [size (..size array)] - (loop [idx 0] - (if (n.< size idx) - (case (..read idx array) - (#.Some value) - ( (predicate value) - (recur (inc idx))) - - #.None - (recur (inc idx))) - ))))] + (function (_ array) + (let [size (..size array)] + (loop [idx 0] + (if (n.< size idx) + (case (..read idx array) + (#.Some value) + ( (predicate value) + (recur (inc idx))) + + #.None + (recur (inc idx))) + )))))] [every? true and] [any? false or] diff --git a/stdlib/source/library/lux/data/collection/bits.lux b/stdlib/source/library/lux/data/collection/bits.lux index c90cff48c..6066bd0c2 100644 --- a/stdlib/source/library/lux/data/collection/bits.lux +++ b/stdlib/source/library/lux/data/collection/bits.lux @@ -21,6 +21,7 @@ i64.width) (type: #export Bits + {#.doc (doc "A bit-map.")} (Array Chunk)) (def: empty_chunk @@ -32,6 +33,7 @@ (array.new 0)) (def: #export (size bits) + {#.doc (doc "Measures the size of a bit-map by counting all the 1s in the bit-map.")} (-> Bits Nat) (array\fold (function (_ chunk total) (|> chunk i64.count (n.+ total))) @@ -44,7 +46,7 @@ (def: #export empty? (-> Bits Bit) - (|>> size (n.= 0))) + (|>> ..size (n.= 0))) (def: #export (get index bits) (-> Nat Bits Bit) diff --git a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux index fcac55d8a..0b8976411 100644 --- a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux +++ b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux @@ -11,7 +11,8 @@ [collection ["." list ("#\." monoid fold)]]] [macro - ["." code]] + ["." code] + ["." template]] [math [number ["n" nat]]]]]) @@ -44,10 +45,12 @@ ) (type: #export (Dictionary k v) + {#.doc (doc "A dictionary data-structure with ordered entries.")} {#&order (Order k) #root (Maybe (Node k v))}) (def: #export (new order) + {#.doc (doc "An empty dictionary, employing the given order.")} (All [k v] (-> (Order k) (Dictionary k v))) {#&order order #root #.None}) @@ -99,6 +102,7 @@ (template [ ] [(def: #export ( dict) + {#.doc (doc (~~ (template.text ["Yields value under the " "imum key."])))} (All [k v] (-> (Dictionary k v) (Maybe v))) (case (get@ #root dict) #.None @@ -538,11 +542,11 @@ #.None dict)) -(def: #export (of_list Order list) +(def: #export (of_list order list) (All [k v] (-> (Order k) (List [k v]) (Dictionary k v))) (list\fold (function (_ [key value] dict) (put key value dict)) - (new Order) + (new order) list)) (template [ ] diff --git a/stdlib/source/library/lux/data/collection/dictionary/plist.lux b/stdlib/source/library/lux/data/collection/dictionary/plist.lux index ac7cbcf6f..03025db7e 100644 --- a/stdlib/source/library/lux/data/collection/dictionary/plist.lux +++ b/stdlib/source/library/lux/data/collection/dictionary/plist.lux @@ -12,7 +12,10 @@ [number ["n" nat]]]]]) +## https://en.wikipedia.org/wiki/Property_list (type: #export (PList a) + {#.doc (doc "A property list." + "It's a simple dictionary-like structure with Text keys.")} (List [Text a])) (def: #export empty diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index feaebb373..ee500594b 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -75,13 +75,13 @@ [(#.Item head in) out] [in (#.Item head out)])))) -(def: #export (as_pairs xs) +(def: #export (pairs xs) {#.doc (doc "Cut the list into pairs of 2." - "Caveat emptor: If the list has an uneven number of elements, the last one will be skipped.")} + "Caveat emptor: If the list has an un-even number of elements, the last one will be skipped.")} (All [a] (-> (List a) (List [a a]))) (case xs (^ (list& x1 x2 xs')) - (#.Item [x1 x2] (as_pairs xs')) + (#.Item [x1 x2] (pairs xs')) _ #.End)) diff --git a/stdlib/source/library/lux/data/collection/queue/priority.lux b/stdlib/source/library/lux/data/collection/queue/priority.lux index 0b25c11fe..8f0a788fc 100644 --- a/stdlib/source/library/lux/data/collection/queue/priority.lux +++ b/stdlib/source/library/lux/data/collection/queue/priority.lux @@ -18,8 +18,13 @@ (type: #export Priority Nat) -(def: #export max Priority n\top) -(def: #export min Priority n\bottom) +(def: #export max + Priority + n\top) + +(def: #export min + Priority + n\bottom) (def: builder (tree.builder n.maximum)) diff --git a/stdlib/source/library/lux/data/collection/set/multi.lux b/stdlib/source/library/lux/data/collection/set/multi.lux index 14ee02181..155217b81 100644 --- a/stdlib/source/library/lux/data/collection/set/multi.lux +++ b/stdlib/source/library/lux/data/collection/set/multi.lux @@ -22,6 +22,8 @@ (abstract: #export (Set a) (Dictionary a Nat) + {#.doc (doc "A set that keeps track of repetition in its entries.")} + (def: #export new (All [a] (-> (Hash a) (Set a))) (|>> dictionary.new :abstraction)) @@ -94,6 +96,7 @@ subject))) (def: #export (sub? reference subject) + {#.doc (doc "Is 'subject' a sub-set of 'reference'?")} (All [a] (-> (Set a) (Set a) Bit)) (|> subject :representation @@ -104,6 +107,7 @@ (n.>= multiplicity)))))) (def: #export (support set) + {#.doc (doc "A set of the unique (non repeated) members.")} (All [a] (-> (Set a) (//.Set a))) (let [(^@ set [hash _]) (:representation set)] (|> set @@ -154,5 +158,6 @@ (//.to_list subject))) (def: #export super? + {#.doc (doc "Is 'subject' a super-set of 'reference'?")} (All [a] (-> (Set a) (Set a) Bit)) (function.flip sub?)) diff --git a/stdlib/source/library/lux/data/collection/set/ordered.lux b/stdlib/source/library/lux/data/collection/set/ordered.lux index e53e3398e..fbe72bada 100644 --- a/stdlib/source/library/lux/data/collection/set/ordered.lux +++ b/stdlib/source/library/lux/data/collection/set/ordered.lux @@ -15,6 +15,8 @@ (abstract: #export (Set a) (/.Dictionary a a) + {#.doc (doc "A set with ordered entries.")} + (def: #export new (All [a] (-> (Order a) (Set a))) (|>> /.new :abstraction)) @@ -75,11 +77,13 @@ ) (def: #export (sub? super sub) + {#.doc (doc "Is 'sub' a sub-set of 'super'?")} (All [a] (-> (Set a) (Set a) Bit)) (|> sub ..to_list (list.every? (..member? super)))) (def: #export (super? sub super) + {#.doc (doc "Is 'super' a super-set of 'sub'?")} (All [a] (-> (Set a) (Set a) Bit)) (sub? super sub)) diff --git a/stdlib/source/library/lux/data/collection/tree/finger.lux b/stdlib/source/library/lux/data/collection/tree/finger.lux index 1e986da40..be444ba1a 100644 --- a/stdlib/source/library/lux/data/collection/tree/finger.lux +++ b/stdlib/source/library/lux/data/collection/tree/finger.lux @@ -10,13 +10,17 @@ [type [abstract (#+ abstract: :abstraction :representation)]]]]) +## https://en.wikipedia.org/wiki/Finger_tree (abstract: #export (Tree @ t v) {#monoid (Monoid t) #tag t #root (| v [(Tree @ t v) (Tree @ t v)])} + {#.doc (doc "A finger tree.")} + (interface: #export (Builder @ t) + {#.doc (doc "A builder for finter tree structures.")} (: (All [v] (-> t v (Tree @ t v))) leaf) @@ -36,6 +40,7 @@ ) (implementation: #export (builder monoid) + {#.doc (doc "A new builder using the given monoid.")} (All [t] (Ex [@] (-> (Monoid t) (Builder @ t)))) (def: (leaf tag value) @@ -80,6 +85,7 @@ (values right)))) (def: #export (one predicate tree) + {#.doc (doc "Finds one value that meets the predicate.")} (All [@ t v] (-> (Predicate t) (Tree @ t v) (Maybe v))) (let [[monoid tag root] (:representation tree)] (if (predicate tag) @@ -99,6 +105,7 @@ ) (def: #export (exists? predicate tree) + {#.doc (doc "Verifies that a value exists which meets the predicate.")} (All [@ t v] (-> (Predicate t) (Tree @ t v) Bit)) (case (..one predicate tree) (#.Some _) diff --git a/stdlib/source/library/lux/data/collection/tree/zipper.lux b/stdlib/source/library/lux/data/collection/tree/zipper.lux index 998b75c3e..4c1def087 100644 --- a/stdlib/source/library/lux/data/collection/tree/zipper.lux +++ b/stdlib/source/library/lux/data/collection/tree/zipper.lux @@ -21,6 +21,7 @@ #lefts (List (Tree a)) #rights (List (Tree a))}) +## https://en.wikipedia.org/wiki/Zipper_(data_structure) (type: #export (Zipper a) {#.doc "Tree zippers, for easy navigation and editing of trees."} {#family (Maybe (Family Zipper a)) @@ -41,12 +42,12 @@ (//.equivalence super))] (== reference sample)))) -(def: #export (zip tree) +(def: #export (zipper tree) (All [a] (-> (Tree a) (Zipper a))) {#family #.None #node tree}) -(def: #export unzip +(def: #export tree (All [a] (-> (Zipper a) (Tree a))) (get@ #node)) @@ -54,13 +55,13 @@ (All [a] (-> (Zipper a) a)) (get@ [#node #//.value])) -(def: #export set +(def: #export (set value zipper) (All [a] (-> a (Zipper a) (Zipper a))) - (set@ [#node #//.value])) + (set@ [#node #//.value] value zipper)) -(def: #export update +(def: #export (update transform zipper) (All [a] (-> (-> a a) (Zipper a) (Zipper a))) - (update@ [#node #//.value])) + (update@ [#node #//.value] transform zipper)) (def: children (All [a] (-> (Zipper a) (List (Tree a)))) @@ -306,7 +307,7 @@ (def: (split (^slots [#family #node])) (let [tree_splitter (: (All [a] (-> (Tree a) (Tree (Zipper a)))) (function (tree_splitter tree) - {#//.value (..zip tree) + {#//.value (..zipper tree) #//.children (|> tree (get@ #//.children) (list\map tree_splitter))}))] diff --git a/stdlib/source/library/lux/data/format/css.lux b/stdlib/source/library/lux/data/format/css.lux index d94f97cd9..f2f991da2 100644 --- a/stdlib/source/library/lux/data/format/css.lux +++ b/stdlib/source/library/lux/data/format/css.lux @@ -43,7 +43,7 @@ (-> Encoding (CSS Special)) (|>> encoding.name %.text - (text.enclose ["@charset " ";"]) + (text.enclosed ["@charset " ";"]) :abstraction)) (def: #export (font font) @@ -65,7 +65,7 @@ (list\map (function (_ [property value]) (format property ": " value ";"))) (text.join_with /style.separator) - (text.enclose ["{" "}"]) + (text.enclosed ["{" "}"]) (format "@font-face") :abstraction))) diff --git a/stdlib/source/library/lux/data/format/css/selector.lux b/stdlib/source/library/lux/data/format/css/selector.lux index 330f6a907..08f2165da 100644 --- a/stdlib/source/library/lux/data/format/css/selector.lux +++ b/stdlib/source/library/lux/data/format/css/selector.lux @@ -151,14 +151,14 @@ (-> Locale (Selector Can_Chain)) (|> locale locale.code - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) (format ":lang") :abstraction)) (def: #export not (-> (Selector Any) (Selector Can_Chain)) (|>> :representation - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) (format ":not") :abstraction)) @@ -192,7 +192,7 @@ [(def: #export ( index) (-> Index (Selector Can_Chain)) (|> (:representation index) - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) (format ) (:abstraction Selector)))] diff --git a/stdlib/source/library/lux/data/format/css/value.lux b/stdlib/source/library/lux/data/format/css/value.lux index 1b69f1496..e49c06687 100644 --- a/stdlib/source/library/lux/data/format/css/value.lux +++ b/stdlib/source/library/lux/data/format/css/value.lux @@ -783,7 +783,7 @@ (-> Text (List Text) Value) (|> inputs (text.join_with ..value_separator) - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) (format name) :abstraction)) @@ -1199,7 +1199,7 @@ (|>> (list\map (|>> (list\map (|>> (maybe.default empty) :representation)) (text.join_with ..grid_column_separator) - (text.enclose ["'" "'"]))) + (text.enclosed ["'" "'"]))) (text.join_with ..grid_row_separator) :abstraction))) diff --git a/stdlib/source/library/lux/data/format/html.lux b/stdlib/source/library/lux/data/format/html.lux index a96a6df84..419096680 100644 --- a/stdlib/source/library/lux/data/format/html.lux +++ b/stdlib/source/library/lux/data/format/html.lux @@ -70,11 +70,11 @@ (|> attributes ..attributes (format tag " ") - (text.enclose ["<" ">"]))) + (text.enclosed ["<" ">"]))) (def: close (-> Tag Text) - (text.enclose [""])) + (text.enclosed [""])) (abstract: #export (HTML brand) Text @@ -127,7 +127,7 @@ (def: #export (comment content node) (All [brand] (-> Text (HTML brand) (HTML brand))) (:abstraction - (format (text.enclose [""] content) + (format (text.enclosed [""] content) (:representation node)))) (def: (empty name attributes) diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux index 417e7791d..8f3293e56 100644 --- a/stdlib/source/library/lux/data/format/json.lux +++ b/stdlib/source/library/lux/data/format/json.lux @@ -234,7 +234,7 @@ (def: string_format (-> String Text) (|>> (text.replace_all text.double_quote ..escaped_dq) - (text.enclose [text.double_quote text.double_quote]))) + (text.enclosed [text.double_quote text.double_quote]))) (template [ ] [(def: @@ -256,7 +256,7 @@ (|>> (row\map format) row.to_list (text.join_with ..separator) - (text.enclose [..open_array ..close_array]))) + (text.enclosed [..open_array ..close_array]))) (def: (kv_format format [key value]) (-> (-> JSON Text) (-> [String JSON] Text)) @@ -271,7 +271,7 @@ (|>> dictionary.entries (list\map (..kv_format format)) (text.join_with ..separator) - (text.enclose [..open_object ..close_object]))) + (text.enclosed [..open_object ..close_object]))) (def: #export (format json) (-> JSON Text) diff --git a/stdlib/source/library/lux/data/format/markdown.lux b/stdlib/source/library/lux/data/format/markdown.lux index 68af40458..2fbef2fa0 100644 --- a/stdlib/source/library/lux/data/format/markdown.lux +++ b/stdlib/source/library/lux/data/format/markdown.lux @@ -77,7 +77,7 @@ [(def: #export (-> (Markdown Span) (Markdown Span)) (|>> :representation - (text.enclose [ ]) + (text.enclosed [ ]) :abstraction))] [bold "**"] @@ -111,7 +111,7 @@ (format (%.nat (inc idx)) ". " (:representation summary) text.new_line (case detail (#.Some detail) - (|> detail :representation ..indent (text.enclose [text.new_line text.new_line])) + (|> detail :representation ..indent (text.enclosed [text.new_line text.new_line])) #.None "")))) @@ -125,7 +125,7 @@ (format "*. " (:representation summary) text.new_line (case detail (#.Some detail) - (|> detail :representation ..indent (text.enclose [text.new_line text.new_line])) + (|> detail :representation ..indent (text.enclosed [text.new_line text.new_line])) #.None "")))) @@ -135,14 +135,14 @@ (def: #export snippet {#.doc "A snippet of code."} (-> Text (Markdown Span)) - (|>> ..safe (text.enclose ["`" "`"]) :abstraction)) + (|>> ..safe (text.enclosed ["`" "`"]) :abstraction)) (def: #export code {#.doc "A block of code."} (-> Text (Markdown Block)) (let [open (format "```" text.new_line) close (format text.new_line "```")] - (|>> (text.enclose [open close]) ..block))) + (|>> (text.enclosed [open close]) ..block))) (def: #export (image description url) (-> Text URL (Markdown Span)) @@ -162,7 +162,7 @@ (template [ ] [(def: #export (-> (Markdown Span)) - (|>> (text.enclose ["<" ">"]) :abstraction))] + (|>> (text.enclosed ["<" ">"]) :abstraction))] [url URL] [email Email] diff --git a/stdlib/source/library/lux/data/format/tar.lux b/stdlib/source/library/lux/data/format/tar.lux index d216a1ef8..d5dad8d9b 100644 --- a/stdlib/source/library/lux/data/format/tar.lux +++ b/stdlib/source/library/lux/data/format/tar.lux @@ -8,7 +8,7 @@ ["." try (#+ Try)] ["." exception (#+ exception:)] ["<>" parser - ["" binary (#+ Parser)]]] + ["<.>" binary (#+ Parser)]]] [data ["." product] ["." binary (#+ Binary)] @@ -100,11 +100,11 @@ [not_a_small_number small_limit ..small_size Small small from_small small_writer (format ..blank ..null) - coerce_small] + as_small] [not_a_big_number big_limit ..big_size Big big from_big big_writer ..blank - coerce_big] + as_big] ) (exception: #export (wrong_character {expected Char} {actual Char}) @@ -115,8 +115,8 @@ (def: verify_small_suffix (Parser Any) (do <>.monad - [pre_end .bits/8 - end .bits/8 + [pre_end .bits/8 + end .bits/8 _ (let [expected (`` (char (~~ (static ..blank))))] (<>.assert (exception.construct ..wrong_character [expected pre_end]) (n.= expected pre_end))) @@ -128,7 +128,7 @@ (def: small_parser (Parser Small) (do <>.monad - [digits (.segment ..small_size) + [digits (.segment ..small_size) digits (<>.lift (\ utf8.codec decode digits)) _ ..verify_small_suffix] (<>.lift @@ -139,9 +139,9 @@ (def: big_parser (Parser Big) (do <>.monad - [digits (.segment ..big_size) + [digits (.segment ..big_size) digits (<>.lift (\ utf8.codec decode digits)) - end .bits/8 + end .bits/8 _ (let [expected (`` (char (~~ (static ..blank))))] (<>.assert (exception.construct ..wrong_character [expected end]) (n.= expected end)))] @@ -177,7 +177,7 @@ (def: checksum_code (-> Binary Checksum) (|>> ..checksum - ..coerce_small + ..as_small ..from_small (\ n.octal encode) (..octal_padding ..small_size) @@ -195,7 +195,7 @@ (def: checksum_parser (Parser [Nat Checksum]) (do <>.monad - [ascii (.segment ..small_size) + [ascii (.segment ..small_size) digits (<>.lift (\ utf8.codec decode ascii)) _ ..verify_small_suffix value (<>.lift @@ -273,8 +273,8 @@ (def: (Parser ) (do <>.monad - [string (.segment ) - end .bits/8 + [string (.segment ) + end .bits/8 #let [expected (`` (char (~~ (static ..null))))] _ (<>.assert (exception.construct ..wrong_character [expected end]) (n.= expected end))] @@ -315,8 +315,8 @@ (def: magic_parser (Parser Magic) (do <>.monad - [string (.segment ..magic_size) - end .bits/8 + [string (.segment ..magic_size) + end .bits/8 #let [expected (`` (char (~~ (static ..null))))] _ (<>.assert (exception.construct ..wrong_character [expected end]) (n.= expected end))] @@ -417,7 +417,7 @@ (def: link_flag_parser (Parser Link_Flag) (do <>.monad - [linkflag .bits/8] + [linkflag .bits/8] (case (.nat linkflag) (^template [ ] [(^ ) @@ -540,7 +540,7 @@ (def: #export no_id ID - (..coerce_small 0)) + (..as_small 0)) (type: #export Owner {#name Name @@ -638,7 +638,7 @@ (|>> instant.relative (duration.query duration.second) .nat - ..coerce_big)) + ..as_big)) (def: (file_writer link_flag) (-> Link_Flag (Writer File)) @@ -678,8 +678,8 @@ #mode ..none #user_id ..no_id #group_id ..no_id - #size (..coerce_big 0) - #modification_time (..coerce_big 0) + #size (..as_big 0) + #modification_time (..as_big 0) #checksum ..dummy_checksum #link_flag ..symbolic_link #link_name path @@ -696,8 +696,8 @@ #mode ..none #user_id ..no_id #group_id ..no_id - #size (..coerce_big 0) - #modification_time (..coerce_big 0) + #size (..as_big 0) + #modification_time (..as_big 0) #checksum ..dummy_checksum #link_flag ..directory #link_name ..no_path @@ -753,7 +753,7 @@ (def: header_parser (Parser Header) (do <>.monad - [binary_header (<>.speculative (.segment block_size)) + [binary_header (<>.speculative (.segment block_size)) path ..path_parser mode ..mode_parser user_id ..small_parser @@ -772,7 +772,7 @@ group_name ..name_parser major_device ..small_parser minor_device ..small_parser - _ (.segment ..header_padding_size)] + _ (.segment ..header_padding_size)] (in {#path path #mode mode #user_id user_id @@ -801,9 +801,9 @@ (is? expected (get@ #link_flag header))) #let [size (get@ #size header) rounded_size (..rounded_content_size size)] - content (.segment (..from_big size)) + content (.segment (..from_big size)) content (<>.lift (..content content)) - _ (.segment (n.- (..from_big size) rounded_size))] + _ (.segment (n.- (..from_big size) rounded_size))] (in [(get@ #path header) (|> header (get@ #modification_time) @@ -847,7 +847,7 @@ (def: end_of_archive_block_parser (Parser Any) (do <>.monad - [block (.segment ..block_size)] + [block (.segment ..block_size)] (let [actual (..checksum block)] (<>.lift (exception.assert ..wrong_checksum [0 actual] @@ -859,7 +859,7 @@ (Parser Any) (do <>.monad [_ (<>.at_most 2 end_of_archive_block_parser) - done? .end?] + done? .end?] (<>.lift (exception.assert ..invalid_end_of_archive [] done?)))) diff --git a/stdlib/source/library/lux/data/text.lux b/stdlib/source/library/lux/data/text.lux index 1ab453032..d9abb0f48 100644 --- a/stdlib/source/library/lux/data/text.lux +++ b/stdlib/source/library/lux/data/text.lux @@ -108,7 +108,7 @@ _ false)) -(def: #export (encloses? boundary value) +(def: #export (enclosed_by? boundary value) (-> Text Text Bit) (and (starts_with? boundary value) (ends_with? boundary value))) @@ -130,19 +130,19 @@ (-> Text Text Text) ("lux text concat" subject param)) -(def: #export (enclose [left right] content) +(def: #export (enclosed [left right] content) {#.doc "Surrounds the given content text with left and right side additions."} (-> [Text Text] Text Text) ($_ "lux text concat" left content right)) -(def: #export (enclose' boundary content) +(def: #export (enclosed' boundary content) {#.doc "Surrounds the given content text with the same boundary text."} (-> Text Text Text) - (enclose [boundary boundary] content)) + (enclosed [boundary boundary] content)) (def: #export format (-> Text Text) - (..enclose' ..double_quote)) + (..enclosed' ..double_quote)) (def: #export (clip offset characters input) (-> Nat Nat Text (Maybe Text)) diff --git a/stdlib/source/library/lux/data/text/format.lux b/stdlib/source/library/lux/data/text/format.lux index 5b59cf98a..cf4b3e2d4 100644 --- a/stdlib/source/library/lux/data/text/format.lux +++ b/stdlib/source/library/lux/data/text/format.lux @@ -122,7 +122,7 @@ (All [a] (-> (Format a) (Format (List a)))) (|>> (list\map (|>> formatter (format " "))) (text.join_with "") - (text.enclose ["(list" ")"]))) + (text.enclosed ["(list" ")"]))) (def: #export (maybe format) (All [a] (-> (Format a) (Format (Maybe a)))) diff --git a/stdlib/source/library/lux/data/text/regex.lux b/stdlib/source/library/lux/data/text/regex.lux index 63aca69fb..691fccad7 100644 --- a/stdlib/source/library/lux/data/text/regex.lux +++ b/stdlib/source/library/lux/data/text/regex.lux @@ -6,9 +6,10 @@ monad] [control ["." try] + ["." exception (#+ exception:)] ["<>" parser ("#\." monad) - ["" text (#+ Parser)] - ["" code]]] + ["<.>" text (#+ Parser)] + ["<.>" code]]] [data ["." product] ["." maybe] @@ -25,31 +26,31 @@ (def: regex_char^ (Parser Text) - (.none_of "\.|&()[]{}")) + (.none_of "\.|&()[]{}")) (def: escaped_char^ (Parser Text) (do <>.monad - [? (<>.parses? (.this "\"))] + [? (<>.parses? (.this "\"))] (if ? - .any + .any regex_char^))) (def: (refine^ refinement^ base^) (All [a] (-> (Parser a) (Parser Text) (Parser Text))) (do <>.monad [output base^ - _ (.local output refinement^)] + _ (.local output refinement^)] (in output))) (def: word^ (Parser Text) - (<>.either .alpha_num - (.one_of "_"))) + (<>.either .alpha_num + (.one_of "_"))) (def: (copy reference) (-> Text (Parser Text)) - (<>.after (.this reference) (<>\in reference))) + (<>.after (.this reference) (<>\in reference))) (def: (join_text^ part^) (-> (Parser (List Text)) (Parser Text)) @@ -59,37 +60,37 @@ (def: name_char^ (Parser Text) - (.none_of (format "[]{}()s#.<>" //.double_quote))) + (.none_of (format "[]{}()s#.<>" //.double_quote))) (def: name_part^ (Parser Text) (do <>.monad - [head (refine^ (.not .decimal) + [head (refine^ (.not .decimal) name_char^) - tail (.some name_char^)] + tail (.some name_char^)] (in (format head tail)))) (def: (name^ current_module) (-> Text (Parser Name)) ($_ <>.either - (<>.and (<>\in current_module) (<>.after (.this "..") name_part^)) - (<>.and name_part^ (<>.after (.this ".") name_part^)) - (<>.and (<>\in .prelude_module) (<>.after (.this ".") name_part^)) + (<>.and (<>\in current_module) (<>.after (.this "..") name_part^)) + (<>.and name_part^ (<>.after (.this ".") name_part^)) + (<>.and (<>\in .prelude_module) (<>.after (.this ".") name_part^)) (<>.and (<>\in "") name_part^))) (def: (re_var^ current_module) (-> Text (Parser Code)) (do <>.monad - [name (.enclosed ["\@<" ">"] (name^ current_module))] + [name (.enclosed ["\@<" ">"] (name^ current_module))] (in (` (: (Parser Text) (~ (code.identifier name))))))) (def: re_range^ (Parser Code) (do {! <>.monad} [from (|> regex_char^ (\ ! map (|>> (//.nth 0) maybe.assume))) - _ (.this "-") + _ (.this "-") to (|> regex_char^ (\ ! map (|>> (//.nth 0) maybe.assume)))] - (in (` (.range (~ (code.nat from)) (~ (code.nat to))))))) + (in (` (.range (~ (code.nat from)) (~ (code.nat to))))))) (def: re_char^ (Parser Code) @@ -100,18 +101,18 @@ (def: re_options^ (Parser Code) (do <>.monad - [options (.many escaped_char^)] - (in (` (.one_of (~ (code.text options))))))) + [options (.many escaped_char^)] + (in (` (.one_of (~ (code.text options))))))) (def: re_user_class^' (Parser Code) (do <>.monad - [negate? (<>.maybe (.this "^")) + [negate? (<>.maybe (.this "^")) parts (<>.many ($_ <>.either re_range^ re_options^))] (in (case negate? - (#.Some _) (` (.not ($_ <>.either (~+ parts)))) + (#.Some _) (` (.not ($_ <>.either (~+ parts)))) #.None (` ($_ <>.either (~+ parts))))))) (def: re_user_class^ @@ -119,7 +120,7 @@ (do <>.monad [_ (in []) init re_user_class^' - rest (<>.some (<>.after (.this "&&") (.enclosed ["[" "]"] re_user_class^')))] + rest (<>.some (<>.after (.this "&&") (.enclosed ["[" "]"] re_user_class^')))] (in (list\fold (function (_ refinement base) (` ((~! refine^) (~ refinement) (~ base)))) init @@ -127,80 +128,80 @@ (def: blank^ (Parser Text) - (.one_of (format " " //.tab))) + (.one_of (format " " //.tab))) (def: ascii^ (Parser Text) - (.range (hex "0") (hex "7F"))) + (.range (hex "0") (hex "7F"))) (def: control^ (Parser Text) - (<>.either (.range (hex "0") (hex "1F")) - (.one_of (//.of_code (hex "7F"))))) + (<>.either (.range (hex "0") (hex "1F")) + (.one_of (//.of_code (hex "7F"))))) (def: punct^ (Parser Text) - (.one_of (format "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~" - //.double_quote))) + (.one_of (format "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~" + //.double_quote))) (def: graph^ (Parser Text) - (<>.either punct^ .alpha_num)) + (<>.either punct^ .alpha_num)) (def: print^ (Parser Text) (<>.either graph^ - (.one_of (//.of_code (hex "20"))))) + (.one_of (//.of_code (hex "20"))))) (def: re_system_class^ (Parser Code) (do <>.monad [] ($_ <>.either - (<>.after (.this ".") (in (` .any))) - (<>.after (.this "\d") (in (` .decimal))) - (<>.after (.this "\D") (in (` (.not .decimal)))) - (<>.after (.this "\s") (in (` .space))) - (<>.after (.this "\S") (in (` (.not .space)))) - (<>.after (.this "\w") (in (` (~! word^)))) - (<>.after (.this "\W") (in (` (.not (~! word^))))) - - (<>.after (.this "\p{Lower}") (in (` .lower))) - (<>.after (.this "\p{Upper}") (in (` .upper))) - (<>.after (.this "\p{Alpha}") (in (` .alpha))) - (<>.after (.this "\p{Digit}") (in (` .decimal))) - (<>.after (.this "\p{Alnum}") (in (` .alpha_num))) - (<>.after (.this "\p{Space}") (in (` .space))) - (<>.after (.this "\p{HexDigit}") (in (` .hexadecimal))) - (<>.after (.this "\p{OctDigit}") (in (` .octal))) - (<>.after (.this "\p{Blank}") (in (` (~! blank^)))) - (<>.after (.this "\p{ASCII}") (in (` (~! ascii^)))) - (<>.after (.this "\p{Contrl}") (in (` (~! control^)))) - (<>.after (.this "\p{Punct}") (in (` (~! punct^)))) - (<>.after (.this "\p{Graph}") (in (` (~! graph^)))) - (<>.after (.this "\p{Print}") (in (` (~! print^)))) + (<>.after (.this ".") (in (` .any))) + (<>.after (.this "\d") (in (` .decimal))) + (<>.after (.this "\D") (in (` (.not .decimal)))) + (<>.after (.this "\s") (in (` .space))) + (<>.after (.this "\S") (in (` (.not .space)))) + (<>.after (.this "\w") (in (` (~! word^)))) + (<>.after (.this "\W") (in (` (.not (~! word^))))) + + (<>.after (.this "\p{Lower}") (in (` .lower))) + (<>.after (.this "\p{Upper}") (in (` .upper))) + (<>.after (.this "\p{Alpha}") (in (` .alpha))) + (<>.after (.this "\p{Digit}") (in (` .decimal))) + (<>.after (.this "\p{Alnum}") (in (` .alpha_num))) + (<>.after (.this "\p{Space}") (in (` .space))) + (<>.after (.this "\p{HexDigit}") (in (` .hexadecimal))) + (<>.after (.this "\p{OctDigit}") (in (` .octal))) + (<>.after (.this "\p{Blank}") (in (` (~! blank^)))) + (<>.after (.this "\p{ASCII}") (in (` (~! ascii^)))) + (<>.after (.this "\p{Contrl}") (in (` (~! control^)))) + (<>.after (.this "\p{Punct}") (in (` (~! punct^)))) + (<>.after (.this "\p{Graph}") (in (` (~! graph^)))) + (<>.after (.this "\p{Print}") (in (` (~! print^)))) ))) (def: re_class^ (Parser Code) (<>.either re_system_class^ - (.enclosed ["[" "]"] re_user_class^))) + (.enclosed ["[" "]"] re_user_class^))) (def: number^ (Parser Nat) - (|> (.many .decimal) + (|> (.many .decimal) (<>.codec n.decimal))) (def: re_back_reference^ (Parser Code) (<>.either (do <>.monad - [_ (.this "\") + [_ (.this "\") id number^] (in (` ((~! ..copy) (~ (code.identifier ["" (n\encode id)])))))) (do <>.monad - [_ (.this "\k<") + [_ (.this "\k<") captured_name name_part^ - _ (.this ">")] + _ (.this ">")] (in (` ((~! ..copy) (~ (code.identifier ["" captured_name])))))))) (def: (re_simple^ current_module) @@ -216,7 +217,7 @@ (-> Text (Parser Code)) (do <>.monad [base (re_simple^ current_module) - quantifier (.one_of "?*+")] + quantifier (.one_of "?*+")] (case quantifier "?" (in (` (<>.default "" (~ base)))) @@ -229,26 +230,33 @@ (in (` ((~! join_text^) (<>.many (~ base))))) ))) +(exception: #export (incorrect_quantification {from Nat} {to Nat}) + (exception.report + ["Input" (format (%.nat from) "," (%.nat to))] + ["Should be" (format (%.nat to) "," (%.nat from))])) + (def: (re_counted_quantified^ current_module) (-> Text (Parser Code)) (do {! <>.monad} [base (re_simple^ current_module)] - (.enclosed ["{" "}"] - ($_ <>.either - (do ! - [[from to] (<>.and number^ (<>.after (.this ",") number^))] - (in (` ((~! join_text^) (<>.between (~ (code.nat from)) - (~ (code.nat to)) - (~ base)))))) - (do ! - [limit (<>.after (.this ",") number^)] - (in (` ((~! join_text^) (<>.at_most (~ (code.nat limit)) (~ base)))))) - (do ! - [limit (<>.before (.this ",") number^)] - (in (` ((~! join_text^) (<>.at_least (~ (code.nat limit)) (~ base)))))) - (do ! - [limit number^] - (in (` ((~! join_text^) (<>.exactly (~ (code.nat limit)) (~ base)))))))))) + (<| (.enclosed ["{" "}"]) + ($_ <>.either + (do ! + [[from to] (<>.and number^ (<>.after (.this ",") number^)) + _ (<>.assert (exception.construct ..incorrect_quantification [from to]) + (n.<= to from))] + (in (` ((~! join_text^) (<>.between (~ (code.nat from)) + (~ (code.nat (n.- from to))) + (~ base)))))) + (do ! + [limit (<>.after (.this ",") number^)] + (in (` ((~! join_text^) (<>.at_most (~ (code.nat limit)) (~ base)))))) + (do ! + [limit (<>.before (.this ",") number^)] + (in (` ((~! join_text^) (<>.at_least (~ (code.nat limit)) (~ base)))))) + (do ! + [limit number^] + (in (` ((~! join_text^) (<>.exactly (~ (code.nat limit)) (~ base)))))))))) (def: (re_quantified^ current_module) (-> Text (Parser Code)) @@ -364,7 +372,7 @@ (do <>.monad [#let [sub^ (re_sequential^ capturing? re_scoped^ current_module)] head sub^ - tail (<>.some (<>.after (.this "|") sub^))] + tail (<>.some (<>.after (.this "|") sub^))] (if (list.empty? tail) (in head) (in [(list\fold n.max (product.left head) (list\map product.left tail)) @@ -378,31 +386,31 @@ (-> Text (Parser [Re_Group Code])) ($_ <>.either (do <>.monad - [_ (.this "(?:") + [_ (.this "(?:") [_ scoped] (re_alternative^ #0 re_scoped^ current_module) - _ (.this ")")] + _ (.this ")")] (in [#Non_Capturing scoped])) (do <>.monad [complex (re_complex^ current_module)] (in [#Non_Capturing complex])) (do <>.monad - [_ (.this "(?<") + [_ (.this "(?<") captured_name name_part^ - _ (.this ">") + _ (.this ">") [num_captures pattern] (re_alternative^ #1 re_scoped^ current_module) - _ (.this ")")] + _ (.this ")")] (in [(#Capturing [(#.Some captured_name) num_captures]) pattern])) (do <>.monad - [_ (.this "(") + [_ (.this "(") [num_captures pattern] (re_alternative^ #1 re_scoped^ current_module) - _ (.this ")")] + _ (.this ")")] (in [(#Capturing [#.None num_captures]) pattern])))) (def: (regex^ current_module) (-> Text (Parser Code)) (\ <>.monad map product.right (re_alternative^ #1 re_scoped^ current_module))) -(syntax: #export (regex {pattern .text}) +(syntax: #export (regex {pattern .text}) {#.doc (doc "Create lexers using regular-expression syntax." "For example:" @@ -463,8 +471,8 @@ )} (do meta.monad [current_module meta.current_module_name] - (case (.run (regex^ current_module) - pattern) + (case (.run (regex^ current_module) + pattern) (#try.Failure error) (meta.failure (format "Error while parsing regular-expression:" //.new_line error)) @@ -473,9 +481,9 @@ (in (list regex)) ))) -(syntax: #export (^regex {[pattern bindings] (.form (<>.and .text (<>.maybe .any)))} +(syntax: #export (^regex {[pattern bindings] (.form (<>.and .text (<>.maybe .any)))} body - {branches (<>.many .any)}) + {branches (<>.many .any)}) {#.doc (doc "Allows you to test text against regular expressions." (case some_text (^regex "(\d{3})-(\d{3})-(\d{4})" @@ -489,7 +497,7 @@ do_something_else))} (with_gensyms [g!temp] (in (list& (` (^multi (~ g!temp) - {((~! .run) (..regex (~ (code.text pattern))) (~ g!temp)) + {((~! .run) (..regex (~ (code.text pattern))) (~ g!temp)) (#try.Success (~ (maybe.default g!temp bindings)))})) body branches)))) diff --git a/stdlib/source/library/lux/debug.lux b/stdlib/source/library/lux/debug.lux index 2778746ea..2e6b46b4f 100644 --- a/stdlib/source/library/lux/debug.lux +++ b/stdlib/source/library/lux/debug.lux @@ -138,7 +138,7 @@ array.to_list (list\map inspection) (text.join_with " ") - (text.enclose ["[" "]"]))))) + (text.enclosed ["[" "]"]))))) (def: #export (inspection value) Inspector @@ -171,7 +171,7 @@ (|> (%.format (%.nat (.nat (java/lang/Integer::longValue tag))) " " (%.bit last?) " " (inspection choice)) - (text.enclose ["(" ")"]))) + (text.enclosed ["(" ")"]))) _ (tuple_inspection inspection value))) @@ -200,7 +200,7 @@ (|> (%.format (JSON::stringify variant_tag) " " (%.bit (not ("js object null?" variant_flag))) " " (inspection variant_value)) - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (not (or ("js object undefined?" ("js object get" "_lux_low" value)) ("js object undefined?" ("js object get" "_lux_high" value)))) @@ -241,7 +241,7 @@ (|> (%.format (|> variant_tag (:as .Nat) %.nat) " " (|> variant_flag "python object none?" not %.bit) " " (inspection variant_value)) - (text.enclose ["(" ")"])))) + (text.enclosed ["(" ")"])))) _ (..str value))) _ @@ -274,7 +274,7 @@ (|> (%.format (|> variant_tag (:as .Nat) %.nat) " " (%.bit (not ("lua object nil?" variant_flag))) " " (inspection variant_value)) - (text.enclose ["(" ")"])))) + (text.enclosed ["(" ")"])))) _ (..tostring value)) @@ -312,7 +312,7 @@ (|> (%.format (|> variant_tag (:as .Nat) %.nat) " " (%.bit (not ("ruby object nil?" variant_flag))) " " (inspection variant_value)) - (text.enclose ["(" ")"])))) + (text.enclosed ["(" ")"])))) (is? (class_of [[] []]) value_class) (tuple_inspection inspection value) @@ -342,7 +342,7 @@ (|> (%.format (|> variant_tag (:as .Nat) %.nat) " " (%.bit (not ("php object null?" variant_flag))) " " (inspection variant_value)) - (text.enclose ["(" ")"])))) + (text.enclosed ["(" ")"])))) _ (..strval value)) @@ -370,7 +370,7 @@ (|> (%.format (|> variant_tag (:as .Nat) %.nat) " " (%.bit (not ("scheme object nil?" variant_flag))) " " (inspection variant_value)) - (text.enclose ["(" ")"]))) + (text.enclosed ["(" ")"]))) (..format ["~s" value]))) ## else diff --git a/stdlib/source/library/lux/ffi.old.lux b/stdlib/source/library/lux/ffi.old.lux index 5187df976..16ff216e4 100644 --- a/stdlib/source/library/lux/ffi.old.lux +++ b/stdlib/source/library/lux/ffi.old.lux @@ -227,7 +227,7 @@ (#FieldAccessDecl ImportFieldDecl)) ## Utils -(def: (manual_primitive_to_type class) +(def: (manual_primitive_type class) (-> Text (Maybe Code)) (case class (^template [ ] @@ -246,7 +246,7 @@ _ #.None)) -(def: (auto_primitive_to_type class) +(def: (auto_primitive_type class) (-> Text (Maybe Code)) (case class (^template [ ] @@ -268,26 +268,26 @@ (-> Text Text) (text.replace_all "/" ".")) -(def: (generic_class_to_type' mode type_params in_array? name+params - class_to_type') +(def: (generic_class_type' mode type_params in_array? name+params + class_type') (-> Primitive_Mode (List Type_Parameter) Bit [Text (List GenericType)] (-> Primitive_Mode (List Type_Parameter) Bit GenericType Code) Code) (case [name+params mode in_array?] (^multi [[prim #.End] #ManualPrM #0] - {(manual_primitive_to_type prim) (#.Some output)}) + {(manual_primitive_type prim) (#.Some output)}) output (^multi [[prim #.End] #AutoPrM #0] - {(auto_primitive_to_type prim) (#.Some output)}) + {(auto_primitive_type prim) (#.Some output)}) output [[name params] _ _] (let [name (safe name) - =params (list\map (class_to_type' mode type_params in_array?) params)] + =params (list\map (class_type' mode type_params in_array?) params)] (` (primitive (~ (code.text name)) [(~+ =params)]))))) -(def: (class_to_type' mode type_params in_array? class) +(def: (class_type' mode type_params in_array? class) (-> Primitive_Mode (List Type_Parameter) Bit GenericType Code) (case class (#GenericTypeVar name) @@ -299,26 +299,26 @@ (code.identifier ["" name]) (#.Some [pname pbounds]) - (class_to_type' mode type_params in_array? (maybe.assume (list.head pbounds)))) + (class_type' mode type_params in_array? (maybe.assume (list.head pbounds)))) (#GenericClass name+params) - (generic_class_to_type' mode type_params in_array? name+params - class_to_type') + (generic_class_type' mode type_params in_array? name+params + class_type') (#GenericArray param) - (let [=param (class_to_type' mode type_params #1 param)] + (let [=param (class_type' mode type_params #1 param)] (` ((~! array.Array) (~ =param)))) (^or (#GenericWildcard #.None) (#GenericWildcard (#.Some [#LowerBound _]))) (` .Any) (#GenericWildcard (#.Some [#UpperBound upper_bound])) - (class_to_type' mode type_params in_array? upper_bound) + (class_type' mode type_params in_array? upper_bound) )) -(def: (class_to_type mode type_params class) +(def: (class_type mode type_params class) (-> Primitive_Mode (List Type_Parameter) GenericType Code) - (class_to_type' mode type_params #0 class)) + (class_type' mode type_params #0 class)) (def: (type_param_type$ [name bounds]) (-> Type_Parameter Code) @@ -333,7 +333,7 @@ (code.identifier ["" pname]) (#.Item bound1 _) - (class_to_type #ManualPrM class_params bound1)))) + (class_type #ManualPrM class_params bound1)))) class_params)] (` (primitive (~ (code.text (safe class_name))) [(~+ =params)])))) @@ -384,21 +384,21 @@ (format "[L" (simple_class$ env param) ";")) )) -(def: (make_get_const_parser class_name field_name) +(def: (get_const_parser class_name field_name) (-> Text Text (Parser Code)) (do <>.monad [#let [dotted_name (format "::" field_name)] _ (.this! (code.identifier ["" dotted_name]))] (in (`' ((~ (code.text (format "jvm getstatic" ":" class_name ":" field_name)))))))) -(def: (make_get_var_parser class_name field_name) +(def: (get_var_parser class_name field_name) (-> Text Text (Parser Code)) (do <>.monad [#let [dotted_name (format "::" field_name)] _ (.this! (code.identifier ["" dotted_name]))] (in (`' ((~ (code.text (format "jvm getfield" ":" class_name ":" field_name))) _jvm_this))))) -(def: (make_put_var_parser class_name field_name) +(def: (put_var_parser class_name field_name) (-> Text Text (Parser Code)) (do <>.monad [#let [dotted_name (format "::" field_name)] @@ -424,7 +424,7 @@ ast' ast')) -(def: (parser_to_replacer p ast) +(def: (parser_replacer p ast) (-> (Parser Code) (-> Code Code)) (case (<>.run p (list ast)) (#.Right [#.End ast']) @@ -434,17 +434,17 @@ ast )) -(def: (field_to_parser class_name [[field_name _ _] field]) +(def: (field_parser class_name [[field_name _ _] field]) (-> Text [Member_Declaration FieldDecl] (Parser Code)) (case field (#ConstantField _) - (make_get_const_parser class_name field_name) + (get_const_parser class_name field_name) (#VariableField _) - (<>.either (make_get_var_parser class_name field_name) - (make_put_var_parser class_name field_name)))) + (<>.either (get_var_parser class_name field_name) + (put_var_parser class_name field_name)))) -(def: (make_constructor_parser params class_name arg_decls) +(def: (constructor_parser params class_name arg_decls) (-> (List Type_Parameter) Text (List ArgDecl) (Parser Code)) (do <>.monad [args (: (Parser (List Code)) @@ -454,7 +454,7 @@ (in (` ((~ (code.text (format "jvm new" ":" class_name ":" (text.join_with "," arg_decls')))) (~+ args)))))) -(def: (make_static_method_parser params class_name method_name arg_decls) +(def: (static_method_parser params class_name method_name arg_decls) (-> (List Type_Parameter) Text Text (List ArgDecl) (Parser Code)) (do <>.monad [#let [dotted_name (format "::" method_name "!")] @@ -477,28 +477,28 @@ (in (`' ((~ (code.text (format ":" class_name ":" method_name ":" (text.join_with "," arg_decls')))) (~' _jvm_this) (~+ args))))))] - [make_special_method_parser "jvm invokespecial"] - [make_virtual_method_parser "jvm invokevirtual"] + [special_method_parser "jvm invokespecial"] + [virtual_method_parser "jvm invokevirtual"] ) -(def: (method_to_parser params class_name [[method_name _ _] meth_def]) +(def: (method_parser params class_name [[method_name _ _] meth_def]) (-> (List Type_Parameter) Text [Member_Declaration Method_Definition] (Parser Code)) (case meth_def (#ConstructorMethod strict? type_vars args constructor_args return_expr exs) - (make_constructor_parser params class_name args) + (constructor_parser params class_name args) (#StaticMethod strict? type_vars args return_type return_expr exs) - (make_static_method_parser params class_name method_name args) + (static_method_parser params class_name method_name args) (^or (#VirtualMethod final? strict? type_vars self_name args return_type return_expr exs) (#OverridenMethod strict? owner_class type_vars self_name args return_type return_expr exs)) - (make_special_method_parser params class_name method_name args) + (special_method_parser params class_name method_name args) (#AbstractMethod type_vars args return_type exs) - (make_virtual_method_parser params class_name method_name args) + (virtual_method_parser params class_name method_name args) (#NativeMethod type_vars args return_type exs) - (make_virtual_method_parser params class_name method_name args))) + (virtual_method_parser params class_name method_name args))) ## Parsers (def: privacy_modifier^ @@ -941,11 +941,11 @@ ## Generators (def: with_parens (-> JVM_Code JVM_Code) - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (def: with_brackets (-> JVM_Code JVM_Code) - (text.enclose ["[" "]"])) + (text.enclosed ["[" "]"])) (def: spaced (-> (List JVM_Code) JVM_Code) @@ -1092,16 +1092,16 @@ (~ body)))))))) (#OverridenMethod strict_fp? class_decl type_vars this_name arg_decls return_type body exs) - (let [super_replacer (parser_to_replacer (.form (do <>.monad - [_ (.this! (' ::super!)) - args (.tuple (<>.exactly (list.size arg_decls) .any)) - #let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ (list))) - arg_decls))]] - (in (`' ((~ (code.text (format "jvm invokespecial" - ":" (get@ #super_class_name super_class) - ":" name - ":" (text.join_with "," arg_decls')))) - (~' _jvm_this) (~+ args)))))))] + (let [super_replacer (parser_replacer (.form (do <>.monad + [_ (.this! (' ::super!)) + args (.tuple (<>.exactly (list.size arg_decls) .any)) + #let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ (list))) + arg_decls))]] + (in (`' ((~ (code.text (format "jvm invokespecial" + ":" (get@ #super_class_name super_class) + ":" name + ":" (text.join_with "," arg_decls')))) + (~' _jvm_this) (~+ args)))))))] (with_parens (spaced (list "override" (class_decl$ class_decl) @@ -1210,11 +1210,11 @@ (do meta.monad [current_module meta.current_module_name #let [fully_qualified_class_name (format (safe current_module) "." full_class_name) - field_parsers (list\map (field_to_parser fully_qualified_class_name) fields) - method_parsers (list\map (method_to_parser (product.right class_decl) fully_qualified_class_name) methods) - replacer (parser_to_replacer (list\fold <>.either - (<>.failure "") - (list\compose field_parsers method_parsers))) + field_parsers (list\map (field_parser fully_qualified_class_name) fields) + method_parsers (list\map (method_parser (product.right class_decl) fully_qualified_class_name) methods) + replacer (parser_replacer (list\fold <>.either + (<>.failure "") + (list\compose field_parsers method_parsers))) def_code (format "jvm class:" (spaced (list (class_decl$ class_decl) (super_class_decl$ super) @@ -1399,7 +1399,7 @@ import_member_args)) arg_types (list\map (: (-> [Bit GenericType] Code) (function (_ [maybe? arg]) - (let [arg_type (class_to_type (get@ #import_member_mode commons) type_params arg)] + (let [arg_type (class_type (get@ #import_member_mode commons) type_params arg)] (if maybe? (` (Maybe (~ arg_type))) arg_type)))) @@ -1568,7 +1568,7 @@ (#FieldAccessDecl fad) (do meta.monad [#let [(^open ".") fad - base_gtype (class_to_type import_field_mode type_params import_field_type) + base_gtype (class_type import_field_mode type_params import_field_type) classC (class_decl_type$ class) typeC (if import_field_maybe? (` (Maybe (~ base_gtype))) @@ -1740,7 +1740,7 @@ (array_length my_array))} (in (list (` ("jvm arraylength" (~ array)))))) -(def: (type_to_class_name type) +(def: (type_class_name type) (-> Type (Meta Text)) (if (type\= Any type) (\ meta.monad in "java.lang.Object") @@ -1754,10 +1754,10 @@ (meta.failure (format "Cannot apply type: " (type.format F) " to " (type.format A))) (#.Some type') - (type_to_class_name type')) + (type_class_name type')) (#.Named _ type') - (type_to_class_name type') + (type_class_name type') _ (meta.failure (format "Cannot convert to JvmType: " (type.format type)))))) @@ -1769,7 +1769,7 @@ [_ (#.Identifier array_name)] (do meta.monad [array_type (meta.type array_name) - array_jvm_type (type_to_class_name array_type)] + array_jvm_type (type_class_name array_type)] (case array_jvm_type (^template [ ] [ @@ -1798,7 +1798,7 @@ [_ (#.Identifier array_name)] (do meta.monad [array_type (meta.type array_name) - array_jvm_type (type_to_class_name array_type)] + array_jvm_type (type_class_name array_type)] (case array_jvm_type (^template [ ] [ @@ -1826,4 +1826,4 @@ (in (list (` ("jvm object class" (~ (code.text (simple_class$ (list) type)))))))) (syntax: #export (type {type (..generic_type^ (list))}) - (in (list (..class_to_type #ManualPrM (list) type)))) + (in (list (..class_type #ManualPrM (list) type)))) diff --git a/stdlib/source/library/lux/macro.lux b/stdlib/source/library/lux/macro.lux index e80b1d665..11509f0cc 100644 --- a/stdlib/source/library/lux/macro.lux +++ b/stdlib/source/library/lux/macro.lux @@ -18,7 +18,7 @@ ["#" meta ["." location]]]) -(def: #export (expand_once syntax) +(def: #export (single_expansion syntax) {#.doc (doc "Given code that requires applying a macro, does it once and returns the result." "Otherwise, returns the code as-is.")} (-> Code (Meta (List Code))) @@ -36,7 +36,7 @@ _ (\ //.monad in (list syntax)))) -(def: #export (expand syntax) +(def: #export (expansion syntax) {#.doc (doc "Given code that requires applying a macro, expands repeatedly until no more direct macro-calls are left." "Otherwise, returns the code as-is.")} (-> Code (Meta (List Code))) @@ -46,10 +46,11 @@ [?macro (//.macro name)] (case ?macro (#.Some macro) - (do //.monad - [expansion ((:as Macro' macro) args) - expansion' (monad.map //.monad expand expansion)] - (in (list\join expansion'))) + (do {! //.monad} + [top_level_expansion ((:as Macro' macro) args)] + (|> top_level_expansion + (monad.map //.monad expansion) + (\ ! map list\join))) #.None (\ //.monad in (list syntax)))) @@ -57,7 +58,7 @@ _ (\ //.monad in (list syntax)))) -(def: #export (expand_all syntax) +(def: #export (full_expansion syntax) {#.doc "Expands all macro-calls everywhere recursively, until only primitive/base code remains."} (-> Code (Meta (List Code))) (case syntax @@ -68,23 +69,23 @@ (#.Some macro) (do //.monad [expansion ((:as Macro' macro) args) - expansion' (monad.map //.monad expand_all expansion)] + expansion' (monad.map //.monad full_expansion expansion)] (in (list\join expansion'))) #.None (do //.monad - [parts' (monad.map //.monad expand_all (list& (code.identifier name) args))] + [parts' (monad.map //.monad full_expansion (list& (code.identifier name) args))] (in (list (code.form (list\join parts'))))))) [_ (#.Form (#.Item [harg targs]))] (do //.monad - [harg+ (expand_all harg) - targs+ (monad.map //.monad expand_all targs)] + [harg+ (full_expansion harg) + targs+ (monad.map //.monad full_expansion targs)] (in (list (code.form (list\compose harg+ (list\join (: (List (List Code)) targs+))))))) [_ (#.Tuple members)] (do //.monad - [members' (monad.map //.monad expand_all members)] + [members' (monad.map //.monad full_expansion members)] (in (list (code.tuple (list\join members'))))) [_ (#.Record members)] @@ -92,8 +93,8 @@ (monad.map //.monad (function (_ [left right]) (do //.monad - [left (expand_all left) - right (expand_all right)] + [left (full_expansion left) + right (full_expansion right)] (case [left right] [(#.Item left #.End) (#.Item right #.End)] (in [left right]) @@ -154,11 +155,11 @@ _ (//.failure (..wrong_syntax_error (name_of ..with_gensyms))))) -(def: #export (expand_1 token) +(def: #export (one_expansion token) {#.doc "Works just like expand, except that it ensures that the output is a single Code token."} (-> Code (Meta Code)) (do //.monad - [token+ (..expand token)] + [token+ (..expansion token)] (case token+ (^ (list token')) (in token') @@ -204,7 +205,7 @@ #.None (//.failure (..wrong_syntax_error macro_name)))))] - [log_expand_once! ..expand_once] - [log_expand! ..expand] - [log_expand_all! ..expand_all] + [log_single_expansion! ..single_expansion] + [log_expansion! ..expansion] + [log_full_expansion! ..full_expansion] ) diff --git a/stdlib/source/library/lux/macro/syntax/definition.lux b/stdlib/source/library/lux/macro/syntax/definition.lux index 3b8bab1d5..da2adcd82 100644 --- a/stdlib/source/library/lux/macro/syntax/definition.lux +++ b/stdlib/source/library/lux/macro/syntax/definition.lux @@ -105,7 +105,7 @@ (do {! <>.monad} [raw .any me_raw (|> raw - macro.expand_all + macro.full_expansion (meta.run compiler) <>.lift)] (<| (.local me_raw) diff --git a/stdlib/source/library/lux/math/number/i16.lux b/stdlib/source/library/lux/math/number/i16.lux index a35300c11..1fd3e6b02 100644 --- a/stdlib/source/library/lux/math/number/i16.lux +++ b/stdlib/source/library/lux/math/number/i16.lux @@ -9,7 +9,8 @@ [// ["." i64 (#+ Sub)]]) -(def: sub (maybe.assume (i64.sub 16))) +(def: sub + (maybe.assume (i64.sub 16))) (def: #export I16 (:by_example [size] diff --git a/stdlib/source/library/lux/math/number/i8.lux b/stdlib/source/library/lux/math/number/i8.lux index 2e8fc0cf1..16da5b679 100644 --- a/stdlib/source/library/lux/math/number/i8.lux +++ b/stdlib/source/library/lux/math/number/i8.lux @@ -9,7 +9,8 @@ [// ["." i64 (#+ Sub)]]) -(def: sub (maybe.assume (i64.sub 8))) +(def: sub + (maybe.assume (i64.sub 8))) (def: #export I8 (:by_example [size] diff --git a/stdlib/source/library/lux/meta.lux b/stdlib/source/library/lux/meta.lux index 3a6174cda..728e969b8 100644 --- a/stdlib/source/library/lux/meta.lux +++ b/stdlib/source/library/lux/meta.lux @@ -383,11 +383,11 @@ (type_definition de_aliased) (#.Right [exported? def_type def_data def_value]) - (let [type_to_code (`` ("lux in-module" (~~ (static .prelude_module)) .type_to_code))] + (let [type_code (`` ("lux in-module" (~~ (static .prelude_module)) .type_code))] (if (or (is? .Type def_type) (\ code.equivalence = - (type_to_code .Type) - (type_to_code def_type))) + (type_code .Type) + (type_code def_type))) (in (:as Type def_value)) (..failure ($_ text\compose "Definition is not a type: " (name\encode name)))))))) diff --git a/stdlib/source/library/lux/target/common_lisp.lux b/stdlib/source/library/lux/target/common_lisp.lux index ecc778d98..ed040a6b4 100644 --- a/stdlib/source/library/lux/target/common_lisp.lux +++ b/stdlib/source/library/lux/target/common_lisp.lux @@ -18,7 +18,7 @@ (def: as_form (-> Text Text) - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (abstract: #export (Code brand) Text @@ -135,7 +135,7 @@ (def: #export string (-> Text Literal) (|>> ..safe - (text.enclose' text.double_quote) + (text.enclosed' text.double_quote) :abstraction)) (def: #export var diff --git a/stdlib/source/library/lux/target/js.lux b/stdlib/source/library/lux/target/js.lux index d19bb0b8b..8bbb1dd93 100644 --- a/stdlib/source/library/lux/target/js.lux +++ b/stdlib/source/library/lux/target/js.lux @@ -17,8 +17,11 @@ [type abstract]]]) -(def: expression (text.enclose ["(" ")"])) -(def: element (text.enclose ["[" "]"])) +(def: expression + (text.enclosed ["(" ")"])) + +(def: element + (text.enclosed ["[" "]"])) (def: nest (-> Text Text) @@ -105,7 +108,7 @@ (def: #export string (-> Text Literal) (|>> ..safe - (text.enclose [text.double_quote text.double_quote]) + (text.enclosed [text.double_quote text.double_quote]) :abstraction)) (def: argument_separator ", ") @@ -149,7 +152,7 @@ (|>> (list\map (.function (_ [key val]) (format (:representation (..string key)) ..field_separator (:representation val)))) (text.join_with ..argument_separator) - (text.enclose ["{" "}"]) + (text.enclosed ["{" "}"]) ..expression :abstraction)) @@ -170,8 +173,8 @@ (let [close (format text.new_line "}")] (|>> :representation ..nest - (text.enclose ["{" - close])))) + (text.enclosed ["{" + close])))) (def: #export (function! name inputs body) (-> Var (List Var) Statement Statement) @@ -405,7 +408,7 @@ (|> (format (|> cases (list\map (.function (_ [when then]) (format (|> when - (list\map (|>> :representation (text.enclose ["case " ":"]))) + (list\map (|>> :representation (text.enclosed ["case " ":"]))) (text.join_with text.new_line)) (..nest (:representation then))))) (text.join_with text.new_line)) diff --git a/stdlib/source/library/lux/target/jvm/type/descriptor.lux b/stdlib/source/library/lux/target/jvm/type/descriptor.lux index 2cdbeb6ee..6f36f544b 100644 --- a/stdlib/source/library/lux/target/jvm/type/descriptor.lux +++ b/stdlib/source/library/lux/target/jvm/type/descriptor.lux @@ -50,7 +50,7 @@ (-> External (Descriptor Class)) (|>> ///name.internal ///name.read - (text.enclose [..class_prefix ..class_suffix]) + (text.enclosed [..class_prefix ..class_suffix]) :abstraction)) (def: #export (declaration name) @@ -96,7 +96,7 @@ (format (|> inputs (list\map ..descriptor) (text.join_with "") - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (:representation output)))) (implementation: #export equivalence diff --git a/stdlib/source/library/lux/target/jvm/type/signature.lux b/stdlib/source/library/lux/target/jvm/type/signature.lux index 7e1164671..84a6a5982 100644 --- a/stdlib/source/library/lux/target/jvm/type/signature.lux +++ b/stdlib/source/library/lux/target/jvm/type/signature.lux @@ -55,7 +55,7 @@ (def: #export var (-> Text (Signature Var)) - (|>> (text.enclose [..var_prefix //descriptor.class_suffix]) + (|>> (text.enclosed [..var_prefix //descriptor.class_suffix]) :abstraction)) (def: #export var_name @@ -129,13 +129,13 @@ (list\map (|>> ..var_name (text.suffix ..class_bound))) (text.join_with "") - (text.enclose [..parameters_start - ..parameters_end]))) + (text.enclosed [..parameters_start + ..parameters_end]))) (|> inputs (list\map ..signature) (text.join_with "") - (text.enclose [..arguments_start - ..arguments_end])) + (text.enclosed [..arguments_start + ..arguments_end])) (:representation output) (|> exceptions (list\map (|>> :representation (format ..exception_prefix))) diff --git a/stdlib/source/library/lux/target/lua.lux b/stdlib/source/library/lux/target/lua.lux index 74a975754..05a2847e7 100644 --- a/stdlib/source/library/lux/target/lua.lux +++ b/stdlib/source/library/lux/target/lua.lux @@ -134,7 +134,7 @@ (def: #export string (-> Text Literal) - (|>> ..safe (text.enclose' text.double_quote) :abstraction)) + (|>> ..safe (text.enclosed' text.double_quote) :abstraction)) (def: #export multi (-> (List Expression) Literal) @@ -146,7 +146,7 @@ (-> (List Expression) Literal) (|>> (list\map ..code) (text.join_with ..input_separator) - (text.enclose ["{" "}"]) + (text.enclosed ["{" "}"]) :abstraction)) (def: #export table @@ -154,7 +154,7 @@ (|>> (list\map (.function (_ [key value]) (format key " = " (:representation value)))) (text.join_with ..input_separator) - (text.enclose ["{" "}"]) + (text.enclosed ["{" "}"]) :abstraction)) (def: #export (nth idx array) @@ -168,7 +168,7 @@ (def: #export length (-> Expression Computation) (|>> :representation - (text.enclose ["#(" ")"]) + (text.enclosed ["#(" ")"]) :abstraction)) (def: #export (apply/* args func) @@ -176,7 +176,7 @@ (|> args (list\map ..code) (text.join_with ..input_separator) - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) (format (:representation func)) :abstraction)) @@ -185,7 +185,7 @@ (|> args (list\map ..code) (text.join_with ..input_separator) - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) (format (:representation table) ":" method) :abstraction)) @@ -328,10 +328,10 @@ (-> (List Var) Statement Expression) (|> (format "function " (|> args ..locations - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (..nest (:representation body!)) text.new_line "end") - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) :abstraction)) (template [ ] @@ -341,7 +341,7 @@ (format " " (:representation name) (|> args ..locations - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (..nest (:representation body!)) text.new_line "end")))] diff --git a/stdlib/source/library/lux/target/php.lux b/stdlib/source/library/lux/target/php.lux index 7cc266b98..e96d8fe85 100644 --- a/stdlib/source/library/lux/target/php.lux +++ b/stdlib/source/library/lux/target/php.lux @@ -37,11 +37,11 @@ (def: block (-> Text Text) - (|>> ..nest (text.enclose ["{" (format text.new_line "}")]))) + (|>> ..nest (text.enclosed ["{" (format text.new_line "}")]))) (def: group (-> Text Text) - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (abstract: #export (Code brand) Text @@ -176,7 +176,7 @@ (def: #export string (-> Text Literal) (|>> ..safe - (text.enclose [text.double_quote text.double_quote]) + (text.enclosed [text.double_quote text.double_quote]) :abstraction)) (def: arguments diff --git a/stdlib/source/library/lux/target/python.lux b/stdlib/source/library/lux/target/python.lux index 056426d2a..b7ac6a094 100644 --- a/stdlib/source/library/lux/target/python.lux +++ b/stdlib/source/library/lux/target/python.lux @@ -29,7 +29,7 @@ (def: expression (-> Text Text) - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (for {@.old (as_is (ffi.import: java/lang/CharSequence) (ffi.import: java/lang/String @@ -170,7 +170,7 @@ (def: #export string (-> Text Literal) (|>> ..safe - (text.enclose [text.double_quote text.double_quote]) + (text.enclosed [text.double_quote text.double_quote]) :abstraction)) (def: #export unicode diff --git a/stdlib/source/library/lux/target/ruby.lux b/stdlib/source/library/lux/target/ruby.lux index 497cae831..7f6b66c74 100644 --- a/stdlib/source/library/lux/target/ruby.lux +++ b/stdlib/source/library/lux/target/ruby.lux @@ -192,7 +192,7 @@ (def: #export (array_range from to array) (-> Expression Expression Expression Computation) (|> (format (:representation from) ".." (:representation to)) - (text.enclose ["[" "]"]) + (text.enclosed ["[" "]"]) (format (:representation array)) :abstraction)) @@ -200,7 +200,7 @@ (-> (List Expression) Literal) (|>> (list\map (|>> :representation)) (text.join_with ..input_separator) - (text.enclose ["[" "]"]) + (text.enclosed ["[" "]"]) :abstraction)) (def: #export hash @@ -208,7 +208,7 @@ (|>> (list\map (.function (_ [k v]) (format (:representation k) " => " (:representation v)))) (text.join_with ..input_separator) - (text.enclose ["{" "}"]) + (text.enclosed ["{" "}"]) :abstraction)) (def: #export (apply/* args func) @@ -216,7 +216,7 @@ (|> args (list\map (|>> :representation)) (text.join_with ..input_separator) - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) (format (:representation func)) :abstraction)) @@ -225,7 +225,7 @@ (|> args (list\map (|>> :representation)) (text.join_with ..input_separator) - (text.enclose ["[" "]"]) + (text.enclosed ["[" "]"]) (format (:representation lambda)) :abstraction)) @@ -236,7 +236,7 @@ (def: #export (nth idx array) (-> Expression Expression Access) (|> (:representation idx) - (text.enclose ["[" "]"]) + (text.enclosed ["[" "]"]) (format (:representation array)) :abstraction)) @@ -245,7 +245,7 @@ (|> (format (:representation test) " ? " (:representation then) " : " (:representation else)) - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) :abstraction)) (def: #export statement @@ -356,7 +356,7 @@ (|> args (list\map (|>> :representation)) (text.join_with ..input_separator) - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (..nest (:representation body!))))) (def: #export (lambda name args body!) @@ -364,9 +364,9 @@ (let [proc (|> (format (|> args (list\map (|>> :representation)) (text.join_with ..input_separator) - (text.enclose' "|")) + (text.enclosed' "|")) (..nest (:representation body!))) - (text.enclose ["{" "}"]) + (text.enclosed ["{" "}"]) (format "lambda "))] (|> (case name #.None @@ -374,7 +374,7 @@ (#.Some name) (format (:representation name) " = " proc)) - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) :abstraction))) (template [ ] diff --git a/stdlib/source/library/lux/target/scheme.lux b/stdlib/source/library/lux/target/scheme.lux index f03f876b8..f2b855522 100644 --- a/stdlib/source/library/lux/target/scheme.lux +++ b/stdlib/source/library/lux/target/scheme.lux @@ -85,14 +85,14 @@ (format (|> mandatory (list\map ..code) (text.join_with " "))) - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) :abstraction)) #.None (|> mandatory (list\map ..code) (text.join_with " ") - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) :abstraction))) (def: #export nil @@ -163,7 +163,7 @@ (list\map (|>> :representation nest)) (#.Item (:representation head)) (text.join_with nested_new_line) - (text.enclose ["(" ")"]) + (text.enclosed ["(" ")"]) :abstraction))))) (def: #export (apply/* args func) diff --git a/stdlib/source/library/lux/time.lux b/stdlib/source/library/lux/time.lux index e726ad968..4a65fa4b8 100644 --- a/stdlib/source/library/lux/time.lux +++ b/stdlib/source/library/lux/time.lux @@ -148,7 +148,7 @@ (n.* utc_millis millis))))))) ) -(def: (pad value) +(def: (padded value) (-> Nat Text) (if (n.< 10 value) (text\compose "0" (n\encode value)) @@ -160,7 +160,7 @@ (duration.merge space duration) duration)) -(def: (encode_millis millis) +(def: (millis_format millis) (-> Nat Text) (cond (n.= 0 millis) "" (n.< 10 millis) ($_ text\compose ".00" (n\encode millis)) @@ -199,19 +199,19 @@ .nat ..of_millis)) -(def: (encode time) +(def: (format time) (-> Time Text) (let [(^slots [#hour #minute #second #milli_second]) (..clock time)] ($_ text\compose - (..pad hour) - ..separator (..pad minute) - ..separator (..pad second) - (..encode_millis milli_second)))) + (..padded hour) + ..separator (..padded minute) + ..separator (..padded second) + (..millis_format milli_second)))) (implementation: #export codec {#.doc (doc "Based on ISO 8601." "For example: 21:14:51.827")} (Codec Text Time) - (def: encode ..encode) + (def: encode ..format) (def: decode (.run ..parser))) diff --git a/stdlib/source/library/lux/time/date.lux b/stdlib/source/library/lux/time/date.lux index 79250a35e..1db01faf8 100644 --- a/stdlib/source/library/lux/time/date.lux +++ b/stdlib/source/library/lux/time/date.lux @@ -57,7 +57,7 @@ ["Year" (\ //year.codec encode year)] ["Month" (n\encode (//month.number month))])) -(def: (pad value) +(def: (padded value) (-> Nat Text) (let [digits (n\encode value)] (if (n.< 10 value) @@ -179,19 +179,19 @@ utc_day ..section_parser] (<>.lift (..date utc_year month utc_day)))) -(def: (encode value) +(def: (format value) (-> Date Text) ($_ text\compose (\ //year.codec encode (..year value)) - ..separator (..pad (|> value ..month //month.number)) - ..separator (..pad (..day_of_month value)))) + ..separator (..padded (|> value ..month //month.number)) + ..separator (..padded (..day_of_month value)))) (implementation: #export codec {#.doc (doc "Based on ISO 8601." "For example: 2017-01-15")} (Codec Text Date) - (def: encode ..encode) + (def: encode ..format) (def: decode (.run ..parser))) (def: days_per_leap diff --git a/stdlib/source/library/lux/time/instant.lux b/stdlib/source/library/lux/time/instant.lux index 8445ed977..e734e1bfc 100644 --- a/stdlib/source/library/lux/time/instant.lux +++ b/stdlib/source/library/lux/time/instant.lux @@ -124,7 +124,7 @@ //.of_millis try.assumed)) -(def: (encode instant) +(def: (format instant) (-> Instant Text) (let [[date time] (..split_date_time instant) time (..clock_time time)] @@ -152,7 +152,7 @@ "For example: 2017-01-15T21:14:51.827Z")} (Codec Text Instant) - (def: encode ..encode) + (def: encode ..format) (def: decode (.run ..parser))) (def: #export now diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux index f5e65f9bb..8588f52e0 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux @@ -356,7 +356,7 @@ (|> members (list\map %analysis) (text.join_with " ") - (text.enclose ["[" "]"]))) + (text.enclosed ["[" "]"]))) (#Reference reference) (reference.format reference) @@ -370,8 +370,8 @@ (format (|> environment (list\map %analysis) (text.join_with " ") - (text.enclose ["[" "]"]))) - (text.enclose ["(" ")"])) + (text.enclosed ["[" "]"]))) + (text.enclosed ["(" ")"])) (#Apply _) (|> analysis @@ -379,14 +379,14 @@ #.Item (list\map %analysis) (text.join_with " ") - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (#Extension name parameters) (|> parameters (list\map %analysis) (text.join_with " ") (format (%.text name) " ") - (text.enclose ["(" ")"])))) + (text.enclosed ["(" ")"])))) (template [ ] [(type: #export diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux index 9a34b72aa..99e1730f1 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux @@ -73,7 +73,7 @@ (#Bit value') (|> value' %.bit - (text.enclose ["(#Bit " ")"])) + (text.enclosed ["(#Bit " ")"])) (#Variant ?max_cases cases) (|> cases @@ -81,9 +81,9 @@ (list\map (function (_ [idx coverage]) (format (%.nat idx) " " (%coverage coverage)))) (text.join_with " ") - (text.enclose ["{" "}"]) + (text.enclosed ["{" "}"]) (format (%.nat (..cases ?max_cases)) " ") - (text.enclose ["(#Variant " ")"])) + (text.enclosed ["(#Variant " ")"])) (#Seq left right) (format "(#Seq " (%coverage left) " " (%coverage right) ")") diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis.lux index a1a979555..93e1c6d1f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis.lux @@ -10,7 +10,7 @@ ["." / #_ ["#." lux]]) -(def: #export (bundle eval host-specific) +(def: #export (bundle eval host_specific) (-> Eval Bundle Bundle) - (dictionary.merge host-specific + (dictionary.merge host_specific (/lux.bundle eval))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux index 9f43c5f28..87c1e59cc 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux @@ -125,7 +125,7 @@ ## ## (/.install "/" (binary (product.uncurry _.//2))) ## ## (/.install "%" (binary (product.uncurry _.rem/2))) ## ## (/.install "i64" (unary _.truncate/1)) -## (/.install "encode" (unary _.write-to-string/1)) +## (/.install "encode" (unary _.write_to_string/1)) ## ## (/.install "decode" (unary //runtime.f64//decode)) ## ))) @@ -139,7 +139,7 @@ ## (def: (text//char [index text]) ## (Binary (Expression Any)) -## (_.char-code/1 (_.char/2 [text index]))) +## (_.char_code/1 (_.char/2 [text index]))) (def: text_procs Bundle @@ -156,7 +156,7 @@ ## (def: (io//log! message) ## (Unary (Expression Any)) -## (_.progn (list (_.write-line/1 message) +## (_.progn (list (_.write_line/1 message) ## //runtime.unit))) ## (def: io_procs diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/loop.lux index bbb46cba2..5ceb08bc3 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/loop.lux @@ -66,5 +66,5 @@ list.enumeration (list\map (|>> product.left (n.+ offset) //case.register)) _.args)]] - (in (_.progn (list (_.multiple-value-setq bindings (_.values/* argsO+)) + (in (_.progn (list (_.multiple_value_setq bindings (_.values/* argsO+)) (_.go tag)))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js.lux index 20a26e9cb..e1c4dd247 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js.lux @@ -63,7 +63,7 @@ (//////phase\map _.return (/function.function statement expression archive abstraction)) )) -(exception: #export cannot-recur-as-an-expression) +(exception: #export cannot_recur_as_an_expression) (def: (expression archive synthesis) Phase @@ -101,7 +101,7 @@ (/loop.scope ..statement expression archive scope) (^ (synthesis.loop/recur updates)) - (//////phase.except ..cannot-recur-as-an-expression []) + (//////phase.except ..cannot_recur_as_an_expression []) (^ (synthesis.function/abstraction abstraction)) (/function.function ..statement expression archive abstraction) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux index 2fbaa82f3..06ae68255 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux @@ -729,7 +729,6 @@ (_.and (|> value ( top)))))] [within? _.<] - [up_to? _.<=] ) (def: (text_clip start end text) @@ -761,14 +760,13 @@ (..some (i64::of_float (|> idx (_.+ startF)))))) ..none)))) -(runtime: (text::clip text from to) +(runtime: (text::clip text minimum additional) (with_vars [length] ($_ _.then (_.set! length (_.length text)) - (_.if ($_ _.and - (|> to (within? length)) - (|> from (up_to? to))) - (..some (text_clip (inc from) (inc to) text)) + (_.set! to (_.+ additional minimum)) + (_.if (within? length to) + (..some (text_clip (inc minimum) (inc to) text)) ..none)))) (def: (char_at idx text) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/program.lux b/stdlib/source/library/lux/tool/compiler/language/lux/program.lux index 3f988197f..16b59870b 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/program.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/program.lux @@ -28,7 +28,7 @@ Text "") -(exception: #export (cannot-find-program {modules (List Module)}) +(exception: #export (cannot_find_program {modules (List Module)}) (exception.report ["Modules" (exception.enumerate %.text modules)])) @@ -43,15 +43,15 @@ [id (archive.id module archive) [descriptor document] (archive.find module archive)] (in [[module id] (get@ #descriptor.registry descriptor)])))))] - (case (list.one (function (_ [[module module-id] registry]) + (case (list.one (function (_ [[module module_id] registry]) (do maybe.monad - [program-id (artifact.remember ..name registry)] - (in [module-id program-id]))) + [program_id (artifact.remember ..name registry)] + (in [module_id program_id]))) registries) - (#.Some program-context) - (in program-context) + (#.Some program_context) + (in program_context) #.None (|> registries (list\map (|>> product.left product.left)) - (exception.except ..cannot-find-program))))) + (exception.except ..cannot_find_program))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux index 87be39c2a..e304e237c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux @@ -345,7 +345,9 @@ (#.Left [[where ] error]))) -(def: no_exponent Offset 0) +(def: no_exponent + Offset + 0) (with_expansions [ (as_is (!number_output source_code start end int.decimal #.Int)) (as_is (!number_output source_code start end frac.decimal #.Frac)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux index fdfebb72c..8559afe35 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux @@ -280,7 +280,7 @@ (list\map (function (_ [test then]) (format ( test) " " (%path' %then then)))) (text.join_with " ") - (text.enclose ["(? " ")"]))]) + (text.enclosed ["(? " ")"]))]) ([#I64_Fork (|>> .int %.int)] [#F64_Fork %.frac] [#Text_Fork %.text]) @@ -314,7 +314,7 @@ (#Then then) (|> (%then then) - (text.enclose ["(! " ")"])))) + (text.enclosed ["(! " ")"])))) (def: #export (%synthesis value) (Format Synthesis) @@ -336,13 +336,13 @@ (#analysis.Variant [lefts right? content]) (|> (%synthesis content) (format (%.nat lefts) " " (%.bit right?) " ") - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) (#analysis.Tuple members) (|> members (list\map %synthesis) (text.join_with " ") - (text.enclose ["[" "]"]))) + (text.enclosed ["[" "]"]))) (#Reference reference) (reference.format reference) @@ -355,36 +355,36 @@ (let [environment' (|> environment (list\map %synthesis) (text.join_with " ") - (text.enclose ["[" "]"]))] + (text.enclosed ["[" "]"]))] (|> (format environment' " " (%.nat arity) " " (%synthesis body)) - (text.enclose ["(#function " ")"]))) + (text.enclosed ["(#function " ")"]))) (#Apply func args) (|> args (list\map %synthesis) (text.join_with " ") (format (%synthesis func) " ") - (text.enclose ["(" ")"]))) + (text.enclosed ["(" ")"]))) (#Branch branch) (case branch (#Let input register body) (|> (format (%.nat register) " " (%synthesis input) " " (%synthesis body)) - (text.enclose ["(#let " ")"])) + (text.enclosed ["(#let " ")"])) (#If test then else) (|> (format (%synthesis test) " " (%synthesis then) " " (%synthesis else)) - (text.enclose ["(#if " ")"])) + (text.enclosed ["(#if " ")"])) (#Get members record) (|> (format (%.list (%path' %synthesis) (list\map (|>> #Member #Access) members)) " " (%synthesis record)) - (text.enclose ["(#get " ")"])) + (text.enclosed ["(#get " ")"])) (#Case input path) (|> (format (%synthesis input) " " (%path' %synthesis path)) - (text.enclose ["(#case " ")"]))) + (text.enclosed ["(#case " ")"]))) (#Loop loop) (case loop @@ -393,21 +393,21 @@ " " (|> (get@ #inits scope) (list\map %synthesis) (text.join_with " ") - (text.enclose ["[" "]"])) + (text.enclosed ["[" "]"])) " " (%synthesis (get@ #iteration scope))) - (text.enclose ["(#loop " ")"])) + (text.enclosed ["(#loop " ")"])) (#Recur args) (|> args (list\map %synthesis) (text.join_with " ") - (text.enclose ["(#recur " ")"])))) + (text.enclosed ["(#recur " ")"])))) (#Extension [name args]) (|> (list\map %synthesis args) (text.join_with " ") (format (%.text name) " ") - (text.enclose ["(" ")"])))) + (text.enclosed ["(" ")"])))) (def: #export %path (Format Path) diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux index 2239960c6..6af912b14 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux @@ -107,7 +107,7 @@ (get@ #descriptor.references) set.to_list (list.all (function (_ module) (dictionary.get module mapping))) - (list\map (|>> ..module_file _.string _.load-relative/1)) + (list\map (|>> ..module_file _.string _.load_relative/1)) (list\fold ..then bundle) (: _.Expression) _.code diff --git a/stdlib/source/library/lux/type.lux b/stdlib/source/library/lux/type.lux index 6b16939e4..f3f79adc2 100644 --- a/stdlib/source/library/lux/type.lux +++ b/stdlib/source/library/lux/type.lux @@ -84,7 +84,7 @@ (#.Primitive name params) ($_ text\compose "(primitive " - (text.enclose' text.double_quote name) + (text.enclosed' text.double_quote name) (|> params (list\map (|>> format (text\compose " "))) (list\fold (function.flip text\compose) "")) diff --git a/stdlib/source/library/lux/type/refinement.lux b/stdlib/source/library/lux/type/refinement.lux index f2709d5e2..35189a071 100644 --- a/stdlib/source/library/lux/type/refinement.lux +++ b/stdlib/source/library/lux/type/refinement.lux @@ -21,9 +21,9 @@ (All [t] (Ex [%] (-> (Predicate t) (Refiner t %)))) - (function (_ un_refined) - (if (predicate un_refined) - (#.Some (:abstraction {#value un_refined + (function (_ value) + (if (predicate value) + (#.Some (:abstraction {#value value #predicate predicate})) #.None))) @@ -32,7 +32,7 @@ (All [t %] (-> (Refined t %) )) (|>> :representation (get@ )))] - [un_refine t #value] + [value t #value] [predicate (Predicate t) #predicate] ) diff --git a/stdlib/source/library/lux/world/db/sql.lux b/stdlib/source/library/lux/world/db/sql.lux index 93cd86b48..656e079b4 100644 --- a/stdlib/source/library/lux/world/db/sql.lux +++ b/stdlib/source/library/lux/world/db/sql.lux @@ -15,7 +15,7 @@ (def: parenthesize (-> Text Text) - (text.enclose ["(" ")"])) + (text.enclosed ["(" ")"])) ## Kind (template [] @@ -37,17 +37,17 @@ [Source'] [DB'] - [No-Limit] [With-Limit] - [No-Offset] [With-Offset] + [No_Limit] [With_Limit] + [No_Offset] [With_Offset] [Order'] - [No-Order] [With-Order] - [No-Group] [With-Group] + [No_Order] [With_Order] + [No_Group] [With_Group] [(Query' order group limit offset)] [Command'] - [No-Where] [With-Where] [Without-Where] - [No-Having] [With-Having] [Without-Having] + [No_Where] [With_Where] [Without_Where] + [No_Having] [With_Having] [Without_Having] [(Action' where having kind)] [(Schema' kind)] @@ -57,7 +57,7 @@ (type: #export Alias Text) -(def: #export no-alias Alias "") +(def: #export no_alias Alias "") (abstract: #export (SQL kind) Text @@ -93,8 +93,8 @@ [Statement (Statement' Any)] ) - (def: Base-Query (.type (Query No-Where No-Having No-Order No-Group No-Limit No-Offset))) - (def: Any-Query (.type (Query Any Any Any Any Any Any))) + (def: Base_Query (.type (Query No_Where No_Having No_Order No_Group No_Limit No_Offset))) + (def: Any_Query (.type (Query Any Any Any Any Any Any))) (def: #export read {#.doc (doc "Only use this function for debugging purposes." @@ -109,7 +109,7 @@ (def: enumerate (-> (List (SQL Any)) Text) (|>> (list\map (|>> :representation)) - (text.join-with ", "))) + (text.join_with ", "))) ## Value (def: #export ? Placeholder (:abstraction "?")) @@ -136,13 +136,13 @@ (..parenthesize (..enumerate parameters))))) ## Condition - (template [ ] + (template [ ] [(def: #export ( reference sample) (-> Value Value Condition) (:abstraction (..parenthesize (format (:representation sample) - " " " " + " " " " (:representation reference)))))] [= "="] @@ -171,12 +171,12 @@ " IN " (..parenthesize (enumerate options))))) - (template [ ] - [(def: #export ( left right) + (template [ ] + [(def: #export ( left right) (-> Condition Condition Condition) (:abstraction (format (..parenthesize (:representation left)) - " " " " + " " " " (..parenthesize (:representation right)))))] [and "AND"] @@ -189,7 +189,7 @@ (|>> :representation ..parenthesize (format " ") :abstraction))] [not Condition "NOT"] - [exists Any-Query "EXISTS"] + [exists Any_Query "EXISTS"] ) ## Query @@ -198,14 +198,14 @@ (-> Source) (|>> :representation :abstraction))] - [from-table Table (<|)] - [from-view View (<|)] - [from-query Any-Query ..parenthesize] + [from_table Table (<|)] + [from_view View (<|)] + [from_query Any_Query ..parenthesize] ) - (template [ ] - [(def: #export ( columns source) - (-> (List [Column Alias]) Source Base-Query) + (template [ ] + [(def: #export ( columns source) + (-> (List [Column Alias]) Source Base_Query) (:abstraction (format " " @@ -216,42 +216,42 @@ _ (|> columns (list\map (.function (_ [column alias]) - (if (text\= ..no-alias alias) + (if (text\= ..no_alias alias) (:representation column) (format (:representation column) " AS " alias)))) - (text.join-with ", "))) + (text.join_with ", "))) " FROM " (:representation source))))] [select "SELECT"] - [select-distinct "SELECT DISTINCT"] + [select_distinct "SELECT DISTINCT"] ) - (template [ ] + (template [ ] [(def: #export ( table condition prev) - (-> Table Condition Base-Query Base-Query) + (-> Table Condition Base_Query Base_Query) (:abstraction (format (:representation prev) - " " " " + " " " " (:representation table) " ON " (:representation condition))))] - [inner-join "INNER JOIN"] - [left-join "LEFT JOIN"] - [right-join "RIGHT JOIN"] - [full-outer-join "FULL OUTER JOIN"] + [inner_join "INNER JOIN"] + [left_join "LEFT JOIN"] + [right_join "RIGHT JOIN"] + [full_outer_join "FULL OUTER JOIN"] ) - (template [ ] + (template [ ] [(def: #export ( left right) - (-> Any-Query Any-Query (Query Without-Where Without-Having No-Order No-Group No-Limit No-Offset)) + (-> Any_Query Any_Query (Query Without_Where Without_Having No_Order No_Group No_Limit No_Offset)) (:abstraction (format (:representation left) - " " " " + " " " " (:representation right))))] [union "UNION"] - [union-all "UNION ALL"] + [union_all "UNION ALL"] [intersect "INTERSECT"] ) @@ -265,12 +265,12 @@ (%.nat value))))] [limit "LIMIT" [where having order group offset] - (Query where having order group No-Limit offset) - (Query where having order group With-Limit offset)] + (Query where having order group No_Limit offset) + (Query where having order group With_Limit offset)] [offset "OFFSET" [where having order group limit] - (Query where having order group limit No-Offset) - (Query where having order group limit With-Offset)] + (Query where having order group limit No_Offset) + (Query where having order group limit With_Offset)] ) (template [ ] @@ -282,11 +282,11 @@ [descending "DESC"] ) - (def: #export (order-by pairs query) + (def: #export (order_by pairs query) (All [where having group limit offset] (-> (List [Value Order]) - (Query where having No-Order group limit offset) - (Query where having With-Order group limit offset))) + (Query where having No_Order group limit offset) + (Query where having With_Order group limit offset))) (case pairs #.End (|> query :representation :abstraction) @@ -298,13 +298,13 @@ (|> pairs (list\map (.function (_ [value order]) (format (:representation value) " " (:representation order)))) - (text.join-with ", ")))))) + (text.join_with ", ")))))) - (def: #export (group-by pairs query) + (def: #export (group_by pairs query) (All [where having order limit offset] (-> (List Value) - (Query where having order No-Group limit offset) - (Query where having order With-Group limit offset))) + (Query where having order No_Group limit offset) + (Query where having order With_Group limit offset))) (case pairs #.End (|> query :representation :abstraction) @@ -317,18 +317,18 @@ ## Command (def: #export (insert table columns rows) - (-> Table (List Column) (List (List Value)) (Command Without-Where Without-Having)) + (-> Table (List Column) (List (List Value)) (Command Without_Where Without_Having)) (:abstraction (format "INSERT INTO " (:representation table) " " (..parenthesize (..enumerate columns)) " VALUES " (|> rows (list\map (|>> ..enumerate ..parenthesize)) - (text.join-with ", ")) + (text.join_with ", ")) ))) (def: #export (update table pairs) - (-> Table (List [Column Value]) (Command No-Where No-Having)) + (-> Table (List [Column Value]) (Command No_Where No_Having)) (:abstraction (format "UPDATE " (:representation table) (case pairs #.End @@ -338,16 +338,16 @@ (format " SET " (|> pairs (list\map (.function (_ [column value]) (format (:representation column) "=" (:representation value)))) - (text.join-with ", "))))))) + (text.join_with ", "))))))) (def: #export delete - (-> Table (Command No-Where No-Having)) + (-> Table (Command No_Where No_Having)) (|>> :representation (format "DELETE FROM ") :abstraction)) ## Action (def: #export (where condition prev) (All [kind having] - (-> Condition (Action No-Where having kind) (Action With-Where having kind))) + (-> Condition (Action No_Where having kind) (Action With_Where having kind))) (:abstraction (format (:representation prev) " WHERE " @@ -355,7 +355,7 @@ (def: #export (having condition prev) (All [where kind] - (-> Condition (Action where No-Having kind) (Action where With-Having kind))) + (-> Condition (Action where No_Having kind) (Action where With_Having kind))) (:abstraction (format (:representation prev) " HAVING " @@ -373,7 +373,7 @@ (format (:representation attr) " " )))] [unique "UNIQUE"] - [not-null "NOT NULL"] + [not_null "NOT NULL"] [stored "STORED"] ) @@ -382,27 +382,27 @@ (:abstraction (format (:representation attr) " DEFAULT " (:representation value)))) - (def: #export (define-column name type) + (def: #export (define_column name type) (-> Column (Schema Value) (Schema Column)) (:abstraction (format (:representation name) " " (:representation type)))) - (def: #export (auto-increment offset column) + (def: #export (auto_increment offset column) (-> Int (Schema Column) (Schema Column)) (:abstraction (format (:representation column) " AUTO_INCREMENT=" (:representation (..int offset))))) - (def: #export (create-table or-replace? table columns) + (def: #export (create_table or_replace? table columns) (-> Bit Table (List (Schema Column)) Definition) - (let [command (if or-replace? + (let [command (if or_replace? "CREATE OR REPLACE TABLE" "CREATE TABLE IF NOT EXISTS")] (:abstraction (format command " " (:representation table) (..parenthesize (..enumerate columns)))))) - (def: #export (create-table-as table query) - (-> Table Any-Query Definition) + (def: #export (create_table_as table query) + (-> Table Any_Query Definition) (:abstraction (format "CREATE TABLE " (:representation table) " AS " (:representation query)))) @@ -416,12 +416,12 @@ [truncate "TRUNCATE"] ) - (def: #export (add-column table column) + (def: #export (add_column table column) (-> Table (Schema Column) Definition) (:abstraction (format "ALTER TABLE " (:representation table) " ADD " (:representation column)))) - (def: #export (drop-column table column) + (def: #export (drop_column table column) (-> Table Column Definition) (:abstraction (format "ALTER TABLE " (:representation table) " DROP COLUMN " (:representation column)))) @@ -443,22 +443,22 @@ (-> Definition) (|>> :representation (format " ") :abstraction))] - [create-db DB "CREATE DATABASE"] - [drop-db DB "DROP DATABASE"] - [drop-view View "DROP VIEW"] + [create_db DB "CREATE DATABASE"] + [drop_db DB "DROP DATABASE"] + [drop_view View "DROP VIEW"] ) (template [ ] [(def: #export ( view query) - (-> View Any-Query Definition) + (-> View Any_Query Definition) (:abstraction (format " " (:representation view) " AS " (:representation query))))] - [create-view "CREATE VIEW"] - [create-or-replace-view "CREATE OR REPLACE VIEW"] + [create_view "CREATE VIEW"] + [create_or_replace_view "CREATE OR REPLACE VIEW"] ) - (def: #export (create-index index table unique? columns) + (def: #export (create_index index table unique? columns) (-> Index Table Bit (List Column) Definition) (:abstraction (format "CREATE " (if unique? "UNIQUE" "") " INDEX " (:representation index) @@ -466,7 +466,7 @@ (def: #export (with alias query body) (All [where having order group limit offset] - (-> Table Any-Query + (-> Table Any_Query (Query where having order group limit offset) (Query where having order group limit offset))) (:abstraction diff --git a/stdlib/source/library/lux/world/net/http/cookie.lux b/stdlib/source/library/lux/world/net/http/cookie.lux index 1254923b8..2c5965338 100644 --- a/stdlib/source/library/lux/world/net/http/cookie.lux +++ b/stdlib/source/library/lux/world/net/http/cookie.lux @@ -20,18 +20,19 @@ ["." // (#+ Header) ["." header]]) -(type: #export Directive (-> Text Text)) +(type: #export Directive + (-> Text Text)) (def: (directive extension) (-> Text Directive) - (function (_ so-far) - (format so-far "; " extension))) + (function (_ so_far) + (format so_far "; " extension))) (def: #export (set name value) (-> Text Text Header) (header.add "Set-Cookie" (format name "=" value))) -(def: #export (max-age duration) +(def: #export (max_age duration) (-> Duration Directive) (let [seconds (duration.query duration.second duration)] (..directive (format "Max-Age=" (if (i.< +0 seconds) @@ -53,15 +54,15 @@ (..directive ))] [secure "Secure"] - [http-only "HttpOnly"] + [http_only "HttpOnly"] ) -(type: #export CSRF-Policy +(type: #export CSRF_Policy #Strict #Lax) -(def: #export (same-site policy) - (-> CSRF-Policy Directive) +(def: #export (same_site policy) + (-> CSRF_Policy Directive) (..directive (format "SameSite=" (case policy #Strict "Strict" #Lax "Lax")))) @@ -69,9 +70,9 @@ (def: (cookie context) (-> Context (Parser Context)) (do p.monad - [key (l.slice (l.many! (l.none-of! "="))) + [key (l.slice (l.many! (l.none_of! "="))) _ (l.this "=") - value (l.slice (l.many! (l.none-of! ";")))] + value (l.slice (l.many! (l.none_of! ";")))] (in (dictionary.put key value context)))) (def: (cookies context) diff --git a/stdlib/source/library/lux/world/net/http/query.lux b/stdlib/source/library/lux/world/net/http/query.lux index 4ee1c2cc2..0f78ba5e3 100644 --- a/stdlib/source/library/lux/world/net/http/query.lux +++ b/stdlib/source/library/lux/world/net/http/query.lux @@ -22,7 +22,7 @@ (p.rec (function (_ component) (do {! p.monad} - [head (l.some (l.none-of "+%&;"))] + [head (l.some (l.none_of "+%&;"))] ($_ p.either (p.after (p.either l.end (l.this "&")) @@ -35,7 +35,7 @@ [_ (l.this "%") code (|> (l.exactly 2 l.hexadecimal) (p.codec nat.hex) - (\ ! map text.from-code)) + (\ ! map text.from_code)) tail component] (in (format head code tail)))))))) @@ -46,7 +46,7 @@ [_ l.end] (in context)) (do {! p.monad} - [key (l.some (l.none-of "=&;")) + [key (l.some (l.none_of "=&;")) key (l.local key ..component)] (p.either (do ! [_ (l.this "=") @@ -54,7 +54,7 @@ (form (dictionary.put key value context))) (do ! [_ ($_ p.or - (l.one-of "&;") + (l.one_of "&;") l.end)] (form (dictionary.put key "" context))))) ## if invalid form data, just stop parsing... diff --git a/stdlib/source/library/lux/world/net/http/route.lux b/stdlib/source/library/lux/world/net/http/route.lux index 39d66cba0..a390c51bb 100644 --- a/stdlib/source/library/lux/world/net/http/route.lux +++ b/stdlib/source/library/lux/world/net/http/route.lux @@ -23,7 +23,7 @@ (server request) _ - (async.resolved //response.not-found))))] + (async.resolved //response.not_found))))] [#//.HTTP http] [#//.HTTPS https] @@ -38,7 +38,7 @@ (server request) _ - (async.resolved //response.not-found))))] + (async.resolved //response.not_found))))] [#//.Get get] [#//.Post post] @@ -54,14 +54,14 @@ (def: #export (uri path server) (-> URI Server Server) (function (_ [identification protocol resource message]) - (if (text.starts-with? path (get@ #//.uri resource)) + (if (text.starts_with? path (get@ #//.uri resource)) (server [identification protocol (update@ #//.uri (|>> (text.clip' (text.size path)) maybe.assume) resource) message]) - (async.resolved //response.not-found)))) + (async.resolved //response.not_found)))) (def: #export (or primary alternative) (-> Server Server Server) @@ -69,6 +69,6 @@ (do async.monad [response (primary request) #let [[status message] response]] - (if (n.= //status.not-found status) + (if (n.= //status.not_found status) (alternative request) (in response))))) diff --git a/stdlib/source/library/lux/world/service/authentication.lux b/stdlib/source/library/lux/world/service/authentication.lux index 4c66ddc1c..7cce79b8e 100644 --- a/stdlib/source/library/lux/world/service/authentication.lux +++ b/stdlib/source/library/lux/world/service/authentication.lux @@ -6,20 +6,20 @@ [security [capability (#+ Capability)]]]]]) -(type: #export (Can-Register ! account secret value) +(type: #export (Can_Register ! account secret value) (Capability [account secret value] (! (Try Any)))) -(type: #export (Can-Authenticate ! account secret value) +(type: #export (Can_Authenticate ! account secret value) (Capability [account secret] (! (Try value)))) -(type: #export (Can-Reset ! account secret) +(type: #export (Can_Reset ! account secret) (Capability [account secret] (! (Try Any)))) -(type: #export (Can-Forget ! account) +(type: #export (Can_Forget ! account) (Capability [account] (! (Try Any)))) (type: #export (Service ! account secret value) - {#can-register (Can-Register ! account secret value) - #can-authenticate (Can-Authenticate ! account secret value) - #can-reset (Can-Reset ! account secret) - #can-forget (Can-Forget ! account)}) + {#can_register (Can_Register ! account secret value) + #can_authenticate (Can_Authenticate ! account secret value) + #can_reset (Can_Reset ! account secret) + #can_forget (Can_Forget ! account)}) diff --git a/stdlib/source/library/lux/world/service/crud.lux b/stdlib/source/library/lux/world/service/crud.lux index bd47744f4..00eb870c5 100644 --- a/stdlib/source/library/lux/world/service/crud.lux +++ b/stdlib/source/library/lux/world/service/crud.lux @@ -14,20 +14,20 @@ {#created Instant #updated Instant}) -(capability: #export (Can-Create ! entity) - (can-create [Instant entity] (! (Try ID)))) +(capability: #export (Can_Create ! entity) + (can_create [Instant entity] (! (Try ID)))) -(capability: #export (Can-Retrieve ! entity) - (can-retrieve ID (! (Try [Time entity])))) +(capability: #export (Can_Retrieve ! entity) + (can_retrieve ID (! (Try [Time entity])))) -(capability: #export (Can-Update ! entity) - (can-update [ID Instant entity] (! (Try Any)))) +(capability: #export (Can_Update ! entity) + (can_update [ID Instant entity] (! (Try Any)))) -(capability: #export (Can-Delete ! entity) - (can-delete ID (! (Try Any)))) +(capability: #export (Can_Delete ! entity) + (can_delete ID (! (Try Any)))) (type: #export (CRUD ! entity) - {#can-create (Can-Create ! entity) - #can-retrieve (Can-Retrieve ! entity) - #can-update (Can-Update ! entity) - #can-delete (Can-Delete ! entity)}) + {#can_create (Can_Create ! entity) + #can_retrieve (Can_Retrieve ! entity) + #can_update (Can_Update ! entity) + #can_delete (Can_Delete ! entity)}) diff --git a/stdlib/source/library/lux/world/service/inventory.lux b/stdlib/source/library/lux/world/service/inventory.lux index b6f023075..f5b0dc807 100644 --- a/stdlib/source/library/lux/world/service/inventory.lux +++ b/stdlib/source/library/lux/world/service/inventory.lux @@ -12,20 +12,20 @@ {#owner ID #property ID}) -(capability: #export (Can-Own !) - (can-own Ownership (! (Try Any)))) +(capability: #export (Can_Own !) + (can_own Ownership (! (Try Any)))) -(capability: #export (Can-Disown !) - (can-disown Ownership (! (Try Any)))) +(capability: #export (Can_Disown !) + (can_disown Ownership (! (Try Any)))) -(capability: #export (Can-Check !) - (can-check Ownership (! (Try Bit)))) +(capability: #export (Can_Check !) + (can_check Ownership (! (Try Bit)))) -(capability: #export (Can-List-Property !) - (can-list-property ID (! (Try (List ID))))) +(capability: #export (Can_List_Property !) + (can_list_property ID (! (Try (List ID))))) (type: #export (Inventory !) - {#can-own (Can-Own !) - #can-disown (Can-Disown !) - #can-check (Can-Check !) - #can-list-property (Can-List-Property !)}) + {#can_own (Can_Own !) + #can_disown (Can_Disown !) + #can_check (Can_Check !) + #can_list_property (Can_List_Property !)}) diff --git a/stdlib/source/library/lux/world/service/journal.lux b/stdlib/source/library/lux/world/service/journal.lux index ba42af209..b82fdd83a 100644 --- a/stdlib/source/library/lux/world/service/journal.lux +++ b/stdlib/source/library/lux/world/service/journal.lux @@ -40,12 +40,12 @@ (text\= (get@ #where reference) (get@ #where sample)) (instant\= (get@ #when reference) (get@ #when sample))))) -(capability: #export (Can-Write ! a) - (can-write (Entry a) (! (Try Any)))) +(capability: #export (Can_Write ! a) + (can_write (Entry a) (! (Try Any)))) -(capability: #export (Can-Read ! a) - (can-read Range (! (Try (List (Entry a)))))) +(capability: #export (Can_Read ! a) + (can_read Range (! (Try (List (Entry a)))))) (type: #export (Journal ! a) - {#can-write (Can-Write ! a) - #can-read (Can-Read ! a)}) + {#can_write (Can_Write ! a) + #can_read (Can_Read ! a)}) diff --git a/stdlib/source/library/lux/world/service/mail.lux b/stdlib/source/library/lux/world/service/mail.lux index 2b2cc9dd1..8a5921e83 100644 --- a/stdlib/source/library/lux/world/service/mail.lux +++ b/stdlib/source/library/lux/world/service/mail.lux @@ -8,12 +8,12 @@ [security ["!" capability (#+ capability:)]]]]]) -(capability: #export (Can-Send ! address message) - (can-send [address message] (! (Try Any)))) +(capability: #export (Can_Send ! address message) + (can_send [address message] (! (Try Any)))) -(capability: #export (Can-Subscribe ! address message) - (can-subscribe [address] (! (Try (Channel message))))) +(capability: #export (Can_Subscribe ! address message) + (can_subscribe [address] (! (Try (Channel message))))) (type: #export (Service ! address message) - {#can-send (Can-Send ! address message) - #can-subscribe (Can-Subscribe ! address message)}) + {#can_send (Can_Send ! address message) + #can_subscribe (Can_Subscribe ! address message)}) diff --git a/stdlib/source/library/lux/world/shell.lux b/stdlib/source/library/lux/world/shell.lux index c9f524a69..8c4614a32 100644 --- a/stdlib/source/library/lux/world/shell.lux +++ b/stdlib/source/library/lux/world/shell.lux @@ -150,7 +150,7 @@ (..safe_common_command replacer)) safe_argument (: (Sanitizer Argument) (|>> (..replace "'" replacer) - (text.enclose' "'")))] + (text.enclosed' "'")))] (..policy safe_command safe_argument))) (def: windows_policy @@ -164,7 +164,7 @@ (|>> (..replace "%" replacer) (..replace "!" replacer) (..replace text.double_quote replacer) - (text.enclose' text.double_quote)))] + (text.enclosed' text.double_quote)))] (..policy safe_command safe_argument))) (with_expansions [ (as_is (import: java/lang/String diff --git a/stdlib/source/program/scriptum.lux b/stdlib/source/program/scriptum.lux index e429ff86f..fd66e6d61 100644 --- a/stdlib/source/program/scriptum.lux +++ b/stdlib/source/program/scriptum.lux @@ -454,7 +454,7 @@ (-> [Text Text] Text Text) (|> block (text.split_all_with text.new_line) - (list\map (text.enclose pre+post)) + (list\map (text.enclosed pre+post)) (text.join_with text.new_line))) (def: (document_module [[module_name module] organization]) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index bfdc93f30..11e3b6c73 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -22,11 +22,13 @@ ["%" format (#+ format)]] [collection ["." list]]] - [macro + ["." macro ["." code ("#\." equivalence)]] ["." math ["." random (#+ Random) ("#\." functor)] [number + [i8 (#+)] + [i16 (#+)] ["n" nat] ["i" int] ["r" rev] @@ -989,6 +991,36 @@ (and (is? expected (identity/constant expected)) (is? expected (identity/function expected)))))) +(.refer "library/lux/target" #*) +(.refer "library/lux/macro" #all) +(.refer "library/lux/math/number/nat" #_) +(.refer "library/lux/math/number/int" #nothing) +(.refer "library/lux/math/number/rev" (#+ /4096)) +(.refer "library/lux/math/number/frac" (#only positive_infinity)) +(.refer "library/lux/math/number/i8" (#- equivalence width i8 i64)) +(.refer "library/lux/math/number/i16" (#exclude equivalence width i16 i64)) + +(def: for_import + Test + (let [can_access? (: (All [a] (-> a a Bit)) + (function (_ global local) + (is? global local)))] + ($_ _.and + (_.cover [/.refer] + (and (can_access? library/lux/target.jvm + jvm) + (can_access? library/lux/macro.single_expansion + single_expansion) + (can_access? library/lux/math/number/rev./4096 + /4096) + (can_access? library/lux/math/number/frac.positive_infinity + positive_infinity) + (can_access? library/lux/math/number/i8.I8 + I8) + (can_access? library/lux/math/number/i16.I16 + I16))) + ))) + (def: test Test (<| (_.covering /._) @@ -1013,6 +1045,7 @@ ..for_case ..for_control_flow ..for_def: + ..for_import ..sub_tests ))) diff --git a/stdlib/source/test/lux/control/concurrency/semaphore.lux b/stdlib/source/test/lux/control/concurrency/semaphore.lux index 1e6dd9a48..3dff3aba1 100644 --- a/stdlib/source/test/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/test/lux/control/concurrency/semaphore.lux @@ -150,7 +150,7 @@ [_ (#.Some limit)] (and (n.> 0 raw) - (n.= raw (refinement.un_refine limit))) + (n.= raw (refinement.value limit))) _ false))) diff --git a/stdlib/source/test/lux/control/parser.lux b/stdlib/source/test/lux/control/parser.lux index b71ab1256..7370e0db0 100644 --- a/stdlib/source/test/lux/control/parser.lux +++ b/stdlib/source/test/lux/control/parser.lux @@ -220,13 +220,13 @@ actual))))) (_.cover [/.between] (and (|> (list\map code.nat expected+) - (/.run (/.between times variadic .nat)) + (/.run (/.between times (n.- times variadic) .nat)) (match actual (\ (list.equivalence n.equivalence) = expected+ actual))) (|> (list\map code.nat (list.take times expected+)) - (/.run (/.between times variadic .nat)) + (/.run (/.between times (n.- times variadic) .nat)) (match actual (\ (list.equivalence n.equivalence) = (list.take times expected+) diff --git a/stdlib/source/test/lux/control/parser/text.lux b/stdlib/source/test/lux/control/parser/text.lux index 84758e83b..055a2f858 100644 --- a/stdlib/source/test/lux/control/parser/text.lux +++ b/stdlib/source/test/lux/control/parser/text.lux @@ -282,13 +282,13 @@ second octal third octal] (_.cover [/.between /.between!] - (and (..should_pass (format first second) (/.between 2 3 /.octal)) - (..should_pass (format first second third) (/.between 2 3 /.octal)) - (..should_fail (format first) (/.between 2 3 /.octal)) + (and (..should_pass (format first second) (/.between 2 1 /.octal)) + (..should_pass (format first second third) (/.between 2 1 /.octal)) + (..should_fail (format first) (/.between 2 1 /.octal)) - (..should_pass! (format first second) (/.between! 2 3 octal!)) - (..should_pass! (format first second third) (/.between! 2 3 octal!)) - (..should_fail (format first) (/.between! 2 3 octal!))))) + (..should_pass! (format first second) (/.between! 2 1 octal!)) + (..should_pass! (format first second third) (/.between! 2 1 octal!)) + (..should_fail (format first) (/.between! 2 1 octal!))))) ))) (def: #export test diff --git a/stdlib/source/test/lux/control/parser/tree.lux b/stdlib/source/test/lux/control/parser/tree.lux index 4b3bf2cad..25f6c350c 100644 --- a/stdlib/source/test/lux/control/parser/tree.lux +++ b/stdlib/source/test/lux/control/parser/tree.lux @@ -61,7 +61,7 @@ [expected random.nat] (_.cover [/.run'] (|> (/.run' /.value - (zipper.zip (tree.leaf expected))) + (zipper.zipper (tree.leaf expected))) (!expect (^multi (#try.Success actual) (n.= expected actual)))))) (!cover [/.down] diff --git a/stdlib/source/test/lux/control/remember.lux b/stdlib/source/test/lux/control/remember.lux index 5f62bac4b..bd9833aec 100644 --- a/stdlib/source/test/lux/control/remember.lux +++ b/stdlib/source/test/lux/control/remember.lux @@ -72,10 +72,10 @@ message (product.right (random.run prng ..message)) expected (product.right (random.run prng ..focus))] (do meta.monad - [should_fail0 (..attempt (macro.expand (to_remember macro yesterday message #.None))) - should_fail1 (..attempt (macro.expand (to_remember macro yesterday message (#.Some expected)))) - should_succeed0 (..attempt (macro.expand (to_remember macro tomorrow message #.None))) - should_succeed1 (..attempt (macro.expand (to_remember macro tomorrow message (#.Some expected))))] + [should_fail0 (..attempt (macro.expansion (to_remember macro yesterday message #.None))) + should_fail1 (..attempt (macro.expansion (to_remember macro yesterday message (#.Some expected)))) + should_succeed0 (..attempt (macro.expansion (to_remember macro tomorrow message #.None))) + should_succeed1 (..attempt (macro.expansion (to_remember macro tomorrow message (#.Some expected))))] (in (list (code.bit (and (case should_fail0 (#try.Failure error) (and (test_failure yesterday message #.None error) diff --git a/stdlib/source/test/lux/data/collection/list.lux b/stdlib/source/test/lux/data/collection/list.lux index 2374b2f21..a2fc3911d 100644 --- a/stdlib/source/test/lux/data/collection/list.lux +++ b/stdlib/source/test/lux/data/collection/list.lux @@ -280,9 +280,9 @@ sample/1 ..random sample/2 ..random] ($_ _.and - (_.cover [/.as_pairs] + (_.cover [/.pairs] (n.= (n./ 2 (/.size sample/0)) - (/.size (/.as_pairs sample/0)))) + (/.size (/.pairs sample/0)))) (_.cover [/.zipped/2] (let [zipped (/.zipped/2 sample/0 sample/1) zipped::size (/.size zipped) @@ -412,7 +412,7 @@ (let [sample+ (/.interpose separator sample)] (and (n.= (|> (/.size sample) (n.* 2) dec) (/.size sample+)) - (|> sample+ /.as_pairs (/.every? (|>> product.right (n.= separator)))))))) + (|> sample+ /.pairs (/.every? (|>> product.right (n.= separator)))))))) (_.cover [/.iterate] (or (/.empty? sample) (let [size (/.size sample)] diff --git a/stdlib/source/test/lux/data/collection/tree/zipper.lux b/stdlib/source/test/lux/data/collection/tree/zipper.lux index 35b55f4bf..df7333db5 100644 --- a/stdlib/source/test/lux/data/collection/tree/zipper.lux +++ b/stdlib/source/test/lux/data/collection/tree/zipper.lux @@ -33,14 +33,14 @@ ($_ _.and (_.cover [/.down] (|> (tree.branch dummy (list (tree.leaf expected))) - /.zip + /.zipper (do> maybe.monad [/.down] [/.value (n.= expected) in]) (maybe.default false))) (_.cover [/.up] (|> (tree.branch expected (list (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.down] [/.up] @@ -48,7 +48,7 @@ (maybe.default false))) (_.cover [/.right] (|> (tree.branch dummy (list (tree.leaf dummy) (tree.leaf expected))) - /.zip + /.zipper (do> maybe.monad [/.down] [/.right] @@ -60,7 +60,7 @@ (tree.leaf dummy) (tree.leaf dummy) (tree.leaf expected))) - /.zip + /.zipper (do> maybe.monad [/.down] [/.rightmost] @@ -68,7 +68,7 @@ (maybe.default false))) (_.cover [/.left] (|> (tree.branch dummy (list (tree.leaf expected) (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.down] [/.right] @@ -81,7 +81,7 @@ (tree.leaf dummy) (tree.leaf dummy) (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.down] [/.rightmost] @@ -92,7 +92,7 @@ (and (|> (tree.branch dummy (list (tree.leaf expected) (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.next] [/.value (n.= expected) in]) @@ -100,7 +100,7 @@ (|> (tree.branch dummy (list (tree.leaf dummy) (tree.leaf expected))) - /.zip + /.zipper (do> maybe.monad [/.next] [/.next] @@ -112,7 +112,7 @@ (tree.leaf dummy) (tree.leaf dummy) (tree.leaf expected))) - /.zip + /.zipper (do> maybe.monad [/.end] [/.value (n.= expected) in]) @@ -123,7 +123,7 @@ (tree.leaf dummy) (tree.leaf dummy) (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.end] [/.start] @@ -133,7 +133,7 @@ (and (|> (tree.branch expected (list (tree.leaf dummy) (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.next] [/.previous] @@ -142,7 +142,7 @@ (|> (tree.branch dummy (list (tree.leaf expected) (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.next] [/.next] @@ -163,45 +163,45 @@ (^open "list\.") (list.equivalence n.equivalence)]] ($_ _.and (_.for [/.equivalence] - ($equivalence.spec (/.equivalence n.equivalence) (\ ! map (|>> product.right /.zip) (//.tree random.nat)))) + ($equivalence.spec (/.equivalence n.equivalence) (\ ! map (|>> product.right /.zipper) (//.tree random.nat)))) (_.for [/.functor] - ($functor.spec (|>> tree.leaf /.zip) /.equivalence /.functor)) + ($functor.spec (|>> tree.leaf /.zipper) /.equivalence /.functor)) (_.for [/.comonad] - ($comonad.spec (|>> tree.leaf /.zip) /.equivalence /.comonad)) + ($comonad.spec (|>> tree.leaf /.zipper) /.equivalence /.comonad)) - (_.cover [/.zip /.unzip] - (|> sample /.zip /.unzip (tree\= sample))) + (_.cover [/.zipper /.tree] + (|> sample /.zipper /.tree (tree\= sample))) (_.cover [/.start?] - (|> sample /.zip /.start?)) + (|> sample /.zipper /.start?)) (_.cover [/.leaf?] - (/.leaf? (/.zip (tree.leaf expected)))) + (/.leaf? (/.zipper (tree.leaf expected)))) (_.cover [/.branch?] - (and (/.branch? (/.zip (tree.branch expected (list (tree.leaf expected))))) - (not (/.branch? (/.zip (tree.branch expected (list))))))) + (and (/.branch? (/.zipper (tree.branch expected (list (tree.leaf expected))))) + (not (/.branch? (/.zipper (tree.branch expected (list))))))) (_.cover [/.value] - (and (n.= expected (/.value (/.zip (tree.leaf expected)))) - (n.= expected (/.value (/.zip (tree.branch expected (list (tree.leaf expected)))))))) + (and (n.= expected (/.value (/.zipper (tree.leaf expected)))) + (n.= expected (/.value (/.zipper (tree.branch expected (list (tree.leaf expected)))))))) (_.cover [/.set] - (|> (/.zip (tree.leaf dummy)) + (|> (/.zipper (tree.leaf dummy)) (/.set expected) /.value (n.= expected))) (_.cover [/.update] - (|> (/.zip (tree.leaf expected)) + (|> (/.zipper (tree.leaf expected)) (/.update inc) /.value (n.= (inc expected)))) ..move (_.cover [/.end?] - (or (/.end? (/.zip sample)) + (or (/.end? (/.zipper sample)) (|> sample - /.zip + /.zipper /.end (maybe\map /.end?) (maybe.default false)))) (_.cover [/.interpose] (let [cursor (|> (tree.branch dummy (list (tree.leaf dummy))) - /.zip + /.zipper (/.interpose expected))] (and (n.= dummy (/.value cursor)) (|> cursor @@ -217,7 +217,7 @@ (maybe.default false))))) (_.cover [/.adopt] (let [cursor (|> (tree.branch dummy (list (tree.leaf dummy))) - /.zip + /.zipper (/.adopt expected))] (and (n.= dummy (/.value cursor)) (|> cursor @@ -233,7 +233,7 @@ (maybe.default false))))) (_.cover [/.insert_left] (|> (tree.branch dummy (list (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.down] [(/.insert_left expected)] @@ -242,7 +242,7 @@ (maybe.default false))) (_.cover [/.insert_right] (|> (tree.branch dummy (list (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.down] [(/.insert_right expected)] @@ -251,7 +251,7 @@ (maybe.default false))) (_.cover [/.remove] (|> (tree.branch dummy (list (tree.leaf dummy))) - /.zip + /.zipper (do> maybe.monad [/.down] [(/.insert_left expected)] diff --git a/stdlib/source/test/lux/data/text.lux b/stdlib/source/test/lux/data/text.lux index 7223497d1..f39c25c01 100644 --- a/stdlib/source/test/lux/data/text.lux +++ b/stdlib/source/test/lux/data/text.lux @@ -65,15 +65,15 @@ [/.prefix /.starts_with?] [/.suffix /.ends_with?] - [/.enclose' /.encloses?] + [/.enclosed' /.enclosed_by?] )) - (_.cover [/.enclose] - (let [value (/.enclose [left right] inner)] + (_.cover [/.enclosed] + (let [value (/.enclosed [left right] inner)] (and (/.starts_with? left value) (/.ends_with? right value)))) (_.cover [/.format] (let [sample (/.format inner)] - (and (/.encloses? /.double_quote sample) + (and (/.enclosed_by? /.double_quote sample) (/.contains? inner sample)))) )))) diff --git a/stdlib/source/test/lux/debug.lux b/stdlib/source/test/lux/debug.lux index 638afd90f..a7741082a 100644 --- a/stdlib/source/test/lux/debug.lux +++ b/stdlib/source/test/lux/debug.lux @@ -210,13 +210,13 @@ (: (List Any)) (list\map /.inspection) (text.join_with " ") - (text.enclose ["[" "]"])) + (text.enclosed ["[" "]"])) (/.inspection [sample_bit sample_int sample_frac sample_text])) ))))) (syntax: (macro_error macro) (function (_ compiler) - (case ((macro.expand macro) compiler) + (case ((macro.expansion macro) compiler) (#try.Failure error) (#try.Success [compiler (list (code.text error))]) diff --git a/stdlib/source/test/lux/ffi.jvm.lux b/stdlib/source/test/lux/ffi.jvm.lux index 4eb815ff7..b5d9fffbf 100644 --- a/stdlib/source/test/lux/ffi.jvm.lux +++ b/stdlib/source/test/lux/ffi.jvm.lux @@ -56,7 +56,7 @@ (syntax: (macro_error expression) (function (_ lux) - (|> (macro.expand_once expression) + (|> (macro.single_expansion expression) (meta.run lux) (case> (#try.Success expansion) (#try.Failure "OOPS!") diff --git a/stdlib/source/test/lux/macro.lux b/stdlib/source/test/lux/macro.lux index 20db9b265..115b5168e 100644 --- a/stdlib/source/test/lux/macro.lux +++ b/stdlib/source/test/lux/macro.lux @@ -75,9 +75,9 @@ {#.module_hash 0 #.module_aliases (list) #.definitions (: (List [Text .Global]) - (list (!global /.log_expand_once!) - (!global /.log_expand!) - (!global /.log_expand_all!))) + (list (!global /.log_single_expansion!) + (!global /.log_expansion!) + (!global /.log_full_expansion!))) #.imports (list) #.tags (list) #.types (list) @@ -113,11 +113,11 @@ pow/1 (\ ! map code.nat random.nat) repetitions (\ ! map (nat.% 10) random.nat) - #let [expand_once (` (..pow/2 (..pow/2 (~ pow/1)))) - expand (` (nat.* (..pow/2 (~ pow/1)) + #let [single_expansion (` (..pow/2 (..pow/2 (~ pow/1)))) + expansion (` (nat.* (..pow/2 (~ pow/1)) (..pow/2 (~ pow/1)))) - expand_all (` (nat.* (nat.* (~ pow/1) (~ pow/1)) - (nat.* (~ pow/1) (~ pow/1))))]] + full_expansion (` (nat.* (nat.* (~ pow/1) (~ pow/1)) + (nat.* (~ pow/1) (~ pow/1))))]] (`` ($_ _.and (~~ (template [ ] [(_.cover [] @@ -128,22 +128,22 @@ (try.default false))) (_.cover [] - (and (|> (/.expand_once (` ( (~' #omit) (..pow/4 (~ pow/1))))) + (and (|> (/.single_expansion (` ( (~' #omit) (..pow/4 (~ pow/1))))) (meta.run lux) (try\map (\ (list.equivalence code.equivalence) = (list))) (try.default false)) - (|> (/.expand_once (` ( (..pow/4 (~ pow/1))))) + (|> (/.single_expansion (` ( (..pow/4 (~ pow/1))))) (meta.run lux) (try\map (\ (list.equivalence code.equivalence) = (list ))) (try.default false))))] - [/.expand_once /.log_expand_once! expand_once] - [/.expand /.log_expand! expand] - [/.expand_all /.log_expand_all! expand_all] + [/.single_expansion /.log_single_expansion! single_expansion] + [/.expansion /.log_expansion! expansion] + [/.full_expansion /.log_full_expansion! full_expansion] )) - (_.cover [/.expand_1] + (_.cover [/.one_expansion] (bit\= (not (nat.= 1 repetitions)) - (|> (/.expand_1 (` (..repeat (~ (code.nat repetitions)) (~ pow/1)))) + (|> (/.one_expansion (` (..repeat (~ (code.nat repetitions)) (~ pow/1)))) (meta.run lux) (!expect (#try.Failure _))))) )))) @@ -163,10 +163,10 @@ (and (text.contains? gensym_prefix actual_gensym) (text.contains? (%.nat seed) actual_gensym)))))) (_.cover [/.wrong_syntax_error] - (|> (/.expand_once (` (/.log_expand_once!))) + (|> (/.single_expansion (` (/.log_single_expansion!))) (meta.run lux) (!expect (^multi (#try.Failure error) - (text.contains? (/.wrong_syntax_error (name_of /.log_expand_once!)) + (text.contains? (/.wrong_syntax_error (name_of /.log_single_expansion!)) error))))) (_.cover [/.with_gensyms] (with_expansions [ (fresh_identifier)] diff --git a/stdlib/source/test/lux/macro/local.lux b/stdlib/source/test/lux/macro/local.lux index 37b718a8e..8b8a14790 100644 --- a/stdlib/source/test/lux/macro/local.lux +++ b/stdlib/source/test/lux/macro/local.lux @@ -29,7 +29,7 @@ (syntax: (macro_error macro) (function (_ compiler) - (case ((macro.expand macro) compiler) + (case ((macro.expansion macro) compiler) (#try.Failure error) (#try.Success [compiler (list (code.text error))]) @@ -61,7 +61,7 @@ (exec (~ pop!) (~ g!output))))] (if pre_remove - (macro.expand_all pre_expansion) + (macro.full_expansion pre_expansion) (in (list pre_expansion))))))) (def: #export test diff --git a/stdlib/source/test/lux/macro/template.lux b/stdlib/source/test/lux/macro/template.lux index c46bb5b8c..ecec132d7 100644 --- a/stdlib/source/test/lux/macro/template.lux +++ b/stdlib/source/test/lux/macro/template.lux @@ -28,7 +28,7 @@ (syntax: (macro_error macro) (function (_ compiler) - (case ((macro.expand macro) compiler) + (case ((macro.expansion macro) compiler) (#try.Failure error) (#try.Success [compiler (list (code.text error))]) diff --git a/stdlib/source/test/lux/math/number/int.lux b/stdlib/source/test/lux/math/number/int.lux index 99738824a..00b66d700 100644 --- a/stdlib/source/test/lux/math/number/int.lux +++ b/stdlib/source/test/lux/math/number/int.lux @@ -177,9 +177,11 @@ (and subtraction! inverse!)))) (do {! random.monad} - [expected (\ ! map (/.% +1,000,000) random.int)] + [expected (\ ! map (/.% +1,000,000) random.int) + sample random.int] (_.cover [/.frac] - (|> expected /.frac f.int (/.= expected)))) + (and (|> expected /.frac f.int (/.= expected)) + (f.number? (/.frac sample))))) (do {! random.monad} [pattern random.int idx (\ ! map (n.% i64.width) random.nat)] diff --git a/stdlib/source/test/lux/math/number/nat.lux b/stdlib/source/test/lux/math/number/nat.lux index 3d553e167..05fbfb303 100644 --- a/stdlib/source/test/lux/math/number/nat.lux +++ b/stdlib/source/test/lux/math/number/nat.lux @@ -121,9 +121,11 @@ (/.= 0 (/.% right lcm))))) )) (do {! random.monad} - [expected (\ ! map (/.% 1,000,000) random.nat)] + [expected (\ ! map (/.% 1,000,000) random.nat) + sample random.nat] (_.cover [/.frac] - (|> expected /.frac f.nat (/.= expected)))) + (and (|> expected /.frac f.nat (/.= expected)) + (f.number? (/.frac sample))))) ..predicate ..signature diff --git a/stdlib/source/test/lux/math/number/rev.lux b/stdlib/source/test/lux/math/number/rev.lux index a302b2fc3..e99a1f656 100644 --- a/stdlib/source/test/lux/math/number/rev.lux +++ b/stdlib/source/test/lux/math/number/rev.lux @@ -156,9 +156,11 @@ (|> sample /.reciprocal .nat /.reciprocal .nat /.reciprocal)))) (do {! random.monad} [expected (\ ! map (|>> f.abs (f.% +1.0)) - random.safe_frac)] + random.safe_frac) + sample random.rev] (_.cover [/.frac] - (|> expected f.rev /.frac (f.= expected)))) + (and (|> expected f.rev /.frac (f.= expected)) + (f.number? (/.frac sample))))) ..signature )))) diff --git a/stdlib/source/test/lux/type/abstract.lux b/stdlib/source/test/lux/type/abstract.lux index aaeb6f1b6..2b96f6788 100644 --- a/stdlib/source/test/lux/type/abstract.lux +++ b/stdlib/source/test/lux/type/abstract.lux @@ -34,7 +34,7 @@ (syntax: (with_no_active_frames macro) (function (_ compiler) - (let [verdict (case ((macro.expand macro) compiler) + (let [verdict (case ((macro.expansion macro) compiler) (#try.Failure error) (exception.match? /.no_active_frames error) diff --git a/stdlib/source/test/lux/type/refinement.lux b/stdlib/source/test/lux/type/refinement.lux index 52c8fac88..ecfbe8aab 100644 --- a/stdlib/source/test/lux/type/refinement.lux +++ b/stdlib/source/test/lux/type/refinement.lux @@ -48,20 +48,20 @@ (maybe\map (|>> /.predicate (is? predicate))) (maybe.default false))) )) - (_.cover [/.un_refine] + (_.cover [/.value] (|> (/.refinement predicate modulus) - (maybe\map (|>> /.un_refine (n.= modulus))) + (maybe\map (|>> /.value (n.= modulus))) (maybe.default false))) (_.cover [/.lift] (and (|> (/.refinement predicate modulus) (maybe\map (/.lift (n.+ modulus))) maybe\join - (maybe\map (|>> /.un_refine (n.= (n.+ modulus modulus)))) + (maybe\map (|>> /.value (n.= (n.+ modulus modulus)))) (maybe.default false)) (|> (/.refinement predicate modulus) (maybe\map (/.lift (n.+ (inc modulus)))) maybe\join - (maybe\map (|>> /.un_refine (n.= (n.+ modulus (inc modulus))))) + (maybe\map (|>> /.value (n.= (n.+ modulus (inc modulus))))) (maybe.default false) not))) (_.cover [/.only] @@ -71,7 +71,7 @@ (list.size actual)) (\ (list.equivalence n.equivalence) = expected - (list\map /.un_refine actual))))) + (list\map /.value actual))))) (_.cover [/.partition] (let [expected (list.only predicate raws) [actual alternative] (/.partition (/.refinement predicate) raws)] @@ -81,7 +81,7 @@ (list.size alternative)) (\ (list.equivalence n.equivalence) = expected - (list\map /.un_refine actual))))) + (list\map /.value actual))))) (_.cover [/.type] (exec (: (Maybe .._type) (.._refiner raw)) diff --git a/stdlib/source/test/lux/type/resource.lux b/stdlib/source/test/lux/type/resource.lux index cd6f78096..f761a0f3f 100644 --- a/stdlib/source/test/lux/type/resource.lux +++ b/stdlib/source/test/lux/type/resource.lux @@ -153,7 +153,7 @@ [[_ _ _ exception] (meta.export exception)] (function (_ compiler) (#.Right [compiler - (list (code.bit (case ((macro.expand_once to_expand) compiler) + (list (code.bit (case ((macro.single_expansion to_expand) compiler) (#try.Success _) false -- cgit v1.2.3