diff options
152 files changed, 1534 insertions, 1115 deletions
diff --git a/documentation/book/the_lux_programming_language/chapter_7.md b/documentation/book/the_lux_programming_language/chapter_7.md index 49c204626..75ec91400 100644 --- a/documentation/book/the_lux_programming_language/chapter_7.md +++ b/documentation/book/the_lux_programming_language/chapter_7.md @@ -186,5 +186,5 @@ It may be the case that in the future Lux adds new mechanisms for achieving the Now that we've discussed _interfaces_ and _implementations_, it's time to talk about a _very special family of interfaces_. -See you in the next chapter! +See you in [the next chapter](chapter_8.md)! diff --git a/documentation/book/the_lux_programming_language/chapter_8.md b/documentation/book/the_lux_programming_language/chapter_8.md new file mode 100644 index 000000000..11b56faf8 --- /dev/null +++ b/documentation/book/the_lux_programming_language/chapter_8.md @@ -0,0 +1,315 @@ +# Chapter 8: Functors and Monads + +_Where I will try to explain something really confusing, and you'll pretend you understand to avoid hurting my feelings._ + +--- + +OK. It's time to get serious. + +The following topics are known to be troublesome to teach, so I can only promise you that I will try really, really hard not too say something confusing (or stupid). + +## Functors + +Functors and monads are both mathematical concepts that are prevalent in **Category Theory**. You may have heard of it before. It's a branch of abstract mathematics that many are drawing inspiration from when developing new tools and techniques for functional programming. + +But I will not go down the route of explaining things to you from a mathematical perspective... as I'm not confident that's going to work. + +--- + +Imagine that you have some data (maybe an `Int`, or a `Text`). You can work with that data: you can pass it around, apply functions to it, print it to the console/terminal, or pattern-match against it. + +Well, imagine a functor as some kind of wrapper on your data. You can still access what's inside, but the wrapper itself offers special superpowers, and each wrapper is different. + +For instance, there's one wrapper that allows us to have (or not to have) our data. + +Schrodinger's wrapper (although most people prefer to call it `Maybe`). + +That wrapper happens to be a type, as **all** functor wrappers are types. + +But not just any type. You see, functors have requirements. + +``` +(interface: #export (Functor f) + (: (All [a b] + (-> (-> a b) (f a) (f b))) + map)) +``` + +This is the `Functor` interface, from `lux/abstract/functor`. + +As you can see, it only has a single member: the `map` function. + +The parameter type `f` is very special, because instead of being a simple type (like `Int` or `Text`), it's actually a parameterized type (with a single parameter). That explains why it's being used the way it is in the type of `map`. + +Not every parameterized type can be a functor, but if the type is something that you can open to work with its inner elements, then it becomes a good candidate. + + And you would be surprised how many things fit that requirement. + +Remember that `Maybe` type we talked about? Let's see how it plays with `Functor`. + +``` +(type: (Maybe a) + #.None + (#.Some a)) +``` + +We've seen `Maybe` before, but now we can check out how it's implemented. + + By the way, it lives in the `library/lux` module, so you don't need to import anything. + +Here is its `Functor` implementation. + +``` +(implementation: #export functor + (Functor Maybe) + + (def: (map f ma) + (case ma + #.None #.None + (#.Some a) (#.Some (f a))))) + +## This one lives in the library/lux/data/maybe module, though. +``` + +We'll know how everything fits if we fill in the blanks for `map`'s type: + +``` +(All [a b] + (-> (-> a b) (Maybe a) (Maybe b)) +``` + +So, the job of `map` here is to take a `Maybe` containing some `a` value, and somehow transform it into a `b`, without escaping the `Maybe`. + +By looking at the `Functor` implementation, we can see how this works out. + +We can actually pattern-match against the entire input and handle the different cases, using the given function to transform our `a` into a `b`. + +Not that hard. + +Oh, and remember our `iterate_list` function from [chapter 5](chapter_5.md)? + +Turns out, that's just the `Functor` implementation from `lux/data/collection/list`: + +``` +(implementation: #export functor + (Functor List) + + (def: (map f ma) + (case ma + #.End #.End + (#.Item a ma') (#.Item (f a) (map f ma'))))) +``` + +Not bad. + +In the case of `List`, the wrapper superpower it provides is the capacity to handle multiple values as a group. This can be used for some really cool techniques; like implementing non-deterministic computations by treating every list element as a branching value (but let's not go down that rabbit-hole for now). + +The power of functors is that they allow you to decorate your types with extra functionality. You can still access the inner data and the `map` function will take advantage of the wrapper's properties to give you that extra power you want. + +You can implement things like stateful computations, error-handling, logging, I/O, asynchronous concurrency and many other crazy things with the help of functors. + +However, to make them really easy to use, you might want to add some extra functionality. + +## Monads + +One thing you may have noticed about the `Functor` interface is that you have a way to operate on functorial values, but you don't have any _standardized_ means of creating them. + +I mean, you can use the `list` and `list&` macros to create lists and the `#.None` and `#.Some` tags for `Maybe`, but there is no unified way for creating **any** functorial value. + +Well, let me introduce you to `Monad`: + +``` +(interface: #export (Monad m) + (: (Functor m) + &functor) + (: (All [a] + (-> a (m a))) + in) + (: (All [a] + (-> (m (m a)) (m a))) + join)) +``` + +This interface extends `Functor` with both the capacity to wrap a normal value `in` functorial structure, and to `join` 2 layers of functorial structure into a single one. + +Sweet! + +Wrapping makes working with functors so much easier because you don't need to memorize a bunch of tags, macros or functions in order to create the structures that you need. + +And being able to join layers of functorial structure allows you to write dynamic computations which make use of the functorial structure and that can depend on the value of previous functorial computations. + +To get a taste for it, let's check out another functorial type. + +Remember what I said about error-handling? + +``` +(type: #export (Try a) + (#Failure Text) + (#Success a)) +``` + +This type expresses errors as `Text` values (and it lives in the `lux/control/try` module). + +Here are the relevant `Functor` and `Monad` implementations: + +``` +(implementation: #export functor + (Functor Try) + + (def: (map f ma) + (case ma + (#Failure msg) + (#Failure msg) + + (#Success datum) + (#Success (f datum))))) + +(implementation: #export monad + (Monad Try) + + (def: &functor ..functor) + + (def: (in a) + (#Success a)) + + (def: (join mma) + (case mma + (#Failure msg) + (#Failure msg) + + (#Success ma) + ma))) +``` + +If you listen to functional programmers, you'll likely get the impression that the invention of monads rivals the invention of the wheel. It is this incredibly powerful and fundamental abstraction for a lot of functional programs. + +The thing about `Monad` is that, with it, you can use `map` functions that also generate wrapped values (and take advantage of their special properties), and then you can collapse/merge/combine those values into a "joined" value by using the `join` function. + +Let's see that in action: + +``` +(.module: + [library + [lux #* + [data + [collection + ["." list]]]]]) + +(open: list.monad) + +(def foo + (|> (list 1 2 3 4) + (map (list.repeated 3)) + join)) + +## The value of 'foo' is: +(list 1 1 1 2 2 2 3 3 3 4 4 4) +``` + +_It's magic!_ + +Not really. It's just the `Monad` for `List`: + +``` +(implementation: #export functor + (Functor List) + + (def: (map f ma) + (case ma + #.End + #.End + + (#.Item a ma') + (#.Item (f a) (map f ma'))))) + +(implementation: #export fold + (Fold List) + + (def: (fold f init xs) + (case xs + #.End + init + + (#.Item x xs') + (fold f (f x init) xs')))) + +(implementation: #export monoid + (All [a] (Monoid (List a))) + + (def: identity #.End) + (def: (compose xs ys) + (case xs + #.End + ys + + (#.Item x xs') + (#.Item x (compose xs' ys))))) + +(open: "." ..monoid) + +(implementation: #export monad + (Monad List) + + (def: &functor ..functor) + + (def: (in a) + (#.Item a #.End)) + + (def: (join list_of_lists) + (|> list_of_lists reversed (fold compose identity)))) + +## The fold function is for doing incremental iterative computations. +## Here, we're using it to build the total output list by composing/concatenating all the input lists in our `list_of_lists`. +``` + +`Monad`s are incredibly powerful, since being able to use the special power of our `Functor` while `map`ping functions allows us to layer that power in complex ways. + +But... you're probably thinking that writing a bunch of `map`s followed by `join`s is a very tedious process. And, you're right! + +If functional programmers had to subject themselves to that kind of tedium all the time, they'd probably not be so excited about monads. + +Time for the VIP treatment. + +## The `do` Macro + +These macros always show up at the right time to saves us from our hurdles! + +``` +(.module: + [library + [lux #* + [data + ["." maybe]]]]) + +## Macro for easy concatenation of monadic operations. +(do maybe.monad + [x (f0 123) + #let [y (f1 x)] ## #let enables you to use full-featured let-expressions within do + z (f2 y)] + (wrap (f3 z))) +``` + +The `do` macro allows us to write monadic code with great ease (it's almost as if we're just making `let` bindings). + +Just tell it which `Monad` implementation you want, and it will write all the steps in your computation piece by piece using `map` and `join` without you having to waste your time with all the boilerplate. + +Finally, whatever you write as the body of the `do`, it must result in a functorial/monadic value (in this case, a `Maybe` value). + +**Remember**: `join` may collapse/merge/combine layers of the functor, but it never escapes it, and _neither can you_ (generally-speaking). + +--- + +`Functor`s and `Monad`s have a bad reputation for being difficult to understand, but hopefully I didn't botch this explanation _too much_. + +Personally, I think the best way to understand functors and monads is to read different implementations of them for various types (and maybe write a few of your own). + + For that, feel free to peruse the Lux Standard Library at your leisure. + +This is the sort of think that you need to learn by intuition and kind of _get the feel for_. + +Hopefully, you'll be able to get a feel for them in the next chapters, because we're going to be exploring a lot of monads from here on. + +So, buckle-up, cowboy. This ride is about to get bumpy. + +See you in the next chapter! + diff --git a/lux-jvm/source/luxc/lang/directive/jvm.lux b/lux-jvm/source/luxc/lang/directive/jvm.lux index fe3889c38..93a356c0e 100644 --- a/lux-jvm/source/luxc/lang/directive/jvm.lux +++ b/lux-jvm/source/luxc/lang/directive/jvm.lux @@ -446,7 +446,7 @@ (let [[mapping input] (..relabel [mapping input])] [mapping (list& input output)])) [mapping (list)] labels)] - [mapping (#/.TABLESWITCH min max default (list.reverse labels))]) + [mapping (#/.TABLESWITCH min max default (list.reversed labels))]) (#/.LOOKUPSWITCH default keys+labels) (let [[mapping default] (..relabel [mapping default]) @@ -454,7 +454,7 @@ (let [[mapping input] (..relabel [mapping input])] [mapping (list& [expected input] output)])) [mapping (list)] keys+labels)] - [mapping (#/.LOOKUPSWITCH default (list.reverse keys+labels))]) + [mapping (#/.LOOKUPSWITCH default (list.reversed keys+labels))]) )) (def: (relabel_exception [mapping instruction]) @@ -523,7 +523,7 @@ (def: fresh Mapping - (dictionary.new nat.hash)) + (dictionary.empty nat.hash)) (def: bytecode (-> (/.Bytecode Inst /.Label) jvm.Inst) @@ -575,10 +575,10 @@ directive.lift_generation) _ (directive.lift_generation (generation.log! (format "Generation " (%.text (:as Text name)))))] - (wrap directive.no_requirements)) + (in directive.no_requirements)) _ - (phase.throw extension.invalid_syntax [extension_name %.code inputsC+])))) + (phase.except extension.invalid_syntax [extension_name %.code inputsC+])))) (def: #export (custom [parser handler]) (All [i] @@ -591,7 +591,7 @@ (handler extension_name phase archive input') (#try.Failure error) - (phase.throw extension.invalid_syntax [extension_name %.code input])))) + (phase.except extension.invalid_syntax [extension_name %.code input])))) (type: Declaration [External (List (Type Var))]) @@ -678,7 +678,7 @@ state ..state _ (<code>.tuple (<>.some ..annotation)) type ..value] - (wrap [name privacy state (list) type])))) + (in [name privacy state (list) type])))) (type: Argument [Text (Type Value)]) @@ -1021,7 +1021,7 @@ [typeL (//A.reflection_type mapping typeJ) termA (typeA.with_type typeL (analyse archive termC))] - (wrap [typeJ termA]))) + (in [typeJ termA]))) constructor_argumentsC) selfT (//A.reflection_type mapping (/type.class class_name class_tvars)) arguments' (monad.map ! @@ -1031,14 +1031,14 @@ arguments) returnT (//A.boxed_reflection_return mapping /type.void) [_scope bodyA] (|> arguments' - (#.Cons [self selfT]) - list.reverse + (#.Item [self selfT]) + list.reversed (list\fold scopeA.with_local (analyse archive bodyC)) (typeA.with_type returnT) analysis.with_scope)] - (wrap [privacy strict_floating_point? annotations method_tvars exceptions - self arguments constructor_argumentsA - bodyA]))))) + (in [privacy strict_floating_point? annotations method_tvars exceptions + self arguments constructor_argumentsA + bodyA]))))) (def: (override_method_analysis archive [class_name class_tvars] supers method) (-> Archive Declaration (List (Type Class)) (Override Code) (Operation (Override Analysis))) @@ -1061,14 +1061,14 @@ arguments) returnT (//A.boxed_reflection_return mapping returnJ) [_scope bodyA] (|> arguments' - (#.Cons [self selfT]) - list.reverse + (#.Item [self selfT]) + list.reversed (list\fold scopeA.with_local (analyse archive bodyC)) (typeA.with_type returnT) analysis.with_scope)] - (wrap [[super_name super_tvars] method_name strict_floating_point? annotations - method_tvars self arguments returnJ exceptionsJ - bodyA]))))) + (in [[super_name super_tvars] method_name strict_floating_point? annotations + method_tvars self arguments returnJ exceptionsJ + bodyA]))))) (def: (virtual_method_analysis archive [class_name class_tvars] method) (-> Archive Declaration (Virtual Code) (Operation (Virtual Analysis))) @@ -1089,14 +1089,14 @@ arguments) returnT (//A.boxed_reflection_return mapping returnJ) [_scope bodyA] (|> arguments' - (#.Cons [self selfT]) - list.reverse + (#.Item [self selfT]) + list.reversed (list\fold scopeA.with_local (analyse archive bodyC)) (typeA.with_type returnT) analysis.with_scope)] - (wrap [name privacy final? strict_floating_point? annotations method_tvars - self arguments returnJ exceptionsJ - bodyA]))))) + (in [name privacy final? strict_floating_point? annotations method_tvars + self arguments returnJ exceptionsJ + bodyA]))))) (def: (static_method_analysis archive method) (-> Archive (Static Code) (Operation (Static Analysis))) @@ -1115,13 +1115,13 @@ arguments) returnT (//A.boxed_reflection_return mapping returnJ) [_scope bodyA] (|> arguments' - list.reverse + list.reversed (list\fold scopeA.with_local (analyse archive bodyC)) (typeA.with_type returnT) analysis.with_scope)] - (wrap [name privacy strict_floating_point? annotations method_tvars - arguments returnJ exceptionsJ - bodyA]))))) + (in [name privacy strict_floating_point? annotations method_tvars + arguments returnJ exceptionsJ + bodyA]))))) (def: (method_analysis archive declaration supers method) (-> Archive Declaration (List (Type Class)) (Method Code) (Operation (Method Analysis))) @@ -1143,7 +1143,7 @@ (static_method_analysis archive method)) (#Abstract method) - (\ phase.monad wrap (#Abstract method)) + (\ phase.monad in (#Abstract method)) )) (template: (method_body <bodyS>) @@ -1167,14 +1167,14 @@ (synthesise archive termA))) constructor_argumentsA) bodyS (synthesise archive (#analysis.Function (list) (//A.hide_method_body (list.size arguments) bodyA)))] - (wrap [privacy strict_floating_point? annotations method_tvars exceptions - self arguments constructor_argumentsS - (case bodyS - (^ (method_body bodyS)) - bodyS + (in [privacy strict_floating_point? annotations method_tvars exceptions + self arguments constructor_argumentsS + (case bodyS + (^ (method_body bodyS)) + bodyS - _ - bodyS)]))))) + _ + bodyS)]))))) (def: (override_method_synthesis archive method) (-> Archive (Override Analysis) (Operation (Override Synthesis))) @@ -1186,14 +1186,14 @@ (directive.lift_synthesis (do ! [bodyS (synthesise archive (#analysis.Function (list) (//A.hide_method_body (list.size arguments) bodyA)))] - (wrap [[super_name super_tvars] method_name strict_floating_point? annotations - method_tvars self arguments returnJ exceptionsJ - (case bodyS - (^ (method_body bodyS)) - bodyS + (in [[super_name super_tvars] method_name strict_floating_point? annotations + method_tvars self arguments returnJ exceptionsJ + (case bodyS + (^ (method_body bodyS)) + bodyS - _ - bodyS)]))))) + _ + bodyS)]))))) (def: (virtual_method_synthesis archive method) (-> Archive (Virtual Analysis) (Operation (Virtual Synthesis))) @@ -1205,14 +1205,14 @@ (directive.lift_synthesis (do ! [bodyS (synthesise archive (#analysis.Function (list) (//A.hide_method_body (list.size arguments) bodyA)))] - (wrap [name privacy final? strict_floating_point? annotations method_tvars - self arguments returnJ exceptionsJ - (case bodyS - (^ (method_body bodyS)) - bodyS + (in [name privacy final? strict_floating_point? annotations method_tvars + self arguments returnJ exceptionsJ + (case bodyS + (^ (method_body bodyS)) + bodyS - _ - bodyS)]))))) + _ + bodyS)]))))) (def: (static_method_synthesis archive method) (-> Archive (Static Analysis) (Operation (Static Synthesis))) @@ -1224,14 +1224,14 @@ (directive.lift_synthesis (do ! [bodyS (synthesise archive (#analysis.Function (list) (//A.hide_method_body (list.size arguments) bodyA)))] - (wrap [name privacy strict_floating_point? annotations method_tvars - arguments returnJ exceptionsJ - (case bodyS - (^ (method_body bodyS)) - bodyS + (in [name privacy strict_floating_point? annotations method_tvars + arguments returnJ exceptionsJ + (case bodyS + (^ (method_body bodyS)) + bodyS - _ - bodyS)]))))) + _ + bodyS)]))))) (def: (method_synthesis archive method) (-> Archive (Method Analysis) (Operation (Method Synthesis))) @@ -1253,7 +1253,7 @@ (static_method_synthesis archive method)) (#Abstract method) - (\ phase.monad wrap (#Abstract method)) + (\ phase.monad in (#Abstract method)) )) (def: (constructor_method_generation archive super_class method) @@ -1279,16 +1279,16 @@ (|>> (_.ALOAD 0) super_constructor_argument_values (_.INVOKESPECIAL super_class ..constructor_name super_constructorT)))]] - (wrap (def.method (..visibility privacy) - (if strict_floating_point? - jvm.strictM - jvm.noneM) - ..constructor_name - (/type.method [method_tvars argumentsT /type.void exceptions]) - (|>> initialize_object! - (//G.prepare_arguments 1 argumentsT) - bodyG - _.RETURN))))))) + (in (def.method (..visibility privacy) + (if strict_floating_point? + jvm.strictM + jvm.noneM) + ..constructor_name + (/type.method [method_tvars argumentsT /type.void exceptions]) + (|>> initialize_object! + (//G.prepare_arguments 1 argumentsT) + bodyG + _.RETURN))))))) (def: (override_method_generation archive method) (-> Archive (Override Synthesis) (Operation jvm.Def)) @@ -1301,15 +1301,15 @@ (do ! [bodyG (generate archive (//G.hidden_method_body (list.size arguments) bodyS)) #let [argumentsT (list\map product.right arguments)]] - (wrap (def.method #jvm.Public - (if strict_floating_point? - jvm.strictM - jvm.noneM) - method_name - (/type.method [method_tvars argumentsT returnJ exceptionsJ]) - (|>> (//G.prepare_arguments 1 argumentsT) - bodyG - (//G.returnI returnJ)))))))) + (in (def.method #jvm.Public + (if strict_floating_point? + jvm.strictM + jvm.noneM) + method_name + (/type.method [method_tvars argumentsT returnJ exceptionsJ]) + (|>> (//G.prepare_arguments 1 argumentsT) + bodyG + (//G.returnI returnJ)))))))) (def: (virtual_method_generation archive method) (-> Archive (Virtual Synthesis) (Operation jvm.Def)) @@ -1322,19 +1322,19 @@ (do ! [bodyG (generate archive (//G.hidden_method_body (list.size arguments) bodyS)) #let [argumentsT (list\map product.right arguments)]] - (wrap (def.method (..visibility privacy) - (|> jvm.noneM - (jvm.++M (if strict_floating_point? - jvm.strictM - jvm.noneM)) - (jvm.++M (if final? - jvm.finalM - jvm.noneM))) - method_name - (/type.method [method_tvars argumentsT returnJ exceptionsJ]) - (|>> (//G.prepare_arguments 1 argumentsT) - bodyG - (//G.returnI returnJ)))))))) + (in (def.method (..visibility privacy) + (|> jvm.noneM + (jvm.++M (if strict_floating_point? + jvm.strictM + jvm.noneM)) + (jvm.++M (if final? + jvm.finalM + jvm.noneM))) + method_name + (/type.method [method_tvars argumentsT returnJ exceptionsJ]) + (|>> (//G.prepare_arguments 1 argumentsT) + bodyG + (//G.returnI returnJ)))))))) (def: (static_method_generation archive method) (-> Archive (Static Synthesis) (Operation jvm.Def)) @@ -1347,16 +1347,16 @@ (do ! [bodyG (generate archive (//G.hidden_method_body (list.size arguments) bodyS)) #let [argumentsT (list\map product.right arguments)]] - (wrap (def.method (..visibility privacy) - (|> jvm.staticM - (jvm.++M (if strict_floating_point? - jvm.strictM - jvm.noneM))) - method_name - (/type.method [method_tvars argumentsT returnJ exceptionsJ]) - (|>> (//G.prepare_arguments 0 argumentsT) - bodyG - (//G.returnI returnJ)))))))) + (in (def.method (..visibility privacy) + (|> jvm.staticM + (jvm.++M (if strict_floating_point? + jvm.strictM + jvm.noneM))) + method_name + (/type.method [method_tvars argumentsT returnJ exceptionsJ]) + (|>> (//G.prepare_arguments 0 argumentsT) + bodyG + (//G.returnI returnJ)))))))) (def: (method_generation archive super_class method) (-> Archive (Type Class) (Method Synthesis) (Operation jvm.Def)) @@ -1374,7 +1374,7 @@ (..static_method_generation archive method) (#Abstract method) - (\ phase.monad wrap (..abstract_method_generation method)) + (\ phase.monad in (..abstract_method_generation method)) )) (import: java/lang/ClassLoader) @@ -1445,7 +1445,7 @@ _ (generation.execute! directive) _ (generation.save! artifact_id (#.Some class_name) directive) _ (generation.log! (format "JVM Class " (%.text class_name)))] - (wrap directive.no_requirements)))))])) + (in directive.no_requirements)))))])) (def: jvm::class::interface ..Handler @@ -1472,7 +1472,7 @@ _ (generation.execute! directive) _ (generation.save! artifact_id (#.Some class_name) directive) _ (generation.log! (format "JVM Interface " (%.text class_name)))] - (wrap directive.no_requirements)))))])) + (in directive.no_requirements)))))])) (def: #export (bundle class_loader extender) (-> java/lang/ClassLoader jvm.Extender (directive.Bundle jvm.Anchor jvm.Inst jvm.Definition)) diff --git a/lux-jvm/source/luxc/lang/host/jvm.lux b/lux-jvm/source/luxc/lang/host/jvm.lux index 1c81be667..5c854d646 100644 --- a/lux-jvm/source/luxc/lang/host/jvm.lux +++ b/lux-jvm/source/luxc/lang/host/jvm.lux @@ -103,25 +103,25 @@ (|> (~ g!none) (set@ (~ (code.local_tag option)) #1))))) options)] - (wrap (list& (` (type: (~' #export) (~ g!type) - (~ (code.record (list/map (function (_ tag) - [tag (` .Bit)]) - g!tags+))))) - - (` (def: (~' #export) (~ g!none) - (~ g!type) - (~ (code.record (list/map (function (_ tag) - [tag (` #0)]) - g!tags+))))) - - (` (def: (~' #export) ((~ (code.local_identifier ++)) (~ g!_left) (~ g!_right)) - (-> (~ g!type) (~ g!type) (~ g!type)) - (~ (code.record (list/map (function (_ tag) - [tag (` (or (get@ (~ tag) (~ g!_left)) - (get@ (~ tag) (~ g!_right))))]) - g!tags+))))) - - g!options+)))) + (in (list& (` (type: (~' #export) (~ g!type) + (~ (code.record (list/map (function (_ tag) + [tag (` .Bit)]) + g!tags+))))) + + (` (def: (~' #export) (~ g!none) + (~ g!type) + (~ (code.record (list/map (function (_ tag) + [tag (` #0)]) + g!tags+))))) + + (` (def: (~' #export) ((~ (code.local_identifier ++)) (~ g!_left) (~ g!_right)) + (-> (~ g!type) (~ g!type) (~ g!type)) + (~ (code.record (list/map (function (_ tag) + [tag (` (or (get@ (~ tag) (~ g!_left)) + (get@ (~ tag) (~ g!_right))))]) + g!tags+))))) + + g!options+)))) (config: Class_Config noneC ++C [finalC]) (config: Method_Config noneM ++M [finalM staticM synchronizedM strictM]) diff --git a/lux-jvm/source/luxc/lang/host/jvm/def.lux b/lux-jvm/source/luxc/lang/host/jvm/def.lux index 953dbf200..e1e60179f 100644 --- a/lux-jvm/source/luxc/lang/host/jvm/def.lux +++ b/lux-jvm/source/luxc/lang/host/jvm/def.lux @@ -293,11 +293,11 @@ (def: #export (fuse defs) (-> (List //.Def) //.Def) (case defs - #.Nil + #.End function.identity - (#.Cons singleton #.Nil) + (#.Item singleton #.End) singleton - (#.Cons head tail) + (#.Item head tail) (function.compose (fuse tail) head))) diff --git a/lux-jvm/source/luxc/lang/host/jvm/inst.lux b/lux-jvm/source/luxc/lang/host/jvm/inst.lux index e86504d60..ea68f2680 100644 --- a/lux-jvm/source/luxc/lang/host/jvm/inst.lux +++ b/lux-jvm/source/luxc/lang/host/jvm/inst.lux @@ -47,7 +47,7 @@ (syntax: (declare {codes (p.many s.local_identifier)}) (|> codes (list@map (function (_ code) (` ((~' #static) (~ (code.local_identifier code)) (~' int))))) - wrap)) + in)) (`` (import: org/objectweb/asm/Opcodes ["#::." @@ -375,7 +375,7 @@ labels_array (ffi.array org/objectweb/asm/Label array_size) _ (loop [idx 0] (if (n.< array_size idx) - (let [[key label] (maybe.assume (list.nth idx keys+labels))] + (let [[key label] (maybe.assume (list.item idx keys+labels))] (exec (ffi.array_write idx (ffi.long_to_int key) keys_array) (ffi.array_write idx label labels_array) @@ -392,7 +392,7 @@ _ (loop [idx 0] (if (n.< num_labels idx) (exec (ffi.array_write idx - (maybe.assume (list.nth idx labels)) + (maybe.assume (list.item idx labels)) labels_array) (recur (inc idx))) []))] @@ -459,11 +459,11 @@ (def: #export (fuse insts) (-> (List Inst) Inst) (case insts - #.Nil + #.End function.identity - (#.Cons singleton #.Nil) + (#.Item singleton #.End) singleton - (#.Cons head tail) + (#.Item head tail) (function.compose (fuse tail) head))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm.lux b/lux-jvm/source/luxc/lang/translation/jvm.lux index 1b916d925..4cf712a45 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm.lux @@ -88,13 +88,13 @@ (#try.Success value) #.None - (exception.throw ..invalid_value class_name)) + (exception.except ..invalid_value class_name)) (#try.Failure error) - (exception.throw ..cannot_load [class_name error])) + (exception.except ..cannot_load [class_name error])) (#try.Failure error) - (exception.throw ..invalid_field [class_name ..value_field error]))) + (exception.except ..invalid_field [class_name ..value_field error]))) (def: class_path_separator ".") @@ -129,9 +129,9 @@ (io.run (do (try.with io.monad) [_ (loader.store eval_class bytecode library) class (loader.load eval_class loader) - value (\ io.monad wrap (..class_value eval_class class))] - (wrap [value - [eval_class bytecode]]))))) + value (\ io.monad in (..class_value eval_class class))] + (in [value + [eval_class bytecode]]))))) (def: (execute! library loader [class_name class_bytecode]) (-> Library java/lang/ClassLoader Definition (Try Any)) @@ -142,7 +142,7 @@ (try.lifted io.monad) (: (IO (Try Bit)))) _ (if existing_class? - (wrap []) + (in []) (loader.store class_name class_bytecode library))] (loader.load class_name loader)))) @@ -150,9 +150,9 @@ (-> Library java/lang/ClassLoader generation.Context (Maybe Text) Inst (Try [Text Any Definition])) (do try.monad [[value definition] (evaluate! library loader context valueI)] - (wrap [(maybe.default (..class_name context) - custom) - value definition]))) + (in [(maybe.else (..class_name context) + custom) + value definition]))) (def: #export host (IO [java/lang/ClassLoader Host]) @@ -176,16 +176,16 @@ (def: (re_learn context custom [_ bytecode]) (io.run - (loader.store (maybe.default (..class_name context) custom) bytecode library))) + (loader.store (maybe.else (..class_name context) custom) bytecode library))) (def: (re_load context custom [directive_name bytecode]) (io.run (do (try.with io.monad) - [#let [class_name (maybe.default (..class_name context) - custom)] + [#let [class_name (maybe.else (..class_name context) + custom)] _ (loader.store class_name bytecode library) class (loader.load class_name loader)] - (\ io.monad wrap (..class_value class_name class)))))))]))) + (\ io.monad in (..class_value class_name class)))))))]))) (def: #export $Variant (type.array ..$Value)) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/case.lux b/lux-jvm/source/luxc/lang/translation/jvm/case.lux index b7b1d6b0f..2c9bfdb61 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/case.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/case.lux @@ -71,6 +71,9 @@ 5 _.ICONST_5 _ (_.int (.int value)))) +(def: projectionJT + (type.method [(list) (list //.$Tuple runtime.$Index) //.$Value (list)])) + (def: (left_projection lefts) (-> Nat Inst) (.let [[indexI accessI] (.case lefts @@ -80,7 +83,7 @@ lefts [(leftsI lefts) - (_.INVOKESTATIC //.$Runtime "tuple_left" (type.method [(list) (list //.$Tuple runtime.$Index) //.$Value (list)]))])] + (_.INVOKESTATIC //.$Runtime "tuple_left" ..projectionJT)])] (|>> (_.CHECKCAST //.$Tuple) indexI accessI))) @@ -89,17 +92,23 @@ (-> Nat Inst) (|>> (_.CHECKCAST //.$Tuple) (leftsI lefts) - (_.INVOKESTATIC //.$Runtime "tuple_right" (type.method [(list) (list //.$Tuple runtime.$Index) //.$Value (list)])))) + (_.INVOKESTATIC //.$Runtime "tuple_right" ..projectionJT))) + +(def: equalsJT + (type.method [(list) (list //.$Value) type.boolean (list)])) + +(def: sideJT + (type.method [(list) (list //.$Variant runtime.$Tag runtime.$Flag) runtime.$Value (list)])) (def: (path' stack_depth @else @end phase archive path) (-> Nat Label Label Phase Archive Path (Operation Inst)) (.case path #synthesis.Pop - (operation@wrap ..popI) + (operation@in ..popI) (#synthesis.Bind register) - (operation@wrap (|>> peekI - (_.ASTORE register))) + (operation@in (|>> peekI + (_.ASTORE register))) (#synthesis.Bit_Fork when thenP elseP) (do phase.monad @@ -109,15 +118,15 @@ (path' stack_depth @else @end phase archive elseP) #.None - (wrap (_.GOTO @else))) + (in (_.GOTO @else))) #let [ifI (.if when _.IFEQ _.IFNE)]] - (wrap (<| _.with_label (function (_ @else)) - (|>> peekI - (_.unwrap type.boolean) - (ifI @else) - thenG - (_.label @else) - elseG)))) + (in (<| _.with_label (function (_ @else)) + (|>> peekI + (_.unwrap type.boolean) + (ifI @else) + thenG + (_.label @else) + elseG)))) (^template [<tag> <unwrap> <dup> <pop> <test> <comparison> <if>] [(<tag> cons) @@ -126,70 +135,70 @@ (monad.fold @ (function (_ [test thenP] elseG) (do @ [thenG (path' stack_depth @else @end phase archive thenP)] - (wrap (<| _.with_label (function (_ @else)) - (|>> <dup> - (<test> test) - <comparison> - (<if> @else) - <pop> - thenG - (_.label @else) - elseG))))) + (in (<| _.with_label (function (_ @else)) + (|>> <dup> + (<test> test) + <comparison> + (<if> @else) + <pop> + thenG + (_.label @else) + elseG))))) (|>> <pop> (_.GOTO @else)) - (#.Cons cons)))] - (wrap (|>> peekI - <unwrap> - forkG)))]) + (#.Item cons)))] + (in (|>> peekI + <unwrap> + forkG)))]) ([#synthesis.I64_Fork (_.unwrap type.long) _.DUP2 _.POP2 (|>> .int _.long) _.LCMP _.IFNE] [#synthesis.F64_Fork (_.unwrap type.double) _.DUP2 _.POP2 _.double _.DCMPL _.IFNE] [#synthesis.Text_Fork (|>) _.DUP _.POP _.string - (_.INVOKEVIRTUAL (type.class "java.lang.Object" (list)) "equals" (type.method [(list) (list //.$Value) type.boolean (list)])) + (_.INVOKEVIRTUAL (type.class "java.lang.Object" (list)) "equals" ..equalsJT) _.IFEQ]) (#synthesis.Then bodyS) (do phase.monad [bodyI (phase archive bodyS)] - (wrap (|>> (pop_altI stack_depth) - bodyI - (_.GOTO @end)))) + (in (|>> (pop_altI stack_depth) + bodyI + (_.GOTO @end)))) (^template [<pattern> <right?>] [(^ (<pattern> lefts)) - (operation@wrap (<| _.with_label (function (_ @success)) - _.with_label (function (_ @fail)) - (|>> peekI - (_.CHECKCAST //.$Variant) - (structure.tagI lefts <right?>) - (structure.flagI <right?>) - (_.INVOKESTATIC //.$Runtime "pm_variant" (type.method [(list) (list //.$Variant runtime.$Tag runtime.$Flag) runtime.$Value (list)])) - _.DUP - (_.IFNULL @fail) - (_.GOTO @success) - (_.label @fail) - _.POP - (_.GOTO @else) - (_.label @success) - pushI)))]) + (operation@in (<| _.with_label (function (_ @success)) + _.with_label (function (_ @fail)) + (|>> peekI + (_.CHECKCAST //.$Variant) + (structure.tagI lefts <right?>) + (structure.flagI <right?>) + (_.INVOKESTATIC //.$Runtime "pm_variant" ..sideJT) + _.DUP + (_.IFNULL @fail) + (_.GOTO @success) + (_.label @fail) + _.POP + (_.GOTO @else) + (_.label @success) + pushI)))]) ([synthesis.side/left false] [synthesis.side/right true]) ## Extra optimization (^template [<path> <projection>] [(^ (<path> lefts)) - (operation@wrap (|>> peekI - (<projection> lefts) - pushI)) + (operation@in (|>> peekI + (<projection> lefts) + pushI)) (^ (synthesis.path/seq (<path> lefts) (synthesis.!bind_top register thenP))) (do phase.monad [then! (path' stack_depth @else @end phase archive thenP)] - (wrap (|>> peekI - (<projection> lefts) - (_.ASTORE register) - then!)))]) + (in (|>> peekI + (<projection> lefts) + (_.ASTORE register) + then!)))]) ([synthesis.member/left ..left_projection] [synthesis.member/right ..right_projection]) @@ -197,32 +206,35 @@ (do phase.monad [leftI (path' stack_depth @else @end phase archive leftP) rightI (path' stack_depth @else @end phase archive rightP)] - (wrap (|>> leftI - rightI))) + (in (|>> leftI + rightI))) (#synthesis.Alt leftP rightP) (do phase.monad [@alt_else _.make_label leftI (path' (inc stack_depth) @alt_else @end phase archive leftP) rightI (path' stack_depth @else @end phase archive rightP)] - (wrap (|>> _.DUP - leftI - (_.label @alt_else) - _.POP - rightI))) + (in (|>> _.DUP + leftI + (_.label @alt_else) + _.POP + rightI))) )) +(def: failJT + (type.method [(list) (list) type.void (list)])) + (def: (path @end phase archive path) (-> Label Phase Archive Path (Operation Inst)) (do phase.monad [@else _.make_label pathI (..path' 1 @else @end phase archive path)] - (wrap (|>> pathI - (_.label @else) - _.POP - (_.INVOKESTATIC //.$Runtime "pm_fail" (type.method [(list) (list) type.void (list)])) - _.NULL - (_.GOTO @end))))) + (in (|>> pathI + (_.label @else) + _.POP + (_.INVOKESTATIC //.$Runtime "pm_fail" ..failJT) + _.NULL + (_.GOTO @end))))) (def: #export (if phase archive [testS thenS elseS]) (Generator [Synthesis Synthesis Synthesis]) @@ -230,40 +242,40 @@ [testI (phase archive testS) thenI (phase archive thenS) elseI (phase archive elseS)] - (wrap (<| _.with_label (function (_ @else)) - _.with_label (function (_ @end)) - (|>> testI - (_.unwrap type.boolean) - (_.IFEQ @else) - thenI - (_.GOTO @end) - (_.label @else) - elseI - (_.label @end)))))) + (in (<| _.with_label (function (_ @else)) + _.with_label (function (_ @end)) + (|>> testI + (_.unwrap type.boolean) + (_.IFEQ @else) + thenI + (_.GOTO @end) + (_.label @else) + elseI + (_.label @end)))))) (def: #export (let phase archive [inputS register exprS]) (Generator [Synthesis Nat Synthesis]) (do phase.monad [inputI (phase archive inputS) exprI (phase archive exprS)] - (wrap (|>> inputI - (_.ASTORE register) - exprI)))) + (in (|>> inputI + (_.ASTORE register) + exprI)))) (def: #export (get phase archive [path recordS]) (Generator [(List synthesis.Member) Synthesis]) (do phase.monad [recordG (phase archive recordS)] - (wrap (list@fold (function (_ step so_far) - (.let [next (.case step - (#.Left lefts) - (..left_projection lefts) - - (#.Right lefts) - (..right_projection lefts))] - (|>> so_far next))) - recordG - (list.reverse path))))) + (in (list@fold (function (_ step so_far) + (.let [next (.case step + (#.Left lefts) + (..left_projection lefts) + + (#.Right lefts) + (..right_projection lefts))] + (|>> so_far next))) + recordG + (list.reversed path))))) (def: #export (case phase archive [valueS path]) (Generator [Synthesis Path]) @@ -271,8 +283,8 @@ [@end _.make_label valueI (phase archive valueS) pathI (..path @end phase archive path)] - (wrap (|>> _.NULL - valueI - pushI - pathI - (_.label @end))))) + (in (|>> _.NULL + valueI + pushI + pathI + (_.label @end))))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/extension.lux b/lux-jvm/source/luxc/lang/translation/jvm/extension.lux index 2f1bd6a36..8fced4749 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/extension.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/extension.lux @@ -13,5 +13,5 @@ (def: #export bundle Bundle - (dictionary.merge /common.bundle - /host.bundle)) + (dictionary.merged /common.bundle + /host.bundle)) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux b/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux index 70175b636..eb3d02be7 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux @@ -52,7 +52,7 @@ (handler extension_name phase archive input') (#try.Failure error) - (phase.throw extension.invalid_syntax [extension_name %synthesis input])))) + (phase.except extension.invalid_syntax [extension_name %synthesis input])))) (import: java/lang/Double ["#::." @@ -103,13 +103,13 @@ (monad.map @ (function (_ [chars branch]) (do @ [branchG (phase archive branch)] - (wrap (<| _.with_label (function (_ @branch)) - [(list@map (function (_ char) - [(.int char) @branch]) - chars) - (|>> (_.label @branch) - branchG - (_.GOTO @end))])))) + (in (<| _.with_label (function (_ @branch)) + [(list@map (function (_ char) + [(.int char) @branch]) + chars) + (|>> (_.label @branch) + branchG + (_.GOTO @end))])))) conditionals)) #let [table (|> conditionalsG+ (list@map product.left) @@ -117,13 +117,12 @@ conditionalsG (|> conditionalsG+ (list@map product.right) _.fuse)]] - (wrap (|>> inputG (_.unwrap type.long) _.L2I - (_.LOOKUPSWITCH @else table) - conditionalsG - (_.label @else) - elseG - (_.label @end) - )))))])) + (in (|>> inputG (_.unwrap type.long) _.L2I + (_.LOOKUPSWITCH @else table) + conditionalsG + (_.label @else) + elseG + (_.label @end))))))])) (def: (lux::is [referenceI sampleI]) (Binary Inst) @@ -372,7 +371,7 @@ Bundle (<| (bundle.prefix "lux") (|> bundle::lux - (dictionary.merge bundle::i64) - (dictionary.merge bundle::f64) - (dictionary.merge bundle::text) - (dictionary.merge bundle::io)))) + (dictionary.merged bundle::i64) + (dictionary.merged bundle::f64) + (dictionary.merged bundle::text) + (dictionary.merged bundle::io)))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux index 4f8210a47..e87ea6510 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux @@ -70,7 +70,7 @@ (template [<name> <category> <parser>] [(def: #export <name> (Parser (Type <category>)) - (<text>.embed <parser> <synthesis>.text))] + (<text>.then <parser> <synthesis>.text))] [var Var parser.var] [class Class parser.class] @@ -94,15 +94,15 @@ (def: #export object_array (Parser (Type Object)) (do <>.monad - [arrayJT (<text>.embed parser.array <synthesis>.text)] + [arrayJT (<text>.then parser.array <synthesis>.text)] (case (parser.array? arrayJT) (#.Some elementJT) (case (parser.object? elementJT) (#.Some elementJT) - (wrap elementJT) + (in elementJT) #.None - (<>.failure (exception.construct ..not_an_object_array arrayJT))) + (<>.failure (exception.error ..not_an_object_array [arrayJT]))) #.None (undefined)))) @@ -110,11 +110,11 @@ (template [<name> <inst>] [(def: <name> Inst - <inst>)] + (|>> _.L2I <inst>))] - [L2S (|>> _.L2I _.I2S)] - [L2B (|>> _.L2I _.I2B)] - [L2C (|>> _.L2I _.I2C)] + [L2S _.I2S] + [L2B _.I2B] + [L2C _.I2C] ) (template [<conversion> <name>] @@ -355,9 +355,9 @@ (function (_ extension_name generate archive arrayS) (do phase.monad [arrayI (generate archive arrayS)] - (wrap (|>> arrayI - (_.CHECKCAST (type.array jvm_primitive)) - _.ARRAYLENGTH))))])) + (in (|>> arrayI + (_.CHECKCAST (type.array jvm_primitive)) + _.ARRAYLENGTH))))])) (def: array::length::object Handler @@ -366,9 +366,9 @@ (function (_ extension_name generate archive [elementJT arrayS]) (do phase.monad [arrayI (generate archive arrayS)] - (wrap (|>> arrayI - (_.CHECKCAST (type.array elementJT)) - _.ARRAYLENGTH))))])) + (in (|>> arrayI + (_.CHECKCAST (type.array elementJT)) + _.ARRAYLENGTH))))])) (def: (new_primitive_array_handler jvm_primitive) (-> (Type Primitive) Handler) @@ -377,11 +377,11 @@ (^ (list lengthS)) (do phase.monad [lengthI (generate archive lengthS)] - (wrap (|>> lengthI - (_.array jvm_primitive)))) + (in (|>> lengthI + (_.array jvm_primitive)))) _ - (phase.throw extension.invalid_syntax [extension_name %synthesis inputs])))) + (phase.except extension.invalid_syntax [extension_name %synthesis inputs])))) (def: array::new::object Handler @@ -390,8 +390,8 @@ (function (_ extension_name generate archive [objectJT lengthS]) (do phase.monad [lengthI (generate archive lengthS)] - (wrap (|>> lengthI - (_.ANEWARRAY objectJT)))))])) + (in (|>> lengthI + (_.ANEWARRAY objectJT)))))])) (def: (read_primitive_array_handler jvm_primitive loadI) (-> (Type Primitive) Inst Handler) @@ -401,13 +401,13 @@ (do phase.monad [arrayI (generate archive arrayS) idxI (generate archive idxS)] - (wrap (|>> arrayI - (_.CHECKCAST (type.array jvm_primitive)) - idxI - loadI))) + (in (|>> arrayI + (_.CHECKCAST (type.array jvm_primitive)) + idxI + loadI))) _ - (phase.throw extension.invalid_syntax [extension_name %synthesis inputs])))) + (phase.except extension.invalid_syntax [extension_name %synthesis inputs])))) (def: array::read::object Handler @@ -417,10 +417,10 @@ (do phase.monad [arrayI (generate archive arrayS) idxI (generate archive idxS)] - (wrap (|>> arrayI - (_.CHECKCAST (type.array elementJT)) - idxI - _.AALOAD))))])) + (in (|>> arrayI + (_.CHECKCAST (type.array elementJT)) + idxI + _.AALOAD))))])) (def: (write_primitive_array_handler jvm_primitive storeI) (-> (Type Primitive) Inst Handler) @@ -431,15 +431,15 @@ [arrayI (generate archive arrayS) idxI (generate archive idxS) valueI (generate archive valueS)] - (wrap (|>> arrayI - (_.CHECKCAST (type.array jvm_primitive)) - _.DUP - idxI - valueI - storeI))) + (in (|>> arrayI + (_.CHECKCAST (type.array jvm_primitive)) + _.DUP + idxI + valueI + storeI))) _ - (phase.throw extension.invalid_syntax [extension_name %synthesis inputs])))) + (phase.except extension.invalid_syntax [extension_name %synthesis inputs])))) (def: array::write::object Handler @@ -450,61 +450,61 @@ [arrayI (generate archive arrayS) idxI (generate archive idxS) valueI (generate archive valueS)] - (wrap (|>> arrayI - (_.CHECKCAST (type.array elementJT)) - _.DUP - idxI - valueI - _.AASTORE))))])) + (in (|>> arrayI + (_.CHECKCAST (type.array elementJT)) + _.DUP + idxI + valueI + _.AASTORE))))])) (def: array_bundle Bundle (<| (bundle.prefix "array") (|> bundle.empty - (dictionary.merge (<| (bundle.prefix "length") - (|> bundle.empty - (bundle.install (reflection.reflection reflection.boolean) (primitive_array_length_handler type.boolean)) - (bundle.install (reflection.reflection reflection.byte) (primitive_array_length_handler type.byte)) - (bundle.install (reflection.reflection reflection.short) (primitive_array_length_handler type.short)) - (bundle.install (reflection.reflection reflection.int) (primitive_array_length_handler type.int)) - (bundle.install (reflection.reflection reflection.long) (primitive_array_length_handler type.long)) - (bundle.install (reflection.reflection reflection.float) (primitive_array_length_handler type.float)) - (bundle.install (reflection.reflection reflection.double) (primitive_array_length_handler type.double)) - (bundle.install (reflection.reflection reflection.char) (primitive_array_length_handler type.char)) - (bundle.install "object" array::length::object)))) - (dictionary.merge (<| (bundle.prefix "new") - (|> bundle.empty - (bundle.install (reflection.reflection reflection.boolean) (new_primitive_array_handler type.boolean)) - (bundle.install (reflection.reflection reflection.byte) (new_primitive_array_handler type.byte)) - (bundle.install (reflection.reflection reflection.short) (new_primitive_array_handler type.short)) - (bundle.install (reflection.reflection reflection.int) (new_primitive_array_handler type.int)) - (bundle.install (reflection.reflection reflection.long) (new_primitive_array_handler type.long)) - (bundle.install (reflection.reflection reflection.float) (new_primitive_array_handler type.float)) - (bundle.install (reflection.reflection reflection.double) (new_primitive_array_handler type.double)) - (bundle.install (reflection.reflection reflection.char) (new_primitive_array_handler type.char)) - (bundle.install "object" array::new::object)))) - (dictionary.merge (<| (bundle.prefix "read") - (|> bundle.empty - (bundle.install (reflection.reflection reflection.boolean) (read_primitive_array_handler type.boolean _.BALOAD)) - (bundle.install (reflection.reflection reflection.byte) (read_primitive_array_handler type.byte _.BALOAD)) - (bundle.install (reflection.reflection reflection.short) (read_primitive_array_handler type.short _.SALOAD)) - (bundle.install (reflection.reflection reflection.int) (read_primitive_array_handler type.int _.IALOAD)) - (bundle.install (reflection.reflection reflection.long) (read_primitive_array_handler type.long _.LALOAD)) - (bundle.install (reflection.reflection reflection.float) (read_primitive_array_handler type.float _.FALOAD)) - (bundle.install (reflection.reflection reflection.double) (read_primitive_array_handler type.double _.DALOAD)) - (bundle.install (reflection.reflection reflection.char) (read_primitive_array_handler type.char _.CALOAD)) - (bundle.install "object" array::read::object)))) - (dictionary.merge (<| (bundle.prefix "write") - (|> bundle.empty - (bundle.install (reflection.reflection reflection.boolean) (write_primitive_array_handler type.boolean _.BASTORE)) - (bundle.install (reflection.reflection reflection.byte) (write_primitive_array_handler type.byte _.BASTORE)) - (bundle.install (reflection.reflection reflection.short) (write_primitive_array_handler type.short _.SASTORE)) - (bundle.install (reflection.reflection reflection.int) (write_primitive_array_handler type.int _.IASTORE)) - (bundle.install (reflection.reflection reflection.long) (write_primitive_array_handler type.long _.LASTORE)) - (bundle.install (reflection.reflection reflection.float) (write_primitive_array_handler type.float _.FASTORE)) - (bundle.install (reflection.reflection reflection.double) (write_primitive_array_handler type.double _.DASTORE)) - (bundle.install (reflection.reflection reflection.char) (write_primitive_array_handler type.char _.CASTORE)) - (bundle.install "object" array::write::object)))) + (dictionary.merged (<| (bundle.prefix "length") + (|> bundle.empty + (bundle.install (reflection.reflection reflection.boolean) (primitive_array_length_handler type.boolean)) + (bundle.install (reflection.reflection reflection.byte) (primitive_array_length_handler type.byte)) + (bundle.install (reflection.reflection reflection.short) (primitive_array_length_handler type.short)) + (bundle.install (reflection.reflection reflection.int) (primitive_array_length_handler type.int)) + (bundle.install (reflection.reflection reflection.long) (primitive_array_length_handler type.long)) + (bundle.install (reflection.reflection reflection.float) (primitive_array_length_handler type.float)) + (bundle.install (reflection.reflection reflection.double) (primitive_array_length_handler type.double)) + (bundle.install (reflection.reflection reflection.char) (primitive_array_length_handler type.char)) + (bundle.install "object" array::length::object)))) + (dictionary.merged (<| (bundle.prefix "new") + (|> bundle.empty + (bundle.install (reflection.reflection reflection.boolean) (new_primitive_array_handler type.boolean)) + (bundle.install (reflection.reflection reflection.byte) (new_primitive_array_handler type.byte)) + (bundle.install (reflection.reflection reflection.short) (new_primitive_array_handler type.short)) + (bundle.install (reflection.reflection reflection.int) (new_primitive_array_handler type.int)) + (bundle.install (reflection.reflection reflection.long) (new_primitive_array_handler type.long)) + (bundle.install (reflection.reflection reflection.float) (new_primitive_array_handler type.float)) + (bundle.install (reflection.reflection reflection.double) (new_primitive_array_handler type.double)) + (bundle.install (reflection.reflection reflection.char) (new_primitive_array_handler type.char)) + (bundle.install "object" array::new::object)))) + (dictionary.merged (<| (bundle.prefix "read") + (|> bundle.empty + (bundle.install (reflection.reflection reflection.boolean) (read_primitive_array_handler type.boolean _.BALOAD)) + (bundle.install (reflection.reflection reflection.byte) (read_primitive_array_handler type.byte _.BALOAD)) + (bundle.install (reflection.reflection reflection.short) (read_primitive_array_handler type.short _.SALOAD)) + (bundle.install (reflection.reflection reflection.int) (read_primitive_array_handler type.int _.IALOAD)) + (bundle.install (reflection.reflection reflection.long) (read_primitive_array_handler type.long _.LALOAD)) + (bundle.install (reflection.reflection reflection.float) (read_primitive_array_handler type.float _.FALOAD)) + (bundle.install (reflection.reflection reflection.double) (read_primitive_array_handler type.double _.DALOAD)) + (bundle.install (reflection.reflection reflection.char) (read_primitive_array_handler type.char _.CALOAD)) + (bundle.install "object" array::read::object)))) + (dictionary.merged (<| (bundle.prefix "write") + (|> bundle.empty + (bundle.install (reflection.reflection reflection.boolean) (write_primitive_array_handler type.boolean _.BASTORE)) + (bundle.install (reflection.reflection reflection.byte) (write_primitive_array_handler type.byte _.BASTORE)) + (bundle.install (reflection.reflection reflection.short) (write_primitive_array_handler type.short _.SASTORE)) + (bundle.install (reflection.reflection reflection.int) (write_primitive_array_handler type.int _.IASTORE)) + (bundle.install (reflection.reflection reflection.long) (write_primitive_array_handler type.long _.LASTORE)) + (bundle.install (reflection.reflection reflection.float) (write_primitive_array_handler type.float _.FASTORE)) + (bundle.install (reflection.reflection reflection.double) (write_primitive_array_handler type.double _.DASTORE)) + (bundle.install (reflection.reflection reflection.char) (write_primitive_array_handler type.char _.CASTORE)) + (bundle.install "object" array::write::object)))) ))) (def: (object::null _) @@ -546,11 +546,11 @@ (^ (list (synthesis.text class))) (do phase.monad [] - (wrap (|>> (_.string class) - (_.INVOKESTATIC $Class "forName" (type.method [(list) (list (type.class "java.lang.String" (list))) $Class (list)]))))) + (in (|>> (_.string class) + (_.INVOKESTATIC $Class "forName" (type.method [(list) (list (type.class "java.lang.String" (list))) $Class (list)]))))) _ - (phase.throw extension.invalid_syntax [extension_name %synthesis inputs]))) + (phase.except extension.invalid_syntax [extension_name %synthesis inputs]))) (def: object::instance? Handler @@ -559,9 +559,9 @@ (function (_ extension_name generate archive [class objectS]) (do phase.monad [objectI (generate archive objectS)] - (wrap (|>> objectI - (_.INSTANCEOF (type.class class (list))) - (_.wrap type.boolean)))))])) + (in (|>> objectI + (_.INSTANCEOF (type.class class (list))) + (_.wrap type.boolean)))))])) (def: (object::cast extension_name generate archive inputs) Handler @@ -574,13 +574,13 @@ from) (text\= <object> to)) - (wrap (|>> valueI (_.wrap <primitive>))) + (in (|>> valueI (_.wrap <primitive>))) (and (text\= <object> from) (text\= (reflection.reflection (type.reflection <primitive>)) to)) - (wrap (|>> valueI (_.unwrap <primitive>)))] + (in (|>> valueI (_.unwrap <primitive>)))] [box.boolean type.boolean] [box.byte type.byte] @@ -591,10 +591,10 @@ [box.double type.double] [box.char type.char])) ## else - (wrap valueI)))) + (in valueI)))) _ - (phase.throw extension.invalid_syntax [extension_name %synthesis inputs]))) + (phase.except extension.invalid_syntax [extension_name %synthesis inputs]))) (def: object_bundle Bundle @@ -630,10 +630,10 @@ [] (case (dictionary.get unboxed ..primitives) (#.Some primitive) - (wrap (_.GETSTATIC (type.class class (list)) field primitive)) + (in (_.GETSTATIC (type.class class (list)) field primitive)) #.None - (wrap (_.GETSTATIC (type.class class (list)) field (type.class unboxed (list)))))))])) + (in (_.GETSTATIC (type.class class (list)) field (type.class unboxed (list)))))))])) (def: put::static Handler @@ -645,15 +645,15 @@ #let [$class (type.class class (list))]] (case (dictionary.get unboxed ..primitives) (#.Some primitive) - (wrap (|>> valueI - (_.PUTSTATIC $class field primitive) - (_.string synthesis.unit))) + (in (|>> valueI + (_.PUTSTATIC $class field primitive) + (_.string synthesis.unit))) #.None - (wrap (|>> valueI - (_.CHECKCAST $class) - (_.PUTSTATIC $class field $class) - (_.string synthesis.unit))))))])) + (in (|>> valueI + (_.CHECKCAST $class) + (_.PUTSTATIC $class field $class) + (_.string synthesis.unit))))))])) (def: get::virtual Handler @@ -669,9 +669,9 @@ #.None (_.GETFIELD $class field (type.class unboxed (list))))]] - (wrap (|>> objectI - (_.CHECKCAST $class) - getI))))])) + (in (|>> objectI + (_.CHECKCAST $class) + getI))))])) (def: put::virtual Handler @@ -690,11 +690,11 @@ (let [$unboxed (type.class unboxed (list))] (|>> (_.CHECKCAST $unboxed) (_.PUTFIELD $class field $unboxed))))]] - (wrap (|>> objectI - (_.CHECKCAST $class) - _.DUP - valueI - putI))))])) + (in (|>> objectI + (_.CHECKCAST $class) + _.DUP + valueI + putI))))])) (type: Input (Typed Synthesis)) @@ -710,11 +710,11 @@ [valueI (generate archive valueS)] (case (type.primitive? valueT) (#.Right valueT) - (wrap [valueT valueI]) + (in [valueT valueI]) (#.Left valueT) - (wrap [valueT (|>> valueI - (_.CHECKCAST valueT))])))) + (in [valueT (|>> valueI + (_.CHECKCAST valueT))])))) (def: voidI (_.string synthesis.unit)) @@ -735,9 +735,9 @@ (function (_ extension_name generate archive [class method outputT inputsTS]) (do {! phase.monad} [inputsTI (monad.map ! (generate_input generate archive) inputsTS)] - (wrap (|>> (_.fuse (list\map product.right inputsTI)) - (_.INVOKESTATIC class method (type.method [(list) (list\map product.left inputsTI) outputT (list)])) - (prepare_output outputT)))))])) + (in (|>> (_.fuse (list\map product.right inputsTI)) + (_.INVOKESTATIC class method (type.method [(list) (list\map product.left inputsTI) outputT (list)])) + (prepare_output outputT)))))])) (template [<name> <invoke>] [(def: <name> @@ -748,15 +748,15 @@ (do {! phase.monad} [objectI (generate archive objectS) inputsTI (monad.map ! (generate_input generate archive) inputsTS)] - (wrap (|>> objectI - (_.CHECKCAST class) - (_.fuse (list\map product.right inputsTI)) - (<invoke> class method - (type.method [(list) - (list\map product.left inputsTI) - outputT - (list)])) - (prepare_output outputT)))))]))] + (in (|>> objectI + (_.CHECKCAST class) + (_.fuse (list\map product.right inputsTI)) + (<invoke> class method + (type.method [(list) + (list\map product.left inputsTI) + outputT + (list)])) + (prepare_output outputT)))))]))] [invoke::virtual _.INVOKEVIRTUAL] [invoke::special _.INVOKESPECIAL] @@ -770,30 +770,30 @@ (function (_ extension_name generate archive [class inputsTS]) (do {! phase.monad} [inputsTI (monad.map ! (generate_input generate archive) inputsTS)] - (wrap (|>> (_.NEW class) - _.DUP - (_.fuse (list\map product.right inputsTI)) - (_.INVOKESPECIAL class "<init>" (type.method [(list) (list\map product.left inputsTI) type.void (list)]))))))])) + (in (|>> (_.NEW class) + _.DUP + (_.fuse (list\map product.right inputsTI)) + (_.INVOKESPECIAL class "<init>" (type.method [(list) (list\map product.left inputsTI) type.void (list)]))))))])) (def: member_bundle Bundle (<| (bundle.prefix "member") (|> (: Bundle bundle.empty) - (dictionary.merge (<| (bundle.prefix "get") - (|> (: Bundle bundle.empty) - (bundle.install "static" get::static) - (bundle.install "virtual" get::virtual)))) - (dictionary.merge (<| (bundle.prefix "put") - (|> (: Bundle bundle.empty) - (bundle.install "static" put::static) - (bundle.install "virtual" put::virtual)))) - (dictionary.merge (<| (bundle.prefix "invoke") - (|> (: Bundle bundle.empty) - (bundle.install "static" invoke::static) - (bundle.install "virtual" invoke::virtual) - (bundle.install "special" invoke::special) - (bundle.install "interface" invoke::interface) - (bundle.install "constructor" invoke::constructor)))) + (dictionary.merged (<| (bundle.prefix "get") + (|> (: Bundle bundle.empty) + (bundle.install "static" get::static) + (bundle.install "virtual" get::virtual)))) + (dictionary.merged (<| (bundle.prefix "put") + (|> (: Bundle bundle.empty) + (bundle.install "static" put::static) + (bundle.install "virtual" put::virtual)))) + (dictionary.merged (<| (bundle.prefix "invoke") + (|> (: Bundle bundle.empty) + (bundle.install "static" invoke::static) + (bundle.install "virtual" invoke::virtual) + (bundle.install "special" invoke::special) + (bundle.install "interface" invoke::interface) + (bundle.install "constructor" invoke::constructor)))) ))) (def: annotation_parameter @@ -858,11 +858,11 @@ <synthesis>.tuple (<>.after <synthesis>.any) <synthesis>.any)] - (wrap [environment - [ownerT name - strict_fp? annotations vars - self_name arguments returnT exceptionsT - (..hidden_method_body (list.size arguments) body)]])))) + (in [environment + [ownerT name + strict_fp? annotations vars + self_name arguments returnT exceptionsT + (..hidden_method_body (list.size arguments) body)]])))) (def: (normalize_path normalize) (-> (-> Synthesis Synthesis) @@ -918,7 +918,7 @@ (^ (synthesis.variable var)) (|> mapping (dictionary.get body) - (maybe.default var) + (maybe.else var) synthesis.variable) (^ (synthesis.branch/case [inputS pathS])) @@ -945,7 +945,7 @@ (^ (synthesis.variable var)) (|> mapping (dictionary.get captured) - (maybe.default var) + (maybe.else var) synthesis.variable) _ @@ -991,10 +991,10 @@ (-> Phase Archive (Type Class) (Environment Synthesis) (Operation Inst)) (do {! phase.monad} [captureI+ (monad.map ! (generate archive) env)] - (wrap (|>> (_.NEW class) - _.DUP - (_.fuse captureI+) - (_.INVOKESPECIAL class "<init>" (anonymous_init_method env)))))) + (in (|>> (_.NEW class) + _.DUP + (_.fuse captureI+) + (_.INVOKESPECIAL class "<init>" (anonymous_init_method env)))))) (def: (prepare_argument lux_register argumentT jvm_register) (-> Register (Type Value) Register [Register Inst]) @@ -1086,7 +1086,7 @@ inputsTS overriden_methods]) (do {! phase.monad} - [[context _] (generation.with_new_context archive (wrap [])) + [[context _] (generation.with_new_context archive (in [])) #let [[module_id artifact_id] context anonymous_class_name (///.class_name context) class (type.class anonymous_class_name (list)) @@ -1132,15 +1132,15 @@ [bodyG (generation.with_context artifact_id (generate archive bodyS)) #let [argumentsT (list\map product.right arguments)]] - (wrap (_def.method #$.Public - (if strict_fp? - ($_ $.++M $.finalM $.strictM) - $.finalM) - name - (type.method [varsT argumentsT returnT exceptionsT]) - (|>> (prepare_arguments 1 argumentsT) - bodyG - (returnI returnT))))))) + (in (_def.method #$.Public + (if strict_fp? + ($_ $.++M $.finalM $.strictM) + $.finalM) + name + (type.method [varsT argumentsT returnT exceptionsT]) + (|>> (prepare_arguments 1 argumentsT) + bodyG + (returnI returnT))))))) (\ ! map _def.fuse)) #let [directive [anonymous_class_name (_def.class #$.V1_6 #$.Public $.finalC @@ -1164,13 +1164,13 @@ Bundle (<| (bundle.prefix "jvm") (|> ..conversion_bundle - (dictionary.merge ..int_bundle) - (dictionary.merge ..long_bundle) - (dictionary.merge ..float_bundle) - (dictionary.merge ..double_bundle) - (dictionary.merge ..char_bundle) - (dictionary.merge ..array_bundle) - (dictionary.merge ..object_bundle) - (dictionary.merge ..member_bundle) - (dictionary.merge ..class_bundle) + (dictionary.merged ..int_bundle) + (dictionary.merged ..long_bundle) + (dictionary.merged ..float_bundle) + (dictionary.merged ..double_bundle) + (dictionary.merged ..char_bundle) + (dictionary.merged ..array_bundle) + (dictionary.merged ..object_bundle) + (dictionary.merged ..member_bundle) + (dictionary.merged ..class_bundle) ))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/function.lux b/lux-jvm/source/luxc/lang/translation/jvm/function.lux index fcbfe1277..bb592ca32 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/function.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/function.lux @@ -115,11 +115,11 @@ (list (_.int +0)) _.fuse) function.identity)]] - (wrap (|>> (_.NEW class) - _.DUP - (_.fuse captureI+) - argsI - (_.INVOKESPECIAL class "<init>" (init_method env arity)))))) + (in (|>> (_.NEW class) + _.DUP + (_.fuse captureI+) + argsI + (_.INVOKESPECIAL class "<init>" (init_method env arity)))))) (def: (reset_method return) (-> (Type Class) (Type Method)) @@ -301,7 +301,7 @@ ))] (do phase.monad [instanceI (..instance generate archive classD arity env)] - (wrap [functionD instanceI])))) + (in [functionD instanceI])))) (def: #export (function' forced_context generate archive [env arity bodyS]) (-> (Maybe Context) (Generator Abstraction)) @@ -312,8 +312,8 @@ (do ! [without_context (generation.with_anchor [@begin 1] (generate archive bodyS))] - (wrap [function_context - without_context])) + (in [function_context + without_context])) #.None (generation.with_new_context archive @@ -332,8 +332,8 @@ (generation.save! (product.right function_context) #.None directive) (#.Some function_context) - (wrap []))] - (wrap instanceI))) + (in []))] + (in instanceI))) (def: #export function (Generator Abstraction) @@ -351,5 +351,5 @@ (_.fuse chunkI+) (_.INVOKEVIRTUAL //.$Function //runtime.apply_method (//runtime.apply_signature (list.size chunkI+)))))) _.fuse)]] - (wrap (|>> functionI - applyI)))) + (in (|>> functionI + applyI)))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/loop.lux b/lux-jvm/source/luxc/lang/translation/jvm/loop.lux index d17d3dfe2..40f8ef0de 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/loop.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/loop.lux @@ -55,7 +55,7 @@ valuesI+ (monad.map @ (function (_ [register argS]) (: (Operation Inst) (if (invariant? register argS) - (wrap function.identity) + (in function.identity) (translate archive argS)))) pairs) #let [storesI+ (list@map (function (_ [register argS]) @@ -63,10 +63,10 @@ (if (invariant? register argS) function.identity (_.ASTORE register)))) - (list.reverse pairs))]] - (wrap (|>> (_.fuse valuesI+) - (_.fuse storesI+) - (_.GOTO @begin))))) + (list.reversed pairs))]] + (in (|>> (_.fuse valuesI+) + (_.fuse storesI+) + (_.GOTO @begin))))) (def: #export (scope translate archive [start initsS+ iterationS]) (Generator [Nat (List Synthesis) Synthesis]) @@ -80,6 +80,6 @@ (|>> initI (_.ASTORE (n.+ start register))))) _.fuse)]] - (wrap (|>> initializationI - (_.label @begin) - iterationI)))) + (in (|>> initializationI + (_.label @begin) + iterationI)))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux b/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux index 1bced2ffc..2c814d24f 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux @@ -21,7 +21,7 @@ (-> Bit (Operation Inst)) (let [Boolean (type.class "java.lang.Boolean" (list))] (function (_ value) - (operation@wrap (_.GETSTATIC Boolean (if value "TRUE" "FALSE") Boolean))))) + (operation@in (_.GETSTATIC Boolean (if value "TRUE" "FALSE") Boolean))))) (import: java/lang/Byte ["#::." @@ -38,13 +38,13 @@ (case (.int value) (^template [<int> <instruction>] [<int> - (operation@wrap (|>> <instruction> (_.wrap type.long)))]) + (operation@in (|>> <instruction> (_.wrap type.long)))]) ([+0 _.LCONST_0] [+1 _.LCONST_1]) (^template [<int> <instruction>] [<int> - (operation@wrap (|>> <instruction> _.I2L (_.wrap type.long)))]) + (operation@in (|>> <instruction> _.I2L (_.wrap type.long)))]) ([-1 _.ICONST_M1] ## [+0 _.ICONST_0] ## [+1 _.ICONST_1] @@ -64,7 +64,7 @@ ## else (|> value .int _.long))] - (operation@wrap (|>> constantI (_.wrap type.long)))))) + (operation@in (|>> constantI (_.wrap type.long)))))) (import: java/lang/Double ["#::." @@ -79,17 +79,17 @@ (case value (^template [<int> <instruction>] [<int> - (operation@wrap (|>> <instruction> (_.wrap type.double)))]) + (operation@in (|>> <instruction> (_.wrap type.double)))]) ([+1.0 _.DCONST_1]) (^template [<int> <instruction>] [<int> - (operation@wrap (|>> <instruction> _.F2D (_.wrap type.double)))]) + (operation@in (|>> <instruction> _.F2D (_.wrap type.double)))]) ([+2.0 _.FCONST_2]) (^template [<int> <instruction>] [<int> - (operation@wrap (|>> <instruction> _.I2D (_.wrap type.double)))]) + (operation@in (|>> <instruction> _.I2D (_.wrap type.double)))]) ([-1.0 _.ICONST_M1] ## [+0.0 _.ICONST_0] ## [+1.0 _.ICONST_1] @@ -105,8 +105,8 @@ (i.= ..d0-bits)) _.DCONST_0 (_.double value))] - (operation@wrap (|>> constantI (_.wrap type.double)))))) + (operation@in (|>> constantI (_.wrap type.double)))))) (def: #export text (-> Text (Operation Inst)) - (|>> _.string operation@wrap)) + (|>> _.string operation@in)) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/reference.lux b/lux-jvm/source/luxc/lang/translation/jvm/reference.lux index bfbda85be..b2dfe7676 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/reference.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/reference.lux @@ -41,10 +41,10 @@ (do {@ phase.monad} [class_name (\ @ map //.class_name (generation.context archive))] - (wrap (|>> (_.ALOAD 0) - (_.GETFIELD (type.class class_name (list)) - (|> variable .nat foreign_name) - //.$Value))))) + (in (|>> (_.ALOAD 0) + (_.GETFIELD (type.class class_name (list)) + (|> variable .nat foreign_name) + //.$Value))))) (def: local (-> Register Inst) @@ -54,7 +54,7 @@ (-> Archive Variable (Operation Inst)) (case variable (#variable.Local variable) - (operation@wrap (local variable)) + (operation@in (local variable)) (#variable.Foreign variable) (foreign archive variable))) @@ -64,4 +64,4 @@ (do {@ phase.monad} [class_name (\ @ map //.class_name (generation.remember archive name))] - (wrap (_.GETSTATIC (type.class class_name (list)) //.value_field //.$Value)))) + (in (_.GETSTATIC (type.class class_name (list)) //.value_field //.$Value)))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux b/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux index cccdf42bf..e8f678211 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux @@ -351,7 +351,7 @@ (do phase.monad [_ (generation.execute! directive) _ (generation.save! ..runtime_id #.None directive)] - (wrap [..runtime_id #.None bytecode])))) + (in [..runtime_id #.None bytecode])))) (def: function_id 1) @@ -388,17 +388,17 @@ (do phase.monad [_ (generation.execute! directive) _ (generation.save! ..function_id #.None directive)] - (wrap [..function_id #.None bytecode])))) + (in [..function_id #.None bytecode])))) (def: #export translate (Operation [Registry Output]) (do phase.monad [runtime_payload ..translate_runtime function_payload ..translate_function] - (wrap [(|> artifact.empty - artifact.resource - product.right - artifact.resource - product.right) - (row.row runtime_payload - function_payload)]))) + (in [(|> artifact.empty + artifact.resource + product.right + artifact.resource + product.right) + (row.row runtime_payload + function_payload)]))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux index a9666958b..86b4431da 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux @@ -46,21 +46,21 @@ (Generator (List Synthesis)) (do {@ phase.monad} [#let [size (list.size members)] - _ (phase.assert ..not_a_tuple size - (n.>= 2 size)) + _ (phase.assertion ..not_a_tuple size + (n.>= 2 size)) membersI (|> members list.enumeration (monad.map @ (function (_ [idx member]) (do @ [memberI (generate archive member)] - (wrap (|>> _.DUP - (_.int (.int idx)) - memberI - _.AASTORE))))) + (in (|>> _.DUP + (_.int (.int idx)) + memberI + _.AASTORE))))) (\ @ map _.fuse))] - (wrap (|>> (_.int (.int size)) - (_.array //runtime.$Value) - membersI)))) + (in (|>> (_.int (.int size)) + (_.array //runtime.$Value) + membersI)))) (import: java/lang/Byte ["#::." @@ -109,12 +109,12 @@ (do phase.monad [memberI (generate archive member) #let [tagI (..tagI lefts right?)]] - (wrap (|>> tagI - (flagI right?) - memberI - (_.INVOKESTATIC //.$Runtime - "variant_make" - (type.method [(list) - (list //runtime.$Tag //runtime.$Flag //runtime.$Value) - //.$Variant - (list)])))))) + (in (|>> tagI + (flagI right?) + memberI + (_.INVOKESTATIC //.$Runtime + "variant_make" + (type.method [(list) + (list //runtime.$Tag //runtime.$Flag //runtime.$Value) + //.$Variant + (list)])))))) diff --git a/lux-jvm/source/program.lux b/lux-jvm/source/program.lux index 60fb953aa..6442a87e7 100644 --- a/lux-jvm/source/program.lux +++ b/lux-jvm/source/program.lux @@ -212,19 +212,19 @@ (do phase.monad [instanceG (function.function' (#.Some [0 (.nat -1)]) expression.translate archive [(list) 4 ..how_to_wrap_a_phase]) phase_wrapper (generation.evaluate! [0 (.nat -2)] instanceG)] - (wrap (function (_ phase) - (<| try.assumed - (: (Try java/lang/Object)) - (do try.monad - [apply_method (|> phase_wrapper - (:as java/lang/Object) - (java/lang/Object::getClass) - (java/lang/Class::getMethod runtime.apply_method _apply1_args))] - (java/lang/reflect/Method::invoke - (:as java/lang/Object phase_wrapper) - (|> (ffi.array java/lang/Object 1) - (ffi.array_write 0 (:as java/lang/Object phase))) - apply_method))))))) + (in (function (_ phase) + (<| try.assumed + (: (Try java/lang/Object)) + (do try.monad + [apply_method (|> phase_wrapper + (:as java/lang/Object) + (java/lang/Object::getClass) + (java/lang/Class::getMethod runtime.apply_method _apply1_args))] + (java/lang/reflect/Method::invoke + (:as java/lang/Object phase_wrapper) + (|> (ffi.array java/lang/Object 1) + (ffi.array_write 0 (:as java/lang/Object phase))) + apply_method))))))) (def: #export platform ## (IO (Platform Anchor (Bytecode Any) Definition)) @@ -233,15 +233,15 @@ (do io.monad [## host jvm/host.host [loader host] jvm.host] - (wrap [loader - {#platform.&file_system (file.async file.default) - #platform.host host - ## #platform.phase jvm.generate - #platform.phase expression.translate - ## #platform.runtime runtime.generate - #platform.runtime runtime.translate - #platform.phase_wrapper ..phase_wrapper - #platform.write product.right}]))) + (in [loader + {#platform.&file_system (file.async file.default) + #platform.host host + ## #platform.phase jvm.generate + #platform.phase expression.translate + ## #platform.runtime runtime.generate + #platform.runtime runtime.translate + #platform.phase_wrapper ..phase_wrapper + #platform.write product.right}]))) (def: (extender phase_wrapper) (-> platform.Phase_Wrapper Extender) diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index 5b7f56b2a..c342863e7 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -1476,7 +1476,7 @@ ys} xs)) -(def:''' (_$_joiner op a1 a2) +(def:''' (right_associativity op a1 a2) #End (-> Code Code Code Code) ({[_ (#Form parts)] @@ -1486,7 +1486,7 @@ (form$ (list op a1 a2))} op)) -(def:''' (function/flip func) +(def:''' (function\flip func) #End (All [a b c] (-> (-> a b c) (-> b a c))) @@ -1505,7 +1505,7 @@ #End) ({(#Item op tokens') ({(#Item first nexts) - (return (list (list\fold (function/flip (_$_joiner op)) first nexts))) + (return (list (list\fold (function\flip (right_associativity op)) first nexts))) _ (failure "Wrong syntax for _$")} @@ -1527,7 +1527,7 @@ #End) ({(#Item op tokens') ({(#Item last prevs) - (return (list (list\fold (_$_joiner op) last prevs))) + (return (list (list\fold (right_associativity op) last prevs))) _ (failure "Wrong syntax for $_")} @@ -1734,7 +1734,7 @@ #None} def_meta))) -(def:''' (resolve_global_identifier full_name state) +(def:''' (global_identifier full_name state) #End (-> Name ($' Meta Name)) (let' [[module name] full_name @@ -1850,7 +1850,7 @@ [real_name ({"" (if (text\= "" subst) (in [module name]) - (resolve_global_identifier [subst name])) + (global_identifier [subst name])) _ (in [module name])} @@ -2069,7 +2069,7 @@ #None} x)) -(def:''' (tuple_to_list tuple) +(def:''' (tuple_list tuple) #End (-> Code ($' Maybe ($' List Code))) ({[_ (#Tuple members)] @@ -2178,7 +2178,7 @@ _ (failure "Wrong syntax for template")} [(monad\map maybe_monad get_short bindings) - (monad\map maybe_monad tuple_to_list data)]) + (monad\map maybe_monad tuple_list data)]) _ (failure "Wrong syntax for template")} @@ -2465,20 +2465,20 @@ (return (list syntax))} syntax)) -(def:''' (walk_type type) +(def:''' (normal_type type) #End (-> Code Code) ({[_ (#Form (#Item [_ (#Tag tag)] parts))] - (form$ (#Item [(tag$ tag) (list\map walk_type parts)])) + (form$ (#Item [(tag$ tag) (list\map normal_type parts)])) [_ (#Tuple members)] - (` (Tuple (~+ (list\map walk_type members)))) + (` (Tuple (~+ (list\map normal_type members)))) [_ (#Form (#Item [_ (#Text "lux in-module")] (#Item [_ (#Text module)] (#Item type' #End))))] - (` ("lux in-module" (~ (text$ module)) (~ (walk_type type')))) + (` ("lux in-module" (~ (text$ module)) (~ (normal_type type')))) [_ (#Form (#Item [_ (#Identifier ["" ":~"])] (#Item expression #End)))] expression @@ -2486,8 +2486,8 @@ [_ (#Form (#Item type_fn args))] (list\fold ("lux type check" (-> Code Code Code) (function' [arg type_fn] (` (#.Apply (~ arg) (~ type_fn))))) - (walk_type type_fn) - (list\map walk_type args)) + (normal_type type_fn) + (list\map normal_type args)) _ type} @@ -2502,7 +2502,7 @@ (do meta_monad [type+ (full_expansion type)] ({(#Item type' #End) - (in (list (walk_type type'))) + (in (list (normal_type type'))) _ (failure "The expansion of the type-syntax had to yield a single element.")} @@ -2552,7 +2552,7 @@ [first a x] [second b y]) -(def:''' (unfold_type_def type_codes) +(def:''' (type_declaration type_codes) #End (-> ($' List Code) ($' Meta (Tuple Code ($' Maybe ($' List Text))))) ({(#Item [_ (#Record pairs)] #End) @@ -2705,11 +2705,6 @@ (failure "Wrong syntax for def'")} parts))) -(def:' (rejoin_pair pair) - (-> [Code Code] (List Code)) - (let' [[left right] pair] - (list left right))) - (def:' (text\encode original) (-> Text Text) ($_ text\compose ..double_quote original ..double_quote)) @@ -2940,7 +2935,7 @@ #None (failure "Wrong syntax for function"))) -(def:' (process_def_meta_value code) +(def:' (definition_annotation_value code) (-> Code Code) (case code [_ (#Bit value)] @@ -2969,7 +2964,7 @@ [_ (#Tuple xs)] (|> xs - (list\map process_def_meta_value) + (list\map definition_annotation_value) untemplated_list (meta_code ["library/lux" "Tuple"])) @@ -2977,18 +2972,18 @@ (|> kvs (list\map (: (-> [Code Code] Code) (function (_ [k v]) - (` [(~ (process_def_meta_value k)) - (~ (process_def_meta_value v))])))) + (` [(~ (definition_annotation_value k)) + (~ (definition_annotation_value v))])))) untemplated_list (meta_code ["library/lux" "Record"])) )) -(def:' (process_def_meta kvs) +(def:' (definition_annotations kvs) (-> (List [Code Code]) Code) (untemplated_list (list\map (: (-> [Code Code] Code) (function (_ [k v]) - (` [(~ (process_def_meta_value k)) - (~ (process_def_meta_value v))]))) + (` [(~ (definition_annotation_value k)) + (~ (definition_annotation_value v))]))) kvs))) (def:' (with_func_args args meta) @@ -3028,7 +3023,7 @@ (list [(tag$ ["library/lux" "doc"]) (text$ ($_ "lux text concat" "## Defines global constants/functions." ..\n - "(def: (rejoin_pair pair)" ..\n + "(def: (pair_list pair)" ..\n " (-> [Code Code] (List Code))" ..\n " (let [[left right] pair]" ..\n " (list left right)))" @@ -3079,7 +3074,7 @@ #None body) - =meta (process_def_meta meta)] + =meta (definition_annotations meta)] (return (list (` ("lux def" (~ name) (~ body) [(~ location_code) @@ -3089,7 +3084,7 @@ #None (failure "Wrong syntax for def:")))) -(def: (meta_code_add addition meta) +(def: (with_definition_annotation addition meta) (-> [Code Code] Code Code) (case [addition meta] [[name value] [location (#Record pairs)]] @@ -3098,11 +3093,11 @@ _ meta)) -(def: (meta_code_merge addition base) +(def: (merged_definition_annotations addition base) (-> Code Code Code) (case addition [location (#Record pairs)] - (list\fold meta_code_add base pairs) + (list\fold with_definition_annotation base pairs) _ base)) @@ -3147,7 +3142,7 @@ _ (` ("lux macro" (function ((~ name) (~+ args)) (~ body))))) - =meta (process_def_meta meta)] + =meta (definition_annotations meta)] (return (list (` ("lux def" (~ name) (~ body) [(~ location_code) @@ -3210,8 +3205,8 @@ (function (_ [m_name m_type]) [(local_tag$ m_name) m_type])) members)) - sig_meta (meta_code_merge (` {#.sig? #1}) - meta) + sig_meta (merged_definition_annotations (` {#.sig? #1}) + meta) usage (case args #End def_name @@ -3265,14 +3260,14 @@ (-> Text Nothing) ("lux io error" message)) -(macro: (default tokens state) +(macro: (else tokens state) {#.doc (text$ ($_ "lux text concat" "## Allows you to provide a default value that will be used" ..\n "## if a (Maybe x) value turns out to be #.None." __paragraph - "(default +20 (#.Some +10)) ## => +10" + "(else +20 (#.Some +10)) ## => +10" __paragraph - "(default +20 #.None) ## => +20"))} + "(else +20 #.None) ## => +20"))} (case tokens (^ (list else maybe)) (let [g!temp (: Code [dummy_location (#Identifier ["" ""])]) @@ -3285,7 +3280,7 @@ (#Right [state (list code)])) _ - (#Left "Wrong syntax for default"))) + (#Left "Wrong syntax for else"))) (def: (text\split_all_with splitter input) (-> Text Text (List Text)) @@ -3302,7 +3297,7 @@ ("lux text size" input))] ("lux text clip" after_offset after_length input)))))) -(def: (nth idx xs) +(def: (item idx xs) (All [a] (-> Nat (List a) (Maybe a))) (case xs @@ -3312,7 +3307,7 @@ (#Item x xs') (if ("lux i64 =" 0 idx) (#Some x) - (nth ("lux i64 -" 1 idx) xs')))) + (item ("lux i64 -" 1 idx) xs')))) ## https://en.wikipedia.org/wiki/Lambda_calculus#%CE%B2-reduction (def: (reduced env type) @@ -3347,7 +3342,7 @@ (#Function (reduced env ?input) (reduced env ?output)) (#Parameter idx) - (case (nth idx env) + (case (item idx env) (#Some parameter) parameter @@ -3361,7 +3356,7 @@ type )) -(def: (apply_type type_fn param) +(def: (applied_type param type_fn) (-> Type Type (Maybe Type)) (case type_fn (#UnivQ env body) @@ -3372,11 +3367,11 @@ (#Apply A F) (do maybe_monad - [type_fn* (apply_type F A)] - (apply_type type_fn* param)) + [type_fn* (applied_type A F)] + (applied_type param type_fn*)) (#Named name type) - (apply_type type param) + (applied_type param type) _ #None)) @@ -3396,17 +3391,17 @@ [flat_lambda #Function] ) -(def: (flat_app type) +(def: (flat_application type) (-> Type [Type (List Type)]) (case type (#Apply head func') - (let [[func tail] (flat_app func')] + (let [[func tail] (flat_application func')] [func (#Item head tail)]) _ [type (list)])) -(def: (resolve_struct_type type) +(def: (interface_methods type) (-> Type (Maybe (List Type))) (case type (#Product _) @@ -3414,17 +3409,17 @@ (#Apply arg func) (do maybe_monad - [output (apply_type func arg)] - (resolve_struct_type output)) + [output (applied_type arg func)] + (interface_methods output)) (#UnivQ _ body) - (resolve_struct_type body) + (interface_methods body) (#ExQ _ body) - (resolve_struct_type body) + (interface_methods body) (#Named name type) - (resolve_struct_type type) + (interface_methods type) (#Sum _) #None @@ -3452,7 +3447,7 @@ [module_name current_module_name] (module module_name))) -(def: (resolve_tag [module name]) +(def: (type_tag [module name]) (-> Name (Meta [Nat (List Name) Bit Type])) (do meta_monad [=module (..module module) @@ -3464,17 +3459,17 @@ _ (failure (text\compose "Unknown tag: " (name\encode [module name])))))) -(def: (resolve_type_tags type) +(def: (record_slots type) (-> Type (Meta (Maybe [(List Name) (List Type)]))) (case type (#Apply arg func) - (resolve_type_tags func) + (record_slots func) (#UnivQ env body) - (resolve_type_tags body) + (record_slots body) (#ExQ env body) - (resolve_type_tags body) + (record_slots body) (#Named [module name] unnamed) (do meta_monad @@ -3482,7 +3477,7 @@ #let [{#module_hash _ #module_aliases _ #definitions bindings #imports _ #tags tags #types types #module_annotations _ #module_state _} =module]] (case (get name types) (#Some [tags exported? (#Named _ _type)]) - (case (resolve_struct_type _type) + (case (interface_methods _type) (#Some members) (return (#Some [tags members])) @@ -3490,7 +3485,7 @@ (return #None)) _ - (resolve_type_tags unnamed))) + (record_slots unnamed))) _ (return #None))) @@ -3514,7 +3509,7 @@ (do meta_monad [tokens' (monad\map meta_monad expansion tokens) struct_type get_expected_type - tags+type (resolve_type_tags struct_type) + tags+type (record_slots struct_type) tags (: (Meta (List Name)) (case tags+type (#Some [tags _]) @@ -3595,8 +3590,8 @@ _ (` ((~ name) (~+ args))))] (return (list (` (..def: (~+ (export exported?)) (~ usage) - (~ (meta_code_merge (` {#.implementation? #1}) - meta)) + (~ (merged_definition_annotations (` {#.implementation? #1}) + meta)) (~ type) (implementation (~+ definitions))))))) @@ -3643,7 +3638,7 @@ (case parts (#Some name args meta type_codes) (do meta_monad - [type+tags?? (unfold_type_def type_codes) + [type+tags?? (..type_declaration type_codes) module_name current_module_name] (let [type_name (local_identifier$ name) [type tags??] type+tags?? @@ -3663,7 +3658,7 @@ _ (#Some (` (.All (~ type_name) [(~+ args)] (~ type))))))) - total_meta (let [meta (process_def_meta meta) + total_meta (let [meta (definition_annotations meta) meta (if rec? (` (#.Item (~ (flag_meta "type_rec?")) (~ meta))) meta)] @@ -3726,7 +3721,7 @@ #import_alias (Maybe Text) #import_refer Refer}) -(def: (extract_defs defs) +(def: (referral_references defs) (-> (List Code) (Meta (List Text))) (monad\map meta_monad (: (-> Code (Meta Text)) @@ -3745,13 +3740,13 @@ (^or (^ (list& [_ (#Form (list& [_ (#Tag ["" "+"])] defs))] tokens')) (^ (list& [_ (#Form (list& [_ (#Tag ["" "only"])] defs))] tokens'))) (do meta_monad - [defs' (extract_defs defs)] + [defs' (..referral_references defs)] (in [(#Only defs') tokens'])) (^or (^ (list& [_ (#Form (list& [_ (#Tag ["" "-"])] defs))] tokens')) (^ (list& [_ (#Form (list& [_ (#Tag ["" "exclude"])] defs))] tokens'))) (do meta_monad - [defs' (extract_defs defs)] + [defs' (..referral_references defs)] (in [(#Exclude defs') tokens'])) (^or (^ (list& [_ (#Tag ["" "*"])] tokens')) @@ -3818,7 +3813,7 @@ (def: contextual_reference "#") (def: self_reference ".") -(def: (de_alias context self aliased) +(def: (module_alias context self aliased) (-> Text Text Text Text) (|> aliased (replace_all ..self_reference self) @@ -3977,15 +3972,15 @@ #let [[referral extra] referral+extra] openings+extra (openings_parser extra) #let [[openings extra] openings+extra - de_aliased (de_alias context_alias m_name alias)] - sub_imports (imports_parser #1 import_name de_aliased extra)] + module_alias (..module_alias context_alias m_name alias)] + sub_imports (imports_parser #1 import_name module_alias extra)] (in (case [referral openings] [#Ignore #End] sub_imports _ (list& {#import_name import_name - #import_alias (#Some de_aliased) + #import_alias (#Some module_alias) #import_refer {#refer_defs referral #refer_open openings}} sub_imports)))) @@ -4109,8 +4104,8 @@ (#Some definition) (case definition - (#Left de_aliased) - (definition_type de_aliased state) + (#Left real_name) + (definition_type real_name state) (#Right [exported? def_type def_meta def_value]) (#Some def_type)))))) @@ -4133,8 +4128,8 @@ (#Some definition) (case definition - (#Left de_aliased) - (definition_value de_aliased state) + (#Left real_name) + (definition_value real_name state) (#Right [exported? def_type def_meta def_value]) (#Right [state [def_type def_value]])))))) @@ -4242,7 +4237,7 @@ ($_ text\compose "(Ex " (type\encode body) ")") (#Apply _) - (let [[func args] (flat_app type)] + (let [[func args] (flat_application type)] ($_ text\compose "(" (type\encode func) " " (|> args (list\map type\encode) (interpose " ") list\reverse (list\fold text\compose "")) @@ -4268,7 +4263,7 @@ (^ (list [_ (#Identifier name)] [_ (#Text alias)] body)) (do meta_monad [init_type (type_definition name) - struct_evidence (resolve_type_tags init_type)] + struct_evidence (record_slots init_type)] (case struct_evidence #None (failure (text\compose "Can only 'open' structs: " (type\encode init_type))) @@ -4278,14 +4273,14 @@ [full_body ((: (-> Name [(List Name) (List Type)] Code (Meta Code)) (function (recur source [tags members] target) (let [locals (list\map (function (_ [t_module t_name]) - ["" (de_alias "" t_name alias)]) + ["" (..module_alias "" t_name alias)]) tags) pattern (tuple$ (list\map identifier$ locals))] (do meta_monad [enhanced_target (monad\fold meta_monad (function (_ [m_local m_type] enhanced_target) (do meta_monad - [m_implementation (resolve_type_tags m_type)] + [m_implementation (record_slots m_type)] (case m_implementation (#Some m_tags&members) (recur m_local @@ -4353,11 +4348,11 @@ (^ (list [_ (#Tag slot')] record)) (do meta_monad [slot (normal slot') - output (resolve_tag slot) + output (..type_tag slot) #let [[idx tags exported? type] output] g!_ (gensym "_") g!output (gensym "")] - (case (resolve_struct_type type) + (case (interface_methods type) (#Some members) (let [pattern (record$ (list\map (: (-> [Name [Nat Type]] [Code Code]) (function (_ [[r_prefix r_name] [r_idx r_type]]) @@ -4387,10 +4382,10 @@ _ (failure "Wrong syntax for get@"))) -(def: (open_field alias tags my_tag_index [module short] source type) +(def: (open_declaration alias tags my_tag_index [module short] source type) (-> Text (List Name) Nat Name Code Type (Meta (List Code))) (do meta_monad - [output (resolve_type_tags type) + [output (record_slots type) g!_ (gensym "g!_") #let [g!output (local_identifier$ short) pattern (|> tags @@ -4407,12 +4402,12 @@ [decls' (monad\map meta_monad (: (-> [Nat Name Type] (Meta (List Code))) (function (_ [sub_tag_index sname stype]) - (open_field alias tags' sub_tag_index sname source+ stype))) + (open_declaration alias tags' sub_tag_index sname source+ stype))) (enumeration (zipped/2 tags' members')))] (return (list\join decls'))) _ - (return (list (` ("lux def" (~ (local_identifier$ (de_alias "" short alias))) + (return (list (` ("lux def" (~ (local_identifier$ (..module_alias "" short alias))) (~ source+) [(~ location_code) (#.Record #End)] #0))))))) @@ -4435,14 +4430,14 @@ [_ (#Identifier struct_name)] (do meta_monad [struct_type (type_definition struct_name) - output (resolve_type_tags struct_type) + output (record_slots struct_type) #let [source (identifier$ struct_name)]] (case output (#Some [tags members]) (do meta_monad [decls' (monad\map meta_monad (: (-> [Nat Name Type] (Meta (List Code))) (function (_ [tag_index sname stype]) - (open_field alias tags tag_index sname source stype))) + (open_declaration alias tags tag_index sname source stype))) (enumeration (zipped/2 tags members)))] (return (list\join decls'))) @@ -4489,7 +4484,7 @@ #let [{#module_hash _ #module_aliases _ #definitions _ #imports imports #tags _ #types _ #module_annotations _ #module_state _} module]] (in (is_member? imports import_name)))) -(def: (read_refer module_name options) +(def: (referrals module_name options) (-> Text (List Code) (Meta Refer)) (do meta_monad [referral+options (referrals_parser options) @@ -4509,7 +4504,7 @@ (interpose " ") (list\fold text\compose ""))))))) -(def: (write_refer module_name [r_defs r_opens]) +(def: (referral_definitions module_name [r_defs r_opens]) (-> Text Refer (Meta (List Code))) (do meta_monad [current_module current_module_name @@ -4554,22 +4549,21 @@ (` (open: (~ (text$ alias)) (~ (identifier$ [module_name name]))))) structs)))) list\join)]] - (in (list\compose defs openings)) - )) + (in (list\compose defs openings)))) (macro: #export (refer tokens) (case tokens (^ (list& [_ (#Text module_name)] options)) (do meta_monad - [=refer (read_refer module_name options)] - (write_refer module_name =refer)) + [=refer (referrals module_name options)] + (referral_definitions module_name =refer)) _ (failure "Wrong syntax for refer"))) (def: (refer_code module_name module_alias' [r_defs r_opens]) (-> Text (Maybe Text) Refer Code) - (let [module_alias (..default module_name module_alias') + (let [module_alias (..else module_name module_alias') localizations (: (List Code) (case r_defs #All @@ -4625,14 +4619,14 @@ #let [=imports (|> imports (list\map (: (-> Importation Code) (function (_ [m_name m_alias =refer]) - (` [(~ (text$ m_name)) (~ (text$ (default "" m_alias)))])))) + (` [(~ (text$ m_name)) (~ (text$ (..else "" m_alias)))])))) tuple$) =refers (list\map (: (-> Importation Code) (function (_ [m_name m_alias =refer]) (refer_code m_name m_alias =refer))) imports) =module (` ("lux def module" [(~ location_code) - (#.Record (~ (process_def_meta _meta)))] + (#.Record (~ (definition_annotations _meta)))] (~ =imports)))]] (in (#Item =module =refers)))) @@ -4668,9 +4662,9 @@ (^ (list [_ (#Tag slot')] value record)) (do meta_monad [slot (normal slot') - output (resolve_tag slot) + output (..type_tag slot) #let [[idx tags exported? type] output]] - (case (resolve_struct_type type) + (case (interface_methods type) (#Some members) (do meta_monad [pattern' (monad\map meta_monad @@ -4757,9 +4751,9 @@ (^ (list [_ (#Tag slot')] fun record)) (do meta_monad [slot (normal slot') - output (resolve_tag slot) + output (..type_tag slot) #let [[idx tags exported? type] output]] - (case (resolve_struct_type type) + (case (interface_methods type) (#Some members) (do meta_monad [pattern' (monad\map meta_monad @@ -4847,7 +4841,7 @@ " ([#.UnivQ] [#.ExQ])" __paragraph " (#.Parameter idx)" ..\n - " (default type (list.nth idx env))" + " (else type (list.item idx env))" __paragraph " _" ..\n " type" ..\n @@ -4860,7 +4854,7 @@ (case (: (Maybe (List Code)) (do maybe_monad [bindings' (monad\map maybe_monad get_short bindings) - data' (monad\map maybe_monad tuple_to_list data)] + data' (monad\map maybe_monad tuple_list data)] (let [num_bindings (list\size bindings')] (if (every? (|>> ("lux i64 =" num_bindings)) (list\map list\size data')) @@ -4962,7 +4956,12 @@ (def: un_paired (-> (List [Code Code]) (List Code)) - (|>> (list\map rejoin_pair) list\join)) + (let [pair_list (: (-> [Code Code] (List Code)) + (function (_ pair) + (let [[left right] pair] + (list left right))))] + (|>> (list\map pair_list) + list\join))) (def: (doc_example_to_text prev_location baseline example) (-> Location Nat Code [Location Text]) @@ -5162,7 +5161,7 @@ #let [[hslot tslots] slots] hslot (..normal hslot) tslots (monad\map meta_monad ..normal tslots) - output (resolve_tag hslot) + output (..type_tag hslot) g!_ (gensym "_") #let [[idx tags exported? type] output slot_pairings (list\map (: (-> Name [Text Code]) @@ -5181,7 +5180,7 @@ _ (failure "Wrong syntax for ^slots"))) -(def: (place_tokens label tokens target) +(def: (with_expansions' label tokens target) (-> Text (List Code) Code (Maybe (List Code))) (case target (^or [_ (#Bit _)] [_ (#Nat _)] [_ (#Int _)] [_ (#Rev _)] [_ (#Frac _)] [_ (#Text _)] [_ (#Tag _)]) @@ -5196,7 +5195,7 @@ (^template [<tag>] [[location (<tag> elems)] (do maybe_monad - [placements (monad\map maybe_monad (place_tokens label tokens) elems)] + [placements (monad\map maybe_monad (with_expansions' label tokens) elems)] (in (list [location (<tag> (list\join placements))])))]) ([#Tuple] [#Form]) @@ -5207,8 +5206,8 @@ (: (-> [Code Code] (Maybe [Code Code])) (function (_ [slot value]) (do maybe_monad - [slot' (place_tokens label tokens slot) - value' (place_tokens label tokens value)] + [slot' (with_expansions' label tokens slot) + value' (with_expansions' label tokens value)] (case [slot' value'] (^ [(list =slot) (list =value)]) (in [=slot =value]) @@ -5216,8 +5215,7 @@ _ #None)))) pairs)] - (in (list [location (#Record =pairs)]))) - )) + (in (list [location (#Record =pairs)]))))) (macro: #export (with_expansions tokens) {#.doc (doc "Controlled macro-expansion." @@ -5245,9 +5243,10 @@ (^ (list& [_ (#Identifier ["" var_name])] expr bindings')) (do meta_monad [expansion (single_expansion expr)] - (case (place_tokens var_name expansion (` (.with_expansions - [(~+ bindings')] - (~+ bodies)))) + (case (with_expansions' var_name expansion + (` (.with_expansions + [(~+ bindings')] + (~+ bodies)))) (#Some output) (in output) @@ -5487,7 +5486,7 @@ (^ (list [_ (#Nat idx)])) (do meta_monad [stvs get_scope_type_vars] - (case (..nth idx (list\reverse stvs)) + (case (..item idx (list\reverse stvs)) (#Some var_id) (in (list (` (#Ex (~ (nat$ var_id)))))) @@ -5720,7 +5719,7 @@ (function (_ compiler) (#Right [compiler (get@ [#info #target] compiler)]))) -(def: (resolve_target choice) +(def: (platform_name choice) (-> Code (Meta Text)) (case choice [_ (#Text platform)] @@ -5728,7 +5727,7 @@ [_ (#Identifier identifier)] (do meta_monad - [identifier (..resolve_global_identifier identifier) + [identifier (..global_identifier identifier) type+value (..definition_value identifier) #let [[type value] type+value]] (case (..flat_alias type) @@ -5759,7 +5758,7 @@ (#Item [key pick] options') (do meta_monad - [platform (..resolve_target key)] + [platform (..platform_name key)] (if (text\= target platform) (return (list pick)) (target_pick target options' default))))) @@ -5786,7 +5785,7 @@ [left a x] [right b y]) -(def: (label_code code) +(def: (embedded_expansions code) (-> Code (Meta [(List [Code Code]) Code])) (case code (^ [ann (#Form (list [_ (#Identifier ["" "~~"])] expansion))]) @@ -5797,7 +5796,7 @@ (^template [<tag>] [[ann (<tag> parts)] (do meta_monad - [=parts (monad\map meta_monad label_code parts)] + [=parts (monad\map meta_monad embedded_expansions parts)] (in [(list\fold list\compose (list) (list\map left =parts)) [ann (<tag> (list\map right =parts))]]))]) ([#Form] [#Tuple]) @@ -5807,8 +5806,8 @@ [=kvs (monad\map meta_monad (function (_ [key val]) (do meta_monad - [=key (label_code key) - =val (label_code val) + [=key (embedded_expansions key) + =val (embedded_expansions val) #let [[key_labels key_labelled] =key [val_labels val_labelled] =val]] (in [(list\compose key_labels val_labels) [key_labelled val_labelled]]))) @@ -5823,7 +5822,7 @@ (case tokens (^ (list raw)) (do meta_monad - [=raw (label_code raw) + [=raw (..embedded_expansions raw) #let [[labels labelled] =raw]] (in (list (` (with_expansions [(~+ (|> labels (list\map (function (_ [label expansion]) (list label expansion))) diff --git a/stdlib/source/library/lux/control/concurrency/frp.lux b/stdlib/source/library/lux/control/concurrency/frp.lux index beecb2511..7d0ac6129 100644 --- a/stdlib/source/library/lux/control/concurrency/frp.lux +++ b/stdlib/source/library/lux/control/concurrency/frp.lux @@ -240,13 +240,13 @@ (-> Nat [(Channel Any) (Sink Any)]) (..poll milli_seconds (io []))) -(def: #export (iterate f init) +(def: #export (iterations f init) (All [s o] (-> (-> s (Async (Maybe [s o]))) s (Channel o))) (do async.monad [?next (f init)] (case ?next (#.Some [state output]) - (in (#.Some [output (iterate f state)])) + (in (#.Some [output (iterations f state)])) #.None (in #.None)))) diff --git a/stdlib/source/library/lux/control/concurrency/thread.lux b/stdlib/source/library/lux/control/concurrency/thread.lux index 9a6f3a7b1..edfc01f8c 100644 --- a/stdlib/source/library/lux/control/concurrency/thread.lux +++ b/stdlib/source/library/lux/control/concurrency/thread.lux @@ -169,6 +169,6 @@ (do ! [_ (monad.map ! (|>> (get@ #action) ..execute! io.io) ready)] (recur [])) - (error! (exception.construct ..cannot_continue_running_threads [])))) + (error! (exception.error ..cannot_continue_running_threads [])))) )))) )) diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux index 8358da7b3..65ddd84f1 100644 --- a/stdlib/source/library/lux/control/exception.lux +++ b/stdlib/source/library/lux/control/exception.lux @@ -73,15 +73,15 @@ (All [a] (-> a (Try a))) (#//.Success value)) -(def: #export (construct exception message) - {#.doc "Constructs an exception."} +(def: #export (error exception message) + {#.doc "Constructs an error message from an exception."} (All [e] (-> (Exception e) e Text)) ((get@ #..constructor exception) message)) (def: #export (except exception message) {#.doc "Decorate an error message with an Exception and lift it into the error-handling context."} (All [e a] (-> (Exception e) e (Try a))) - (#//.Failure (..construct exception message))) + (#//.Failure (..error exception message))) (def: #export (assertion exception message test) (All [e] (-> (Exception e) e Bit (Try Any))) @@ -161,7 +161,7 @@ (list\map (function (_ [header message]) (` [(~ header) (~ message)]))))))))))) -(def: #export (enumerate format entries) +(def: #export (listing format entries) {#.doc (doc "A numbered report of the entries on a list." "NOTE: 0-based numbering.")} (All [a] @@ -198,10 +198,10 @@ (#//.Failure error) (#//.Failure (case error "" - (..construct exception message) + (..error exception message) _ - (..decorate (..construct exception message) error))) + (..decorate (..error exception message) error))) success success)) diff --git a/stdlib/source/library/lux/control/function/contract.lux b/stdlib/source/library/lux/control/function/contract.lux index 00c1bb59c..59ad5b681 100644 --- a/stdlib/source/library/lux/control/function/contract.lux +++ b/stdlib/source/library/lux/control/function/contract.lux @@ -35,7 +35,7 @@ (pre (i.= +4 (i.+ +2 +2)) (foo +123 +456 +789)))} (in (list (` (exec - ((~! ..assert!) (~ (code.text (exception.construct ..pre_condition_failed test))) + ((~! ..assert!) (~ (code.text (exception.error ..pre_condition_failed test))) (~ test)) (~ expr)))))) @@ -49,6 +49,6 @@ (with_gensyms [g!output] (in (list (` (let [(~ g!output) (~ expr)] (exec - ((~! ..assert!) (~ (code.text (exception.construct ..post_condition_failed test))) + ((~! ..assert!) (~ (code.text (exception.error ..post_condition_failed test))) ((~ test) (~ g!output))) (~ g!output)))))))) diff --git a/stdlib/source/library/lux/control/parser/analysis.lux b/stdlib/source/library/lux/control/parser/analysis.lux index 19b02e507..738960e55 100644 --- a/stdlib/source/library/lux/control/parser/analysis.lux +++ b/stdlib/source/library/lux/control/parser/analysis.lux @@ -42,11 +42,11 @@ (exception: #export (cannot_parse {input (List Analysis)}) (exception.report - ["Input" (exception.enumerate /.%analysis input)])) + ["Input" (exception.listing /.%analysis input)])) (exception: #export (unconsumed_input {input (List Analysis)}) (exception.report - ["Input" (exception.enumerate /.%analysis input)])) + ["Input" (exception.listing /.%analysis input)])) (type: #export Parser {#.doc (doc "A parser for Lux code analysis nodes.")} diff --git a/stdlib/source/library/lux/control/parser/binary.lux b/stdlib/source/library/lux/control/parser/binary.lux index ec683489f..7827bd8c0 100644 --- a/stdlib/source/library/lux/control/parser/binary.lux +++ b/stdlib/source/library/lux/control/parser/binary.lux @@ -240,7 +240,7 @@ (do //.monad [raw (..list value) #let [output (set.of_list hash raw)] - _ (//.assertion (exception.construct ..set_elements_are_not_unique []) + _ (//.assertion (exception.error ..set_elements_are_not_unique []) (n.= (list.size raw) (set.size output)))] (in output))) diff --git a/stdlib/source/library/lux/control/parser/json.lux b/stdlib/source/library/lux/control/parser/json.lux index f186a315a..741933205 100644 --- a/stdlib/source/library/lux/control/parser/json.lux +++ b/stdlib/source/library/lux/control/parser/json.lux @@ -28,7 +28,7 @@ (exception: #export (unconsumed_input {input (List JSON)}) (exception.report - ["Input" (exception.enumerate /.format input)])) + ["Input" (exception.listing /.format input)])) (exception: #export empty_input) @@ -74,7 +74,7 @@ (in value) _ - (//.failure (exception.construct ..unexpected_value [head])))))] + (//.failure (exception.error ..unexpected_value [head])))))] [null /.Null #/.Null "null"] [boolean /.Boolean #/.Boolean "boolean"] @@ -98,7 +98,7 @@ (in (\ <equivalence> = test value)) _ - (//.failure (exception.construct ..unexpected_value [head]))))) + (//.failure (exception.error ..unexpected_value [head]))))) (def: #export (<check> test) {#.doc (code.text ($_ text\compose "Ensures a JSON value is a " <desc> "."))} @@ -109,10 +109,10 @@ (<tag> value) (if (\ <equivalence> = test value) (in []) - (//.failure (exception.construct ..value_mismatch [(<tag> test) (<tag> value)]))) + (//.failure (exception.error ..value_mismatch [(<tag> test) (<tag> value)]))) _ - (//.failure (exception.construct ..unexpected_value [head])))))] + (//.failure (exception.error ..unexpected_value [head])))))] [boolean? boolean! /.Boolean bit.equivalence #/.Boolean "boolean"] [number? number! /.Number frac.equivalence #/.Number "number"] @@ -142,10 +142,10 @@ (in output) _ - (//.failure (exception.construct ..unconsumed_input remainder)))) + (//.failure (exception.error ..unconsumed_input remainder)))) _ - (//.failure (exception.construct ..unexpected_value [head]))))) + (//.failure (exception.error ..unexpected_value [head]))))) (def: #export (object parser) {#.doc (doc "Parses the contents of a JSON object." @@ -170,10 +170,10 @@ (in output) _ - (//.failure (exception.construct ..unconsumed_input remainder)))) + (//.failure (exception.error ..unconsumed_input remainder)))) _ - (//.failure (exception.construct ..unexpected_value [head]))))) + (//.failure (exception.error ..unexpected_value [head]))))) (def: #export (field field_name parser) {#.doc (doc "Parses a field inside a JSON object." diff --git a/stdlib/source/library/lux/control/parser/synthesis.lux b/stdlib/source/library/lux/control/parser/synthesis.lux index d8406d3ec..1ecdaab9e 100644 --- a/stdlib/source/library/lux/control/parser/synthesis.lux +++ b/stdlib/source/library/lux/control/parser/synthesis.lux @@ -31,15 +31,15 @@ (exception: #export (cannot_parse {input (List Synthesis)}) (exception.report - ["Input" (exception.enumerate /.%synthesis input)])) + ["Input" (exception.listing /.%synthesis input)])) (exception: #export (unconsumed_input {input (List Synthesis)}) (exception.report - ["Input" (exception.enumerate /.%synthesis input)])) + ["Input" (exception.listing /.%synthesis input)])) (exception: #export (expected_empty_input {input (List Synthesis)}) (exception.report - ["Input" (exception.enumerate /.%synthesis input)])) + ["Input" (exception.listing /.%synthesis input)])) (exception: #export (wrong_arity {expected Arity} {actual Arity}) (exception.report diff --git a/stdlib/source/library/lux/control/parser/text.lux b/stdlib/source/library/lux/control/parser/text.lux index 345eae8ee..1806d77e4 100644 --- a/stdlib/source/library/lux/control/parser/text.lux +++ b/stdlib/source/library/lux/control/parser/text.lux @@ -90,7 +90,7 @@ {#.doc "Yields the next character without applying any logic."} (Parser Text) (function (_ [offset tape]) - (case (/.nth offset tape) + (case (/.char offset tape) (#.Some output) (#try.Success [[("lux i64 +" 1 offset) tape] (/.of_char output)]) @@ -101,7 +101,7 @@ {#.doc "Yields the next character (as a slice) without applying any logic."} (Parser Slice) (function (_ [offset tape]) - (case (/.nth offset tape) + (case (/.char offset tape) (#.Some _) (#try.Success [[("lux i64 +" 1 offset) tape] {#basis offset @@ -156,7 +156,7 @@ {#.doc "Yields the next character (without consuming it from the input)."} (Parser Text) (function (_ (^@ input [offset tape])) - (case (/.nth offset tape) + (case (/.char offset tape) (#.Some output) (#try.Success [input (/.of_char output)]) @@ -174,7 +174,7 @@ (-> Nat Nat (Parser Text)) (do //.monad [char any - #let [char' (maybe.assume (/.nth 0 char))] + #let [char' (maybe.assume (/.char 0 char))] _ (//.assertion ($_ /\compose "Character is not within range: " (/.of_char bottom) "-" (/.of_char top)) (.and (n.>= bottom char') (n.<= top char')))] @@ -225,7 +225,7 @@ {#.doc (code.text ($_ /\compose "Yields characters that are" <description_modifier> " part of a piece of text."))} (-> Text (Parser Text)) (function (_ [offset tape]) - (case (/.nth offset tape) + (case (/.char offset tape) (#.Some output) (let [output' (/.of_char output)] (if (<modifier> (/.contains? output' options)) @@ -244,7 +244,7 @@ {#.doc (code.text ($_ /\compose "Yields characters (as a slice) that are" <description_modifier> " part of a piece of text."))} (-> Text (Parser Slice)) (function (_ [offset tape]) - (case (/.nth offset tape) + (case (/.char offset tape) (#.Some output) (let [output' (/.of_char output)] (if (<modifier> (/.contains? output' options)) @@ -268,7 +268,7 @@ {#.doc "Yields characters that satisfy a predicate."} (-> (-> Char Bit) (Parser Text)) (function (_ [offset tape]) - (case (/.nth offset tape) + (case (/.char offset tape) (#.Some output) (if (parser output) (#try.Success [[("lux i64 +" 1 offset) tape] (/.of_char output)]) diff --git a/stdlib/source/library/lux/control/parser/type.lux b/stdlib/source/library/lux/control/parser/type.lux index 7933f3a90..9c4dae7ee 100644 --- a/stdlib/source/library/lux/control/parser/type.lux +++ b/stdlib/source/library/lux/control/parser/type.lux @@ -169,7 +169,7 @@ (let [members (<flattener> (type.anonymous headT))] (if (n.> 1 (list.size members)) (local members poly) - (//.failure (exception.construct <exception> headT)))))))] + (//.failure (exception.error <exception> headT)))))))] [variant type.flat_variant #.Sum ..not_variant] [tuple type.flat_tuple #.Product ..not_tuple] @@ -181,7 +181,7 @@ [headT any #let [[num_arg bodyT] (type.flat_univ_q (type.anonymous headT))]] (if (n.= 0 num_arg) - (//.failure (exception.construct ..not_polymorphic headT)) + (//.failure (exception.error ..not_polymorphic headT)) (in [num_arg bodyT])))) (def: #export (polymorphic poly) @@ -230,7 +230,7 @@ (if (n.> 0 (list.size inputsT)) (//.and (local inputsT in_poly) (local (list outputT) out_poly)) - (//.failure (exception.construct ..not_function headT))))) + (//.failure (exception.error ..not_function headT))))) (def: #export (applied poly) {#.doc (doc "Parses a type application.")} @@ -239,7 +239,7 @@ [headT any #let [[funcT paramsT] (type.flat_application (type.anonymous headT))]] (if (n.= 0 (list.size paramsT)) - (//.failure (exception.construct ..not_application headT)) + (//.failure (exception.error ..not_application headT)) (..local (#.Item funcT paramsT) poly)))) (template [<name> <test> <doc>] @@ -250,7 +250,7 @@ [actual any] (if (<test> expected actual) (in []) - (//.failure (exception.construct ..types_do_not_match [expected actual])))))] + (//.failure (exception.error ..types_do_not_match [expected actual])))))] [exactly type\= "Parses a type exactly."] @@ -279,10 +279,10 @@ (in poly_code) #.None - (//.failure (exception.construct ..unknown_parameter headT))) + (//.failure (exception.error ..unknown_parameter headT))) _ - (//.failure (exception.construct ..not_parameter headT))))) + (//.failure (exception.error ..not_parameter headT))))) (def: #export (parameter! id) (-> Nat (Parser Any)) @@ -293,10 +293,10 @@ (#.Parameter idx) (if (n.= id (adjusted_idx env idx)) (in []) - (//.failure (exception.construct ..wrong_parameter [(#.Parameter id) headT]))) + (//.failure (exception.error ..wrong_parameter [(#.Parameter id) headT]))) _ - (//.failure (exception.construct ..not_parameter headT))))) + (//.failure (exception.error ..not_parameter headT))))) (def: #export existential {#.doc (doc "Yields an existential type.")} @@ -308,7 +308,7 @@ (in ex_id) _ - (//.failure (exception.construct ..not_existential headT))))) + (//.failure (exception.error ..not_existential headT))))) (def: #export named {#.doc (doc "Yields a named type.")} @@ -320,7 +320,7 @@ (in [name anonymousT]) _ - (//.failure (exception.construct ..not_named inputT))))) + (//.failure (exception.error ..not_named inputT))))) (`` (template: (|nothing|) (#.Named [(~~ (static .prelude_module)) "Nothing"] @@ -341,7 +341,7 @@ (in [recT output])) _ - (//.failure (exception.construct ..not_recursive headT))))) + (//.failure (exception.error ..not_recursive headT))))) (def: #export recursive_self (Parser Code) @@ -355,7 +355,7 @@ (in self_call) _ - (//.failure (exception.construct ..not_recursive headT))))) + (//.failure (exception.error ..not_recursive headT))))) (def: #export recursive_call (Parser Code) diff --git a/stdlib/source/library/lux/control/parser/xml.lux b/stdlib/source/library/lux/control/parser/xml.lux index 4af88b9b3..91fd7e67c 100644 --- a/stdlib/source/library/lux/control/parser/xml.lux +++ b/stdlib/source/library/lux/control/parser/xml.lux @@ -32,11 +32,11 @@ (exception: #export (unknown_attribute {expected Attribute} {available (List Attribute)}) (exception.report ["Expected" (%.text (/.attribute expected))] - ["Available" (exception.enumerate (|>> /.attribute %.text) available)])) + ["Available" (exception.listing (|>> /.attribute %.text) available)])) (exception: #export (unconsumed_inputs {inputs (List XML)}) (exception.report - ["Inputs" (exception.enumerate (\ /.codec encode) inputs)])) + ["Inputs" (exception.listing (\ /.codec encode) inputs)])) (def: (run' parser attrs documents) (All [a] (-> (Parser a) Attrs (List XML) (Try a))) diff --git a/stdlib/source/library/lux/control/region.lux b/stdlib/source/library/lux/control/region.lux index a7cda544b..6911ef015 100644 --- a/stdlib/source/library/lux/control/region.lux +++ b/stdlib/source/library/lux/control/region.lux @@ -152,7 +152,7 @@ (All [! e a] (-> (Monad !) (Exception e) e (All [r] (Region r ! a)))) - (failure monad (exception.construct exception message))) + (failure monad (exception.error exception message))) (def: #export (lift monad operation) {#.doc (doc "Lift an effectful computation into a region-based computation.")} diff --git a/stdlib/source/library/lux/control/remember.lux b/stdlib/source/library/lux/control/remember.lux index 659c1cc39..48a7e8abf 100644 --- a/stdlib/source/library/lux/control/remember.lux +++ b/stdlib/source/library/lux/control/remember.lux @@ -64,7 +64,7 @@ #.None (list))) - (meta.failure (exception.construct ..must_remember [deadline today message focus]))))) + (meta.failure (exception.error ..must_remember [deadline today message focus]))))) (template [<name> <message>] [(`` (syntax: #export (<name> {deadline ..deadline} {message <c>.text} {focus (<>.maybe <c>.any)}) diff --git a/stdlib/source/library/lux/data/collection/array.lux b/stdlib/source/library/lux/data/collection/array.lux index 9c07bef65..e823c4212 100644 --- a/stdlib/source/library/lux/data/collection/array.lux +++ b/stdlib/source/library/lux/data/collection/array.lux @@ -293,8 +293,11 @@ (All [a] (-> (Array a) (List a))) (loop [idx (dec (size array)) output #.End] - (if (n.= ..underflow idx) + (case idx + (^ (static ..underflow)) output + + _ (recur (dec idx) (case (read idx array) (#.Some head) @@ -308,8 +311,11 @@ (All [a] (-> a (Array a) (List a))) (loop [idx (dec (size array)) output #.End] - (if (n.= ..underflow idx) + (case idx + (^ (static ..underflow)) output + + _ (recur (dec idx) (#.Item (maybe.else default (read idx array)) output))))) diff --git a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux index ffe34dc92..3b4e7a17c 100644 --- a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux +++ b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux @@ -151,7 +151,7 @@ [reddened #Black #Red (error! error_message)] ) -(def: (add_left addition center) +(def: (with_left addition center) (All [k v] (-> (Node k v) (Node k v) (Node k v))) (case (get@ #color center) #Red @@ -200,7 +200,7 @@ #Black <default_behavior>)))) -(def: (add_right addition center) +(def: (with_right addition center) (All [k v] (-> (Node k v) (Node k v) (Node k v))) (case (get@ #color center) #Red @@ -268,8 +268,8 @@ (#.Some (<add> (maybe.assume outcome) root))))] - [_\< #left add_left] - [(order.> (get@ #&order dict)) #right add_right] + [_\< #left ..with_left] + [(order.> (get@ #&order dict)) #right ..with_right] )) ## (_\= reference key) @@ -334,7 +334,7 @@ _ (black key value ?left ?right))) -(def: (balance_left_remove key value ?left ?right) +(def: (without_left key value ?left ?right) (All [k v] (-> k v (Maybe (Node k v)) (Maybe (Node k v)) (Node k v))) (case ?left (^multi (#.Some left) @@ -363,7 +363,7 @@ (error! error_message)) )) -(def: (balance_right_remove key value ?left ?right) +(def: (without_right key value ?left ?right) (All [k v] (-> k v (Maybe (Node k v)) (Maybe (Node k v)) (Node k v))) (case ?right (^multi (#.Some right) @@ -459,13 +459,13 @@ (get@ #right right))))) #Black - (in (balance_left_remove (get@ #key left) - (get@ #value left) - (get@ #left left) - (#.Some (black (get@ #key right) - (get@ #value right) - (#.Some fused) - (get@ #right right))))) + (in (without_left (get@ #key left) + (get@ #value left) + (get@ #left left) + (#.Some (black (get@ #key right) + (get@ #value right) + (#.Some fused) + (get@ #right right))))) )) ) @@ -499,7 +499,7 @@ (case (get@ #left root) (^multi (#.Some left) {(get@ #color left) #Black}) - [(#.Some (balance_left_remove root_key root_val side_outcome (get@ #right root))) + [(#.Some (without_left root_key root_val side_outcome (get@ #right root))) #0] _ @@ -508,7 +508,7 @@ (case (get@ #right root) (^multi (#.Some right) {(get@ #color right) #Black}) - [(#.Some (balance_right_remove root_key root_val (get@ #left root) side_outcome)) + [(#.Some (without_right root_key root_val (get@ #left root) side_outcome)) #0] _ diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index df4b33c2e..5b20c22fb 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -172,23 +172,23 @@ (#.Item x (repeat (dec n) x)) #.End)) -(def: (iterate' f x) +(def: (iterations' f x) (All [a] (-> (-> a (Maybe a)) a (List a))) (case (f x) (#.Some x') - (#.Item x (iterate' f x')) + (#.Item x (iterations' f x')) #.None (list))) -(def: #export (iterate f x) +(def: #export (iterations f x) {#.doc "Generates a list element by element until the function returns #.None."} (All [a] (-> (-> a (Maybe a)) a (List a))) (case (f x) (#.Some x') - (#.Item x (iterate' f x')) + (#.Item x (iterations' f x')) #.None (list x))) @@ -283,7 +283,7 @@ [any? #0 or] ) -(def: #export (nth i xs) +(def: #export (item i xs) {#.doc "Fetches the element at the specified index."} (All [a] (-> Nat (List a) (Maybe a))) @@ -294,7 +294,7 @@ (#.Item x xs') (if (n.= 0 i) (#.Some x) - (nth (dec i) xs')))) + (item (dec i) xs')))) (implementation: #export (equivalence Equivalence<a>) (All [a] (-> (Equivalence a) (Equivalence (List a)))) diff --git a/stdlib/source/library/lux/data/collection/row.lux b/stdlib/source/library/lux/data/collection/row.lux index 4e341dfbd..1af5037ce 100644 --- a/stdlib/source/library/lux/data/collection/row.lux +++ b/stdlib/source/library/lux/data/collection/row.lux @@ -268,7 +268,7 @@ (exception.except ..incorrect_row_structure [])))) (exception.except ..index_out_of_bounds [row idx]))) -(def: #export (nth idx row) +(def: #export (item idx row) (All [a] (-> Nat (Row a) (Try a))) (do try.monad [base (base_for idx row)] @@ -296,7 +296,7 @@ (def: #export (update idx f row) (All [a] (-> Nat (-> a a) (Row a) (Try (Row a)))) (do try.monad - [val (..nth idx row)] + [val (..item idx row)] (..put idx (f val) row))) (def: #export (pop row) diff --git a/stdlib/source/library/lux/data/collection/sequence.lux b/stdlib/source/library/lux/data/collection/sequence.lux index 4105e22e5..44755f0db 100644 --- a/stdlib/source/library/lux/data/collection/sequence.lux +++ b/stdlib/source/library/lux/data/collection/sequence.lux @@ -23,11 +23,11 @@ {#.doc "An infinite sequence of values."} (Cont [a (Sequence a)])) -(def: #export (iterate f x) +(def: #export (iterations f x) {#.doc "Create a sequence by applying a function to a value, and to its result, on and on..."} (All [a] (-> (-> a a) a (Sequence a))) - (//.pending [x (iterate f (f x))])) + (//.pending [x (iterations f (f x))])) (def: #export (repeat x) {#.doc "Repeat a value forever."} @@ -59,12 +59,12 @@ [tail (Sequence a)] ) -(def: #export (nth idx sequence) +(def: #export (item idx sequence) (All [a] (-> Nat (Sequence a) a)) (let [[head tail] (//.run sequence)] (case idx 0 head - _ (nth (dec idx) tail)))) + _ (item (dec idx) tail)))) (template [<taker> <dropper> <splitter> <pred_type> <pred_test> <pred_step>] [(def: #export (<taker> pred xs) diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux index daac4e81d..cc186e849 100644 --- a/stdlib/source/library/lux/data/format/json.lux +++ b/stdlib/source/library/lux/data/format/json.lux @@ -186,8 +186,8 @@ (and prev (maybe.else #0 (do maybe.monad - [x' (row.nth idx xs) - y' (row.nth idx ys)] + [x' (row.item idx xs) + y' (row.item idx ys)] (in (= x' y')))))) #1 (list.indices (row.size xs)))) diff --git a/stdlib/source/library/lux/data/format/tar.lux b/stdlib/source/library/lux/data/format/tar.lux index 996bb27f9..1f4f71967 100644 --- a/stdlib/source/library/lux/data/format/tar.lux +++ b/stdlib/source/library/lux/data/format/tar.lux @@ -119,10 +119,10 @@ [pre_end <binary>.bits/8 end <binary>.bits/8 _ (let [expected (`` (char (~~ (static ..blank))))] - (<>.assertion (exception.construct ..wrong_character [expected pre_end]) + (<>.assertion (exception.error ..wrong_character [expected pre_end]) (n.= expected pre_end))) _ (let [expected (`` (char (~~ (static ..null))))] - (<>.assertion (exception.construct ..wrong_character [expected end]) + (<>.assertion (exception.error ..wrong_character [expected end]) (n.= expected end)))] (in []))) @@ -144,7 +144,7 @@ digits (<>.lift (\ utf8.codec decode digits)) end <binary>.bits/8 _ (let [expected (`` (char (~~ (static ..blank))))] - (<>.assertion (exception.construct ..wrong_character [expected end]) + (<>.assertion (exception.error ..wrong_character [expected end]) (n.= expected end)))] (<>.lift (do {! try.monad} @@ -277,7 +277,7 @@ [string (<binary>.segment <size>) end <binary>.bits/8 #let [expected (`` (char (~~ (static ..null))))] - _ (<>.assertion (exception.construct ..wrong_character [expected end]) + _ (<>.assertion (exception.error ..wrong_character [expected end]) (n.= expected end))] (<>.lift (do {! try.monad} @@ -319,7 +319,7 @@ [string (<binary>.segment ..magic_size) end <binary>.bits/8 #let [expected (`` (char (~~ (static ..null))))] - _ (<>.assertion (exception.construct ..wrong_character [expected end]) + _ (<>.assertion (exception.error ..wrong_character [expected end]) (n.= expected end))] (<>.lift (\ try.monad map (|>> :abstraction) @@ -798,7 +798,7 @@ (-> Link_Flag (Parser File)) (do <>.monad [header ..header_parser - _ (<>.assertion (exception.construct ..wrong_link_flag [expected (get@ #link_flag header)]) + _ (<>.assertion (exception.error ..wrong_link_flag [expected (get@ #link_flag header)]) (is? expected (get@ #link_flag header))) #let [size (get@ #size header) rounded_size (..rounded_content_size size)] diff --git a/stdlib/source/library/lux/data/text.lux b/stdlib/source/library/lux/data/text.lux index 68ce8ec38..76ae69e33 100644 --- a/stdlib/source/library/lux/data/text.lux +++ b/stdlib/source/library/lux/data/text.lux @@ -1,6 +1,6 @@ (.module: [library - [lux #* + [lux (#- char) ["@" target] [abstract [hash (#+ Hash)] @@ -51,7 +51,7 @@ (-> Text Nat) (|>> "lux text size")) -(def: #export (nth index input) +(def: #export (char index input) {#.doc (doc "Yields the character at the specified index.")} (-> Nat Text (Maybe Char)) (if (n.< ("lux text size" input) index) @@ -314,7 +314,7 @@ {#.doc "Checks whether the character is white-space."} (-> Char Bit) (with_expansions [<options> (template [<char>] - [(^ (char (~~ (static <char>))))] + [(^ (.char (~~ (static <char>))))] [..tab] [..vertical_tab] diff --git a/stdlib/source/library/lux/data/text/escape.lux b/stdlib/source/library/lux/data/text/escape.lux index 02cb8baaa..d34c91d70 100644 --- a/stdlib/source/library/lux/data/text/escape.lux +++ b/stdlib/source/library/lux/data/text/escape.lux @@ -24,7 +24,7 @@ (template [<char> <sigil>] [(def: <char> - (|> <sigil> (//.nth 0) maybe.assume))] + (|> <sigil> (//.char 0) maybe.assume))] [sigil_char ..sigil] [\u_sigil "u"] @@ -32,7 +32,7 @@ (template [<literal> <sigil> <escaped>] [(def: <sigil> - (|> <literal> (//.nth 0) maybe.assume)) + (|> <literal> (//.char 0) maybe.assume)) (def: <escaped> (format ..sigil <literal>))] @@ -51,7 +51,7 @@ (template [<char> <text>] [(def: <char> - (|> <text> (//.nth 0) maybe.assume))] + (|> <text> (//.char 0) maybe.assume))] [\0 //.\0] [\a //.\a] diff --git a/stdlib/source/library/lux/data/text/regex.lux b/stdlib/source/library/lux/data/text/regex.lux index 45798b920..0c5d42d02 100644 --- a/stdlib/source/library/lux/data/text/regex.lux +++ b/stdlib/source/library/lux/data/text/regex.lux @@ -87,9 +87,9 @@ (def: re_range^ (Parser Code) (do {! <>.monad} - [from (|> regex_char^ (\ ! map (|>> (//.nth 0) maybe.assume))) + [from (|> regex_char^ (\ ! map (|>> (//.char 0) maybe.assume))) _ (<text>.this "-") - to (|> regex_char^ (\ ! map (|>> (//.nth 0) maybe.assume)))] + to (|> regex_char^ (\ ! map (|>> (//.char 0) maybe.assume)))] (in (` ((~! <text>.range) (~ (code.nat from)) (~ (code.nat to))))))) (def: re_char^ @@ -243,7 +243,7 @@ ($_ <>.either (do ! [[from to] (<>.and number^ (<>.after (<text>.this ",") number^)) - _ (<>.assertion (exception.construct ..incorrect_quantification [from to]) + _ (<>.assertion (exception.error ..incorrect_quantification [from to]) (n.<= to from))] (in (` ((~! join_text^) ((~! <>.between) (~ (code.nat from)) diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index 27233fb11..81202885a 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -545,11 +545,11 @@ {type_vars (List (Type Var))}) (exception.report ["Name" (%.text name)] - ["Type Variables" (exception.enumerate parser.name type_vars)])) + ["Type Variables" (exception.listing parser.name type_vars)])) (def: (assertion exception payload test) (All [e] (-> (Exception e) e Bit (Parser Any))) - (<>.assertion (exception.construct exception payload) + (<>.assertion (exception.error exception payload) test)) (def: (valid_class_name type_vars) @@ -579,7 +579,7 @@ {type_vars (List (Type Var))}) (exception.report ["Unexpected Type Variable" (%.text name)] - ["Expected Type Variables" (exception.enumerate parser.name type_vars)])) + ["Expected Type Variables" (exception.listing parser.name type_vars)])) (def: (variable^ type_vars) (-> (List (Type Var)) (Parser (Type Parameter))) @@ -1832,7 +1832,7 @@ (exception.report ["Lux Type" (%.type type)])) -(with_expansions [<failure> (as_is (meta.failure (exception.construct ..cannot_convert_to_jvm_type [type])))] +(with_expansions [<failure> (as_is (meta.failure (exception.error ..cannot_convert_to_jvm_type [type])))] (def: (lux_type->jvm_type type) (-> .Type (Meta (Type Value))) (if (lux_type\= .Any type) @@ -2058,4 +2058,4 @@ ("jvm object cast" (~ object)))))) _ - (meta.failure (exception.construct ..cannot_cast_to_non_object [type])))) + (meta.failure (exception.error ..cannot_cast_to_non_object [type])))) diff --git a/stdlib/source/library/lux/macro.lux b/stdlib/source/library/lux/macro.lux index 11509f0cc..04a9324c4 100644 --- a/stdlib/source/library/lux/macro.lux +++ b/stdlib/source/library/lux/macro.lux @@ -111,7 +111,7 @@ "A prefix can be given (or just be empty text) to better identify the code for debugging purposes.")} (-> Text (Meta Code)) (do //.monad - [id //.count] + [id //.seed] (in (|> id (\ nat.decimal encode) ($_ text\compose "__gensym__" prefix) diff --git a/stdlib/source/library/lux/macro/local.lux b/stdlib/source/library/lux/macro/local.lux index 3e37d174f..2872adb12 100644 --- a/stdlib/source/library/lux/macro/local.lux +++ b/stdlib/source/library/lux/macro/local.lux @@ -99,7 +99,7 @@ (-> (List [Name Macro]) (Meta Code)) (do meta.monad [_ (monad.map meta.monad ..push_one macros) - seed meta.count + seed meta.seed g!pop (//.gensym "pop") _ (let [g!pop (: Name ["" (//code.format g!pop)])] (..push_one [g!pop (..pop_all (list\map product.left macros) g!pop)]))] diff --git a/stdlib/source/library/lux/macro/syntax/definition.lux b/stdlib/source/library/lux/macro/syntax/definition.lux index da2adcd82..4ad19d041 100644 --- a/stdlib/source/library/lux/macro/syntax/definition.lux +++ b/stdlib/source/library/lux/macro/syntax/definition.lux @@ -26,6 +26,7 @@ ["#." check (#+ Check)]]) (type: #export Definition + {#.doc (doc "Syntax for a constant definition.")} {#name Text #value (Either Check Code) @@ -100,7 +101,7 @@ )))) (def: #export (parser compiler) - {#.doc "A reader that first macro-expands and then analyses the input Code, to ensure it's a definition."} + {#.doc "A reader that first macro-expands and then analyses the input Code, to ensure it is a definition."} (-> Lux (Parser Definition)) (do {! <>.monad} [raw <code>.any diff --git a/stdlib/source/library/lux/macro/syntax/export.lux b/stdlib/source/library/lux/macro/syntax/export.lux index d51b28bcd..f1e3c7a0f 100644 --- a/stdlib/source/library/lux/macro/syntax/export.lux +++ b/stdlib/source/library/lux/macro/syntax/export.lux @@ -1,4 +1,5 @@ (.module: + {#.doc (.doc "Syntax for marking a definition as an export.")} [library [lux #* [control diff --git a/stdlib/source/library/lux/macro/syntax/input.lux b/stdlib/source/library/lux/macro/syntax/input.lux index 9307322d9..c8630283e 100644 --- a/stdlib/source/library/lux/macro/syntax/input.lux +++ b/stdlib/source/library/lux/macro/syntax/input.lux @@ -12,6 +12,7 @@ ["." code]]]]) (type: #export Input + {#.doc (doc "The common typed-argument syntax used by many macros.")} {#binding Code #type Code}) diff --git a/stdlib/source/library/lux/math/logic/continuous.lux b/stdlib/source/library/lux/math/logic/continuous.lux index 631219671..e68527938 100644 --- a/stdlib/source/library/lux/math/logic/continuous.lux +++ b/stdlib/source/library/lux/math/logic/continuous.lux @@ -1,14 +1,18 @@ +## https://en.wikipedia.org/wiki/Many-valued_logic (.module: + {#.doc (.doc "Continuous logic using Rev values." + "Continuous logic is logic in the interval [0,1] instead of just the binary #0 and #1 options." + "Because Rev is being used, the interval is actual [0,1).")} [library [lux (#- false true or and not) [abstract [monoid (#+ Monoid)]] [math [number - ["r" rev ("#\." interval)]]]]]) + ["/" rev ("#\." interval)]]]]]) -(def: #export false Rev r\bottom) -(def: #export true Rev r\top) +(def: #export false Rev /\bottom) +(def: #export true Rev /\top) (template [<name> <chooser> <monoid> <identity>] [(def: #export <name> @@ -21,13 +25,13 @@ (def: identity <identity>) (def: compose <name>))] - [or r.max disjunction ..false] - [and r.min conjunction ..true] + [or /.max disjunction ..false] + [and /.min conjunction ..true] ) (def: #export (not input) (-> Rev Rev) - (r.- input ..true)) + (/.- input ..true)) (def: #export (implies consequent antecedent) (-> Rev Rev Rev) diff --git a/stdlib/source/library/lux/math/logic/fuzzy.lux b/stdlib/source/library/lux/math/logic/fuzzy.lux index c00f63c43..d869eb4a7 100644 --- a/stdlib/source/library/lux/math/logic/fuzzy.lux +++ b/stdlib/source/library/lux/math/logic/fuzzy.lux @@ -1,4 +1,6 @@ +## https://en.wikipedia.org/wiki/Fuzzy_logic (.module: + {#.doc (.doc "Fuzzy logic, implemented on top of the Rev type.")} [library [lux #* [abstract @@ -16,6 +18,7 @@ ["#" continuous]]) (type: #export (Fuzzy a) + {#.doc (doc "A fuzzy set.")} (-> a Rev)) (implementation: #export functor diff --git a/stdlib/source/library/lux/math/modular.lux b/stdlib/source/library/lux/math/modular.lux index a6ab5afc1..bc92467b1 100644 --- a/stdlib/source/library/lux/math/modular.lux +++ b/stdlib/source/library/lux/math/modular.lux @@ -75,7 +75,7 @@ (<text>.run (do <>.monad [[value _ actual] ($_ <>.and intL (<text>.this ..separator) intL) - _ (<>.assertion (exception.construct ..incorrect_modulus [expected actual]) + _ (<>.assertion (exception.error ..incorrect_modulus [expected actual]) (i.= (//.divisor expected) actual))] (in (..modular expected value)))))) diff --git a/stdlib/source/library/lux/math/number/complex.lux b/stdlib/source/library/lux/math/number/complex.lux index e927bc791..de73592f0 100644 --- a/stdlib/source/library/lux/math/number/complex.lux +++ b/stdlib/source/library/lux/math/number/complex.lux @@ -24,13 +24,14 @@ ["." int]]]]]) (type: #export Complex + {#.doc (doc "A complex number.")} {#real Frac #imaginary Frac}) (syntax: #export (complex real {?imaginary (<>.maybe <code>.any)}) {#.doc (doc "Complex literals." (complex real imaginary) - "The imaginary part can be omitted if it's 0." + "The imaginary part can be omitted if it's +0.0." (complex real))} (in (list (` {#..real (~ real) #..imaginary (~ (maybe.else (' +0.0) ?imaginary))})))) @@ -224,7 +225,7 @@ [pow' Frac ..*'] ) -(def: (copy_sign sign magnitude) +(def: (with_sign sign magnitude) (-> Frac Frac Frac) (f.* (f.signum sign) magnitude)) @@ -238,7 +239,7 @@ imaginary)} {#real (f./ (f.* +2.0 t) (f.abs imaginary)) - #imaginary (f.* t (..copy_sign imaginary +1.0))}))) + #imaginary (f.* t (..with_sign imaginary +1.0))}))) (def: (root/2-1z input) (-> Complex Complex) diff --git a/stdlib/source/library/lux/math/number/i16.lux b/stdlib/source/library/lux/math/number/i16.lux index 1fd3e6b02..569e228fd 100644 --- a/stdlib/source/library/lux/math/number/i16.lux +++ b/stdlib/source/library/lux/math/number/i16.lux @@ -13,6 +13,7 @@ (maybe.assume (i64.sub 16))) (def: #export I16 + {#.doc (doc "A 16-bit integer.")} (:by_example [size] (Sub size) ..sub diff --git a/stdlib/source/library/lux/math/number/i32.lux b/stdlib/source/library/lux/math/number/i32.lux index a0ecfabc2..33374d19a 100644 --- a/stdlib/source/library/lux/math/number/i32.lux +++ b/stdlib/source/library/lux/math/number/i32.lux @@ -9,9 +9,11 @@ [// ["." i64 (#+ Sub)]]) -(def: sub (maybe.assume (i64.sub 32))) +(def: sub + (maybe.assume (i64.sub 32))) (def: #export I32 + {#.doc (doc "A 32-bit integer.")} (:by_example [size] (Sub size) ..sub diff --git a/stdlib/source/library/lux/math/number/i64.lux b/stdlib/source/library/lux/math/number/i64.lux index a5d72f5e7..02dc98748 100644 --- a/stdlib/source/library/lux/math/number/i64.lux +++ b/stdlib/source/library/lux/math/number/i64.lux @@ -35,14 +35,18 @@ [Nat right_shifted "lux i64 right-shift" "Unsigned/logic bitwise right-shift."] ) +## https://en.wikipedia.org/wiki/Mask_(computing) (type: #export Mask + {#.doc (doc "A pattern of bits that can be imposed on I64 values.")} I64) (def: #export (bit position) + {#.doc (doc "A mask with only a specific bit set.")} (-> Nat Mask) (|> 1 .i64 (..left_shifted (n.% ..width position)))) (def: #export sign + {#.doc (doc "A mask for the sign bit of ints.")} Mask (..bit (dec ..width))) @@ -60,6 +64,7 @@ (..not ..false)) (def: #export (mask amount_of_bits) + {#.doc (doc "Mask a block of bits of the specified size.")} (-> Nat Mask) (case amount_of_bits 0 ..false @@ -84,28 +89,28 @@ (add_shift 32) (..and 127)))) -(def: #export (clear idx input) - {#.doc "Clear bit at given index."} +(def: #export (clear index input) + {#.doc "Clear bit at the given index."} (All [s] (-> Nat (I64 s) (I64 s))) - (|> idx ..bit ..not (..and input))) + (|> index ..bit ..not (..and input))) (template [<name> <op> <doc>] - [(def: #export (<name> idx input) + [(def: #export (<name> index input) {#.doc <doc>} (All [s] (-> Nat (I64 s) (I64 s))) - (|> idx ..bit (<op> input)))] + (|> index ..bit (<op> input)))] [set ..or "Set bit at given index."] [flip ..xor "Flip bit at given index."] ) -(def: #export (set? idx input) +(def: #export (set? index input) (-> Nat (I64 Any) Bit) - (|> input (:as I64) (..and (..bit idx)) (n.= 0) .not)) + (|> input (:as I64) (..and (..bit index)) (n.= 0) .not)) -(def: #export (clear? idx input) +(def: #export (clear? index input) (-> Nat (I64 Any) Bit) - (.not (..set? idx input))) + (.not (..set? index input))) (template [<name> <forward> <backward>] [(def: #export (<name> distance input) @@ -117,9 +122,10 @@ [right_rotated ..right_shifted ..left_shifted] ) -(def: #export (region size offset) +(def: #export (region offset size) + {#.doc (doc "A mask for a block of bits of the given size, starting at the given offset.")} (-> Nat Nat Mask) - (..left_shifted offset (..mask size))) + (..left_rotated offset (..mask size))) (implementation: #export equivalence (All [a] (Equivalence (I64 a))) @@ -183,6 +189,8 @@ swap/01))) (interface: #export (Sub size) + {#.doc (doc "A sub-space of I64 with a reduce amount of bits.")} + (: (Equivalence (I64 size)) &equivalence) (: Nat @@ -193,6 +201,7 @@ widen)) (def: #export (sub width) + {#.doc (doc "Given a width in the interval (0,64), yields an implementation for integers of that width.")} (Ex [size] (-> Nat (Maybe (Sub size)))) (if (.and (n.> 0 width) (n.< ..width width)) diff --git a/stdlib/source/library/lux/math/number/i8.lux b/stdlib/source/library/lux/math/number/i8.lux index 16da5b679..1f02b508b 100644 --- a/stdlib/source/library/lux/math/number/i8.lux +++ b/stdlib/source/library/lux/math/number/i8.lux @@ -13,6 +13,7 @@ (maybe.assume (i64.sub 8))) (def: #export I8 + {#.doc (doc "An 8-bit integer.")} (:by_example [size] (Sub size) ..sub diff --git a/stdlib/source/library/lux/meta.lux b/stdlib/source/library/lux/meta.lux index 924401e04..26d7d44c7 100644 --- a/stdlib/source/library/lux/meta.lux +++ b/stdlib/source/library/lux/meta.lux @@ -198,7 +198,7 @@ (macro' (get@ #.modules compiler) this_module module name))] (#try.Success [compiler macro])))))) -(def: #export count +(def: #export seed (Meta Nat) (function (_ compiler) (#try.Success [(update@ #.seed inc compiler) @@ -484,11 +484,11 @@ (|>> (get@ #.imports) (list.any? (text\= import))) ..current_module)) -(def: #export (resolve_tag tag) +(def: #export (tag tag_name) {#.doc "Given a tag, finds out what is its index, its related tag-list and its associated type."} (-> Name (Meta [Nat (List Name) Type])) (do ..monad - [#let [[module name] tag] + [#let [[module name] tag_name] =module (..module module) this_module_name ..current_module_name imported! (..imported? module)] @@ -497,11 +497,11 @@ (if (or (text\= this_module_name module) (and imported! exported?)) (in [idx tag_list type]) - (..failure ($_ text\compose "Cannot access tag: " (name\encode tag) " from module " this_module_name))) + (..failure ($_ text\compose "Cannot access tag: " (name\encode tag_name) " from module " this_module_name))) _ (..failure ($_ text\compose - "Unknown tag: " (name\encode tag) text.new_line + "Unknown tag: " (name\encode tag_name) text.new_line " Known tags: " (|> =module (get@ #.tags) (list\map (|>> product.left [module] name\encode (text.prefix text.new_line))) diff --git a/stdlib/source/library/lux/target/jvm/bytecode.lux b/stdlib/source/library/lux/target/jvm/bytecode.lux index 539408dfc..c281f119f 100644 --- a/stdlib/source/library/lux/target/jvm/bytecode.lux +++ b/stdlib/source/library/lux/target/jvm/bytecode.lux @@ -168,7 +168,7 @@ (def: #export (except exception value) (All [e] (-> (exception.Exception e) e Bytecode)) - (..failure (exception.construct exception value))) + (..failure (exception.error exception value))) (def: #export (resolve environment bytecode) (All [a] (-> Environment (Bytecode a) (Resource [Environment (Row Exception) Instruction a]))) diff --git a/stdlib/source/library/lux/target/jvm/constant/pool.lux b/stdlib/source/library/lux/target/jvm/constant/pool.lux index e2c12039e..6c85e6e61 100644 --- a/stdlib/source/library/lux/target/jvm/constant/pool.lux +++ b/stdlib/source/library/lux/target/jvm/constant/pool.lux @@ -55,7 +55,7 @@ (let [<value>' <value>] (with_expansions [<try_again> (as_is (recur (.inc idx)))] (loop [idx 0] - (case (row.nth idx pool) + (case (row.item idx pool) (#try.Success entry) (case entry [index (<tag> reference)] diff --git a/stdlib/source/library/lux/target/jvm/loader.lux b/stdlib/source/library/lux/target/jvm/loader.lux index a1f9d285b..ec7931743 100644 --- a/stdlib/source/library/lux/target/jvm/loader.lux +++ b/stdlib/source/library/lux/target/jvm/loader.lux @@ -121,10 +121,10 @@ (:assume class) (#try.Failure error) - (error! (exception.construct ..cannot_define [class_name error]))) + (error! (exception.error ..cannot_define [class_name error]))) #.None - (error! (exception.construct ..unknown [class_name]))))))))) + (error! (exception.error ..unknown [class_name]))))))))) (def: #export (store name bytecode library) (-> Text Binary Library (IO (Try Any))) diff --git a/stdlib/source/library/lux/target/php.lux b/stdlib/source/library/lux/target/php.lux index 150833a70..e80fdbecd 100644 --- a/stdlib/source/library/lux/target/php.lux +++ b/stdlib/source/library/lux/target/php.lux @@ -343,14 +343,14 @@ (..arguments inputs)) :abstraction)) - (def: #export (nth idx array) + (def: #export (item idx array) (-> Expression Expression Access) (|> (format (:representation array) "[" (:representation idx) "]") :abstraction)) (def: #export (global name) (-> Text Global) - (|> (..var "GLOBALS") (..nth (..string name)) :transmutation)) + (|> (..var "GLOBALS") (..item (..string name)) :transmutation)) (def: #export (? test then else) (-> Expression Expression Expression Computation) diff --git a/stdlib/source/library/lux/target/r.lux b/stdlib/source/library/lux/target/r.lux index 9907e7c84..20aeb8d4b 100644 --- a/stdlib/source/library/lux/target/r.lux +++ b/stdlib/source/library/lux/target/r.lux @@ -241,7 +241,7 @@ (-> Expression Expression) (..apply/1 (..var "as.integer"))) - (def: #export (nth idx list) + (def: #export (item idx list) (-> Expression Expression Expression) (..self_contained (format (:representation list) "[[" (:representation idx) "]]"))) @@ -372,7 +372,7 @@ (..self_contained (format (:representation var) " <- " (:representation value)))) - (def: #export (set_nth! idx value list) + (def: #export (set_item! idx value list) (-> Expression Expression SVar Expression) (..self_contained (format (:representation list) "[[" (:representation idx) "]] <- " (:representation value)))) diff --git a/stdlib/source/library/lux/test.lux b/stdlib/source/library/lux/test.lux index 59a5a6a12..e3007a55f 100644 --- a/stdlib/source/library/lux/test.lux +++ b/stdlib/source/library/lux/test.lux @@ -171,7 +171,7 @@ (def: #export (times amount test) (-> Nat Test Test) (case amount - 0 (..failure (exception.construct ..must_try_test_at_least_once [])) + 0 (..failure (exception.error ..must_try_test_at_least_once [])) _ (do random.monad [seed random.nat] (function (recur prng) @@ -198,7 +198,7 @@ report (: (-> (Set Name) Text) (|>> set.to_list (list.sort (\ name.order <)) - (exception.enumerate %.name))) + (exception.listing %.name))) expected_definitions_to_cover (set.size (get@ #expected_coverage tally)) unexpected_definitions_covered (set.size unexpected) actual_definitions_covered (n.- unexpected_definitions_covered @@ -390,7 +390,7 @@ output (#try.Failure error) - (..assertion (exception.construct ..error_during_execution [error]) false)) + (..assertion (exception.error ..error_during_execution [error]) false)) io.io async.future async\join)) diff --git a/stdlib/source/library/lux/tool/compiler/default/init.lux b/stdlib/source/library/lux/tool/compiler/default/init.lux index 1a8617f53..ecd883cfe 100644 --- a/stdlib/source/library/lux/tool/compiler/default/init.lux +++ b/stdlib/source/library/lux/tool/compiler/default/init.lux @@ -186,7 +186,7 @@ post_payload (..get_current_payload pre_payoad)] (in [requirements post_payload]))) -(def: (iteration archive expander reader source pre_payload) +(def: (iteration' archive expander reader source pre_payload) (All [directive] (-> Archive Expander Reader Source (Payload directive) (All [anchor expression] @@ -198,7 +198,7 @@ [requirements post_payload] (process_directive archive expander pre_payload code)] (in [source requirements post_payload]))) -(def: (iterate archive expander module source pre_payload aliases) +(def: (iteration archive expander module source pre_payload aliases) (All [directive] (-> Archive Expander Module Source (Payload directive) Aliases (All [anchor expression] @@ -208,7 +208,7 @@ [reader (///directive.lift_analysis (..reader module aliases source))] (function (_ state) - (case (///phase.run' state (..iteration archive expander reader source pre_payload)) + (case (///phase.run' state (..iteration' archive expander reader source pre_payload)) (#try.Success [state source&requirements&buffer]) (#try.Success [state (#.Some source&requirements&buffer)]) @@ -243,7 +243,7 @@ (..begin dependencies hash input)) #let [module (get@ #///.module input)]] (loop [iteration (<| (///phase.run' state) - (..iterate archive expander module source buffer ///syntax.no_aliases))] + (..iteration archive expander module source buffer ///syntax.no_aliases))] (do ! [[state ?source&requirements&temporary_payload] iteration] (case ?source&requirements&temporary_payload @@ -284,5 +284,5 @@ (get@ #///directive.referrals) (monad.map ! (execute! archive))) temporary_payload (..get_current_payload temporary_payload)] - (..iterate archive expander module source temporary_payload (..module_aliases analysis_module))))))})])) + (..iteration archive expander module source temporary_payload (..module_aliases analysis_module))))))})])) )))))})))) diff --git a/stdlib/source/library/lux/tool/compiler/default/platform.lux b/stdlib/source/library/lux/tool/compiler/default/platform.lux index 1848c28bc..8a3f17237 100644 --- a/stdlib/source/library/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/library/lux/tool/compiler/default/platform.lux @@ -8,7 +8,7 @@ ["." monad (#+ Monad do)]] [control ["." function] - ["." try (#+ Try) ("#\." functor)] + ["." try (#+ Try) ("#\." monad)] ["." exception (#+ exception:)] [concurrency ["." async (#+ Async Resolver) ("#\." monad)] @@ -366,6 +366,12 @@ ["Importer" (%.text importer)] ["importee" (%.text importee)])) + (exception: #export (cannot_import_twice {importer Module} + {duplicates (Set Module)}) + (exception.report + ["Importer" (%.text importer)] + ["Duplicates" (%.list %.text (set.to_list duplicates))])) + (def: (verify_dependencies importer importee dependence) (-> Module Module Dependence (Try Any)) (cond (text\= importer importee) @@ -541,20 +547,34 @@ module)] (loop [[archive state] [archive state] compilation (base_compiler (:as ///.Input input)) - all_dependencies (: (List Module) - (list))] - (let [new_dependencies (get@ #///.dependencies compilation) - all_dependencies (list\compose new_dependencies all_dependencies) - continue! (:sharing [<type_vars>] - <Platform> - platform - - (-> <Context> (///.Compilation <State+> .Module Any) (List Module) - (Action [Archive <State+>])) - (:assume - recur))] - (do ! - [[archive state] (case new_dependencies + all_dependencies (: (Set Module) + (set.of_list text.hash (list)))] + (do ! + [#let [new_dependencies (get@ #///.dependencies compilation) + continue! (:sharing [<type_vars>] + <Platform> + platform + + (-> <Context> (///.Compilation <State+> .Module Any) (Set Module) + (Action [Archive <State+>])) + (:assume recur)) + ## TODO: Come up with a less hacky way to prevent duplicate imports. + ## This currently assumes that all imports will be specified once in a single .module: form. + ## This might not be the case in the future. + [all_dependencies duplicates _] (: [(Set Module) (Set Module) Bit] + (list\fold (function (_ new [all duplicates seen_prelude?]) + (if (set.member? all new) + (if (text\= .prelude_module new) + (if seen_prelude? + [all (set.add new duplicates) seen_prelude?] + [all duplicates true]) + [all (set.add new duplicates) seen_prelude?]) + [(set.add new all) duplicates seen_prelude?])) + (: [(Set Module) (Set Module) Bit] + [all_dependencies ..empty (set.empty? all_dependencies)]) + new_dependencies))] + [archive state] (if (set.empty? duplicates) + (case new_dependencies #.End (in [archive state]) @@ -567,36 +587,37 @@ (list\map product.left) (list\fold archive.merged archive))]] (in [archive (try.assumed - (..updated_state archive state))])))] - (case ((get@ #///.process compilation) - ## TODO: The "///directive.set_current_module" below shouldn't be necessary. Remove it ASAP. - ## TODO: The context shouldn't need to be re-set either. - (|> (///directive.set_current_module module) - (///phase.run' state) - try.assumed - product.left) - archive) - (#try.Success [state more|done]) - (case more|done - (#.Left more) - (continue! [archive state] more all_dependencies) - - (#.Right [descriptor document output]) - (do ! - [#let [_ (debug.log! (..module_compilation_log module state)) - descriptor (set@ #descriptor.references (set.of_list text.hash all_dependencies) descriptor)] - _ (..cache_module static platform module_id [descriptor document output])] - (case (archive.add module [descriptor document output] archive) - (#try.Success archive) - (in [archive - (..with_reset_log state)]) - - (#try.Failure error) - (async\in (#try.Failure error))))) - - (#try.Failure error) + (..updated_state archive state))]))) + (async\in (exception.except ..cannot_import_twice [module duplicates])))] + (case ((get@ #///.process compilation) + ## TODO: The "///directive.set_current_module" below shouldn't be necessary. Remove it ASAP. + ## TODO: The context shouldn't need to be re-set either. + (|> (///directive.set_current_module module) + (///phase.run' state) + try.assumed + product.left) + archive) + (#try.Success [state more|done]) + (case more|done + (#.Left more) + (continue! [archive state] more all_dependencies) + + (#.Right [descriptor document output]) (do ! - [_ (ioW.freeze (get@ #&file_system platform) static archive)] - (async\in (#try.Failure error))))))))))] + [#let [_ (debug.log! (..module_compilation_log module state)) + descriptor (set@ #descriptor.references all_dependencies descriptor)] + _ (..cache_module static platform module_id [descriptor document output])] + (case (archive.add module [descriptor document output] archive) + (#try.Success archive) + (in [archive + (..with_reset_log state)]) + + (#try.Failure error) + (async\in (#try.Failure error))))) + + (#try.Failure error) + (do ! + [_ (ioW.freeze (get@ #&file_system platform) static archive)] + (async\in (#try.Failure error)))))))))] (compiler archive.runtime_module compilation_module))) ))) 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 02100305d..7dc985749 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux @@ -471,7 +471,7 @@ (def: #export (except exception parameters) (All [e] (-> (Exception e) e Operation)) - (..failure (exception.construct exception parameters))) + (..failure (exception.error exception parameters))) (def: #export (assertion exception parameters condition) (All [e] (-> (Exception e) e Bit (Operation Any))) @@ -486,7 +486,7 @@ (def: #export (except' exception parameters) (All [e] (-> (Exception e) e (phase.Operation Lux))) - (..failure' (exception.construct exception parameters))) + (..failure' (exception.error exception parameters))) (def: #export (with_stack exception message action) (All [e o] (-> (Exception e) e (Operation o) (Operation o))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/macro.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/macro.lux index ecc765794..95f38c760 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/macro.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/macro.lux @@ -16,14 +16,14 @@ (exception: #export (expansion_failed {macro Name} {inputs (List Code)} {error Text}) (exception.report ["Macro" (%.name macro)] - ["Inputs" (exception.enumerate %.code inputs)] + ["Inputs" (exception.listing %.code inputs)] ["Error" error])) (exception: #export (must_have_single_expansion {macro Name} {inputs (List Code)} {outputs (List Code)}) (exception.report ["Macro" (%.name macro)] - ["Inputs" (exception.enumerate %.code inputs)] - ["Outputs" (exception.enumerate %.code outputs)])) + ["Inputs" (exception.listing %.code inputs)] + ["Outputs" (exception.listing %.code outputs)])) (type: #export Expander (-> Macro (List Code) Lux (Try (Try [Lux (List Code)])))) @@ -38,7 +38,7 @@ (#try.Success output) (#try.Failure error) - ((meta.failure (exception.construct ..expansion_failed [name inputs error])) state))))) + ((meta.failure (exception.error ..expansion_failed [name inputs error])) state))))) (def: #export (expand_one expander name macro inputs) (-> Expander Name Macro (List Code) (Meta Code)) @@ -49,4 +49,4 @@ (in single) _ - (meta.failure (exception.construct ..must_have_single_expansion [name inputs expansion]))))) + (meta.failure (exception.error ..must_have_single_expansion [name inputs expansion]))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux b/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux index bbe6da451..856a044fb 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux @@ -258,7 +258,7 @@ (exception.report ["Definition" (name.short name)] ["Module" (name.module name)] - ["Known Definitions" (exception.enumerate function.identity known_definitions)])) + ["Known Definitions" (exception.listing function.identity known_definitions)])) (def: #export (remember archive name) (All [anchor expression directive] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux index c7b843385..fe7de804f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux @@ -255,7 +255,7 @@ size_sum (list.size flat_sum) num_cases (maybe.else size_sum num_tags) idx (/.tag lefts right?)] - (.case (list.nth idx flat_sum) + (.case (list.item idx flat_sum) (^multi (#.Some caseT) (n.< num_cases idx)) (do ///.monad @@ -288,7 +288,7 @@ (/.with_location location (do ///.monad [tag (///extension.lift (meta.normal tag)) - [idx group variantT] (///extension.lift (meta.resolve_tag tag)) + [idx group variantT] (///extension.lift (meta.tag tag)) _ (//type.with_env (check.check inputT variantT)) #let [[lefts right?] (/.choice (list.size group) idx)]] 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 7799be183..a0d02badc 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 @@ -1,12 +1,12 @@ (.module: [library - [lux #* + [lux (#- Variant) [abstract equivalence ["." monad (#+ do)]] [control ["." try (#+ Try) ("#\." monad)] - ["ex" exception (#+ exception:)]] + ["." exception (#+ exception:)]] [data ["." bit ("#\." equivalence)] ["." maybe] @@ -166,8 +166,9 @@ ## Because of that, the presence of redundant patterns is assumed to ## be a bug, likely due to programmer carelessness. (exception: #export (redundant_pattern {so_far Coverage} {addition Coverage}) - (ex.report ["Coverage so-far" (%coverage so_far)] - ["Coverage addition" (%coverage addition)])) + (exception.report + ["Coverage so-far" (%coverage so_far)] + ["Coverage addition" (%coverage addition)])) (def: (flat_alt coverage) (-> Coverage (List Coverage)) @@ -210,8 +211,9 @@ (open: "coverage/." ..equivalence) (exception: #export (variants_do_not_match {addition_cases Nat} {so_far_cases Nat}) - (ex.report ["So-far Cases" (%.nat so_far_cases)] - ["Addition Cases" (%.nat addition_cases)])) + (exception.report + ["So-far Cases" (%.nat so_far_cases)] + ["Addition Cases" (%.nat addition_cases)])) ## After determining the coverage of each individual pattern, it is ## necessary to merge them all to figure out if the entire @@ -234,10 +236,10 @@ (cond (and (known_cases? addition_cases) (known_cases? so_far_cases) (not (n.= addition_cases so_far_cases))) - (ex.except ..variants_do_not_match [addition_cases so_far_cases]) + (exception.except ..variants_do_not_match [addition_cases so_far_cases]) (\ (dictionary.equivalence ..equivalence) = casesSF casesA) - (ex.except ..redundant_pattern [so_far addition]) + (exception.except ..redundant_pattern [so_far addition]) ## else (do {! try.monad} @@ -291,11 +293,11 @@ ## There is nothing the addition adds to the coverage. [#1 #1] - (ex.except ..redundant_pattern [so_far addition])) + (exception.except ..redundant_pattern [so_far addition])) ## The addition cannot possibly improve the coverage. [_ #Exhaustive] - (ex.except ..redundant_pattern [so_far addition]) + (exception.except ..redundant_pattern [so_far addition]) ## The addition completes the coverage. [#Exhaustive _] @@ -304,7 +306,7 @@ ## The left part will always match, so the addition is redundant. (^multi [(#Seq left right) single] (coverage/= left single)) - (ex.except ..redundant_pattern [so_far addition]) + (exception.except ..redundant_pattern [so_far addition]) ## The right part is not necessary, since it can always match the left. (^multi [single (#Seq left right)] @@ -368,6 +370,6 @@ _ (if (coverage/= so_far addition) ## The addition cannot possibly improve the coverage. - (ex.except ..redundant_pattern [so_far addition]) + (exception.except ..redundant_pattern [so_far addition]) ## There are now 2 alternative paths. (try\in (#Alt so_far addition))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux index 7fb985f4b..d50f72630 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux @@ -58,7 +58,7 @@ (recur value) #.None - (/.failure (ex.construct cannot_analyse [expectedT function_name arg_name body]))) + (/.failure (ex.error cannot_analyse [expectedT function_name arg_name body]))) (^template [<tag> <instancer>] [(<tag> _) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux index 05a147c3d..8daf5242f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux @@ -37,7 +37,7 @@ (exception: #export (cannot_infer {type Type} {args (List Code)}) (exception.report ["Type" (%.type type)] - ["Arguments" (exception.enumerate %.code args)])) + ["Arguments" (exception.listing %.code args)])) (exception: #export (cannot_infer_argument {inferred Type} {argument Code}) (exception.report @@ -264,7 +264,7 @@ (cond (or (n.= expected_size actual_size) (and (n.> expected_size actual_size) (n.< boundary tag))) - (case (list.nth tag cases) + (case (list.item tag cases) (#.Some caseT) (///\in (if (n.= 0 depth) (type.function (list caseT) currentT) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux index 0af3736ac..b0d9920df 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/module.lux @@ -67,7 +67,7 @@ ["Old annotations" (%.code old)] ["New annotations" (%.code new)])) -(def: #export (new hash) +(def: #export (empty hash) (-> Nat Module) {#.module_hash hash #.module_aliases (list) @@ -158,7 +158,7 @@ (///extension.lift (function (_ state) (#try.Success [(update@ #.modules - (plist.put name (new hash)) + (plist.put name (..empty hash)) state) []])))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux index 4ecca3d1a..1a787efec 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux @@ -102,7 +102,7 @@ (case expectedT (#.Sum _) (let [flat (type.flat_variant expectedT)] - (case (list.nth tag flat) + (case (list.item tag flat) (#.Some variant_type) (do ! [valueA (//type.with_type variant_type @@ -263,7 +263,7 @@ (-> Phase Name Phase) (do {! ///.monad} [tag (///extension.lift (meta.normal tag)) - [idx group variantT] (///extension.lift (meta.resolve_tag tag)) + [idx group variantT] (///extension.lift (meta.tag tag)) #let [case_size (list.size group) [lefts right?] (/.choice case_size idx)] expectedT (///extension.lift meta.expected_type)] @@ -308,7 +308,7 @@ (#.Item [head_k head_v] _) (do {! ///.monad} [head_k (///extension.lift (meta.normal head_k)) - [_ tag_set recordT] (///extension.lift (meta.resolve_tag head_k)) + [_ tag_set recordT] (///extension.lift (meta.tag head_k)) #let [size_record (list.size record) size_ts (list.size tag_set)] _ (if (n.= size_ts size_record) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux index aa78e8ade..60f625250 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux @@ -73,7 +73,7 @@ (exception: #export [a] (invalid_syntax {name Name} {%format (Format a)} {inputs (List a)}) (exception.report ["Extension" (%.text name)] - ["Inputs" (exception.enumerate %format inputs)])) + ["Inputs" (exception.listing %format inputs)])) (exception: #export [s i o] (unknown {name Name} {bundle (Bundle s i o)}) (exception.report @@ -81,7 +81,7 @@ ["Available" (|> bundle dictionary.keys (list.sort text\<) - (exception.enumerate %.text))])) + (exception.listing %.text))])) (type: #export (Extender s i o) (-> Any (Handler s i o))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux index 0a60511ab..8d38f4754 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux @@ -230,8 +230,8 @@ (exception.report ["Class" class] ["Method" method] - ["Arguments" (exception.enumerate ..signature inputsJT)] - ["Hints" (exception.enumerate %.type (list\map product.left hints))]))] + ["Arguments" (exception.listing ..signature inputsJT)] + ["Hints" (exception.listing %.type (list\map product.left hints))]))] [no_candidates] [too_many_candidates] @@ -1589,7 +1589,7 @@ (template [<name>] [(exception: #export (<name> {methods (List [Text (Type Method)])}) (exception.report - ["Methods" (exception.enumerate + ["Methods" (exception.listing (function (_ [name type]) (format (%.text name) " " (..signature type))) methods)]))] @@ -1889,7 +1889,7 @@ (exception: #export (unknown_super {name Text} {supers (List (Type Class))}) (exception.report ["Name" (%.text name)] - ["Available" (exception.enumerate (|>> jvm_parser.read_class product.left) supers)])) + ["Available" (exception.listing (|>> jvm_parser.read_class product.left) supers)])) (exception: #export (mismatched_super_parameters {name Text} {expected Nat} {actual Nat}) (exception.report @@ -2052,9 +2052,9 @@ {actual (List (Type Parameter))}) (exception.report ["Expected (amount)" (%.nat (list.size expected))] - ["Expected (parameters)" (exception.enumerate %.text expected)] + ["Expected (parameters)" (exception.listing %.text expected)] ["Actual (amount)" (%.nat (list.size actual))] - ["Actual (parameters)" (exception.enumerate ..signature actual)])) + ["Actual (parameters)" (exception.listing ..signature actual)])) (def: (super_aliasing class_loader class) (-> java/lang/ClassLoader (Type Class) (Operation Aliasing)) @@ -2141,7 +2141,7 @@ super_interfaces)) selfT (///.lift (do meta.monad [where meta.current_module_name - id meta.count] + id meta.seed] (in (inheritance_relationship_type (#.Primitive (..anonymous_class_name where id) (list)) super_classT super_interfaceT+)))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lux.lux index 906b54e23..470078b0f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lux.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lux.lux @@ -90,8 +90,8 @@ (do <>.monad [raw <code>.text] (case (text.size raw) - 1 (in (|> raw (text.nth 0) maybe.assume)) - _ (<>.failure (exception.construct ..char_text_must_be_size_1 [raw]))))) + 1 (in (|> raw (text.char 0) maybe.assume)) + _ (<>.failure (exception.error ..char_text_must_be_size_1 [raw]))))) (def: lux::syntax_char_case! (..custom @@ -164,9 +164,9 @@ (case args (^ (list typeC valueC)) (do {! ////.monad} - [count (///.lift meta.count) + [seed (///.lift meta.seed) actualT (\ ! map (|>> (:as Type)) - (eval archive count Type typeC)) + (eval archive seed Type typeC)) _ (typeA.infer actualT)] (typeA.with_type actualT (analyse archive valueC))) @@ -180,9 +180,9 @@ (case args (^ (list typeC valueC)) (do {! ////.monad} - [count (///.lift meta.count) + [seed (///.lift meta.seed) actualT (\ ! map (|>> (:as Type)) - (eval archive count Type typeC)) + (eval archive seed Type typeC)) _ (typeA.infer actualT) [valueT valueA] (typeA.with_inference (analyse archive valueC))] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux index 2c78f5988..8f61e7ea8 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux @@ -345,7 +345,7 @@ (in elementJT) #.None - (<>.failure (exception.construct ..not_an_object_array arrayJT))) + (<>.failure (exception.error ..not_an_object_array arrayJT))) #.None (undefined)))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux index a66a198c7..b728760c0 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux @@ -43,7 +43,7 @@ (def: (array::read [indexG arrayG]) (Binary Expression) - (_.nth (_.+ (_.int +1) indexG) arrayG)) + (_.item (_.+ (_.int +1) indexG) arrayG)) (def: (array::write [indexG valueG arrayG]) (Trinary Expression) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux index 39ddd3df9..f7a42c5d2 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux @@ -39,7 +39,7 @@ (def: (array::read [indexG arrayG]) (Binary Expression) - (_.nth indexG arrayG)) + (_.item indexG arrayG)) (def: (array::write [indexG valueG arrayG]) (Trinary Expression) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux index 56393387f..57e53f579 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux @@ -42,7 +42,7 @@ (def: (array::read [indexG arrayG]) (Binary (Expression Any)) - (_.nth indexG arrayG)) + (_.item indexG arrayG)) (def: (array::write [indexG valueG arrayG]) (Trinary (Expression Any)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux index 9e6df81c7..cb2e4d28b 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux @@ -43,7 +43,7 @@ (def: (array::read [indexG arrayG]) (Binary Expression) - (_.nth indexG arrayG)) + (_.item indexG arrayG)) (def: (array::write [indexG valueG arrayG]) (Trinary Expression) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/runtime.lux index 6b390352b..b69836192 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/runtime.lux @@ -90,7 +90,7 @@ (syntax: #export (with_vars {vars (<code>.tuple (<>.some <code>.local_identifier))} body) (do {! meta.monad} - [ids (monad.seq ! (list.repeat (list.size vars) meta.count))] + [ids (monad.seq ! (list.repeat (list.size vars) meta.seed))] (in (list (` (let [(~+ (|> vars (list.zipped/2 ids) (list\map (function (_ [id var]) @@ -104,7 +104,7 @@ (<>.some <code>.local_identifier))))} code) (do meta.monad - [runtime_id meta.count] + [runtime_id meta.seed] (macro.with_gensyms [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.var (~ (code.text (%.code runtime)))))] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux index 5ac8a93ec..d351cd6ac 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux @@ -88,7 +88,7 @@ (syntax: #export (with_vars {vars (<code>.tuple (<>.some <code>.local_identifier))} body) (do {! meta.monad} - [ids (monad.seq ! (list.repeat (list.size vars) meta.count))] + [ids (monad.seq ! (list.repeat (list.size vars) meta.seed))] (in (list (` (let [(~+ (|> vars (list.zipped/2 ids) (list\map (function (_ [id var]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux index 0e1b681c4..6d1fda16c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux @@ -113,7 +113,7 @@ (def: peek Expression - (_.nth (_.length @cursor) @cursor)) + (_.item (_.length @cursor) @cursor)) (def: save! Statement @@ -214,7 +214,7 @@ [/////synthesis.side/right /////synthesis.simple_right_side ..right_choice]) (^ (/////synthesis.member/left 0)) - (///////phase\in (|> ..peek (_.nth (_.int +1)) ..push!)) + (///////phase\in (|> ..peek (_.item (_.int +1)) ..push!)) (^template [<pm> <getter>] [(^ (<pm> lefts)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux index 9affe12f6..28c33a86a 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux @@ -82,7 +82,7 @@ initialize! (list\fold (.function (_ post pre!) ($_ _.then pre! - (_.local/1 (..input post) (_.nth (|> post inc .int _.int) @curried)))) + (_.local/1 (..input post) (_.item (|> post inc .int _.int) @curried)))) initialize_self! (list.indices arity)) pack (|>> (list) _.array) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux index 7d92f48d3..935caf949 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux @@ -105,7 +105,7 @@ (syntax: #export (with_vars {vars (<code>.tuple (<>.some <code>.local_identifier))} body) (do {! meta.monad} - [ids (monad.seq ! (list.repeat (list.size vars) meta.count))] + [ids (monad.seq ! (list.repeat (list.size vars) meta.seed))] (in (list (` (let [(~+ (|> vars (list.zipped/2 ids) (list\map (function (_ [id var]) @@ -122,7 +122,7 @@ (<>.some <code>.local_identifier))))} code) (do meta.monad - [runtime_id meta.count] + [runtime_id meta.seed] (macro.with_gensyms [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.var (~ (code.text (%.code runtime)))))] @@ -158,16 +158,16 @@ (_.function (~ g!_) (list (~+ inputsC)) (~ code)))))))))))))))) -(def: (nth index table) +(def: (item index table) (-> Expression Expression Location) - (_.nth (_.+ (_.int +1) index) table)) + (_.item (_.+ (_.int +1) index) table)) (def: last_index (|>> _.length (_.- (_.int +1)))) (with_expansions [<recur> (as_is ($_ _.then (_.set (list lefts) (_.- last_index_right lefts)) - (_.set (list tuple) (..nth last_index_right tuple))))] + (_.set (list tuple) (..item last_index_right tuple))))] (runtime: (tuple//left lefts tuple) (with_vars [last_index_right] (<| (_.while (_.bool true)) @@ -175,7 +175,7 @@ (_.local/1 last_index_right (..last_index tuple)) (_.if (_.> lefts last_index_right) ## No need for recursion - (_.return (..nth lefts tuple)) + (_.return (..item lefts tuple)) ## Needs recursion <recur>))))) @@ -186,7 +186,7 @@ (_.local/1 last_index_right (..last_index tuple)) (_.local/1 right_index (_.+ (_.int +1) lefts)) (_.cond (list [(_.= last_index_right right_index) - (_.return (..nth right_index tuple))] + (_.return (..item right_index tuple))] [(_.> last_index_right right_index) ## Needs recursion. <recur>]) @@ -246,7 +246,7 @@ ($_ _.then (_.let (list tail) ..none) (<| (_.for_step idx (_.length raw) (_.int +1) (_.int -1)) - (_.set (list tail) (..some (_.array (list (_.nth idx raw) + (_.set (list tail) (..some (_.array (list (_.item idx raw) tail))))) (_.return tail)))) @@ -399,7 +399,7 @@ (runtime: (array//write idx value array) ($_ _.then - (_.set (list (..nth idx array)) value) + (_.set (list (..item idx array)) value) (_.return array))) (def: runtime//array diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/case.lux index 5eb23e1a9..549d19954 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/case.lux @@ -50,7 +50,7 @@ (in (|> bodyG (list (_.set (..register register) valueG)) _.array/* - (_.nth (_.int +1)))))) + (_.item (_.int +1)))))) (def: #export (let! statement expression archive [valueS register bodyS]) (Generator! [Synthesis Register Synthesis]) @@ -112,8 +112,8 @@ (def: peek Expression - (_.nth (|> @cursor _.count/1 (_.- (_.int +1))) - @cursor)) + (_.item (|> @cursor _.count/1 (_.- (_.int +1))) + @cursor)) (def: save! Statement @@ -216,7 +216,7 @@ [/////synthesis.side/right /////synthesis.simple_right_side ..right_choice]) (^ (/////synthesis.member/left 0)) - (///////phase\in (|> ..peek (_.nth (_.int +0)) ..push!)) + (///////phase\in (|> ..peek (_.item (_.int +0)) ..push!)) (^template [<pm> <getter>] [(^ (<pm> lefts)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/extension/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/extension/common.lux index 08a124e2c..f3ad84b3d 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/extension/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/extension/common.lux @@ -86,7 +86,7 @@ (bundle.install "index" (trinary text//index)) (bundle.install "size" (unary _.strlen/1)) (bundle.install "char" (binary (function (text//char [text idx]) - (|> text (_.nth idx) _.ord/1)))) + (|> text (_.item idx) _.ord/1)))) (bundle.install "clip" (trinary (function (text//clip [from to text]) (_.substr/3 [text from (_.- from to)])))) ))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/function.lux index 9f02325d3..6318a9d88 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/function.lux @@ -87,7 +87,7 @@ initialize! (list\fold (.function (_ post pre!) ($_ _.then pre! - (_.set! (..input post) (_.nth (|> post .int _.int) @curried)))) + (_.set! (..input post) (_.item (|> post .int _.int) @curried)))) initialize_self! (list.indices arity))] #let [[definition instantiation] (..with_closure closureG+ @selfG @selfL diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/loop.lux index 630e222e5..0c3c94f1f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/loop.lux @@ -118,5 +118,5 @@ (|> argsO+ list.enumeration (list\map (function (_ [idx _]) - (_.nth (_.int (.int idx)) @temp)))) + (_.item (_.int (.int idx)) @temp)))) (_.go_to @scope)))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/runtime.lux index 6c08b4ed0..a18335967 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/runtime.lux @@ -73,7 +73,7 @@ (syntax: #export (with_vars {vars (<code>.tuple (<>.some <code>.local_identifier))} body) (do {! meta.monad} - [ids (monad.seq ! (list.repeat (list.size vars) meta.count))] + [ids (monad.seq ! (list.repeat (list.size vars) meta.seed))] (in (list (` (let [(~+ (|> vars (list.zipped/2 ids) (list\map (function (_ [id var]) @@ -90,7 +90,7 @@ (<>.some <code>.local_identifier))))} code) (do meta.monad - [runtime_id meta.count] + [runtime_id meta.seed] (macro.with_gensyms [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.constant (~ (code.text (%.code runtime)))))] @@ -149,7 +149,7 @@ "_lux_size") (def: tuple_size - (_.nth (_.string ..tuple_size_field))) + (_.item (_.string ..tuple_size_field))) (def: jphp? (_.=== (_.string "5.6.99") (_.phpversion/0 []))) @@ -162,7 +162,7 @@ (runtime: (array//write idx value array) ($_ _.then - (_.set! (_.nth idx array) value) + (_.set! (_.item idx array) value) (_.return array))) (def: runtime//array @@ -180,7 +180,7 @@ (with_expansions [<recur> (as_is ($_ _.then (_.set! lefts (_.- last_index_right lefts)) - (_.set! tuple (_.nth last_index_right tuple))))] + (_.set! tuple (_.item last_index_right tuple))))] (runtime: (tuple//make size values) (_.if ..jphp? ($_ _.then @@ -202,7 +202,7 @@ (_.set! last_index_right (..normal_last_index tuple))) (_.if (_.> lefts last_index_right) ## No need for recursion - (_.return (_.nth lefts tuple)) + (_.return (_.item lefts tuple)) ## Needs recursion <recur>))))) @@ -215,7 +215,7 @@ (_.set! output (_.array/* (list))) (<| (_.while (|> index (_.+ offset) (_.< size))) ($_ _.then - (_.set! (_.nth index output) (_.nth (_.+ offset index) input)) + (_.set! (_.item index output) (_.item (_.+ offset index) input)) (_.set! index (_.+ (_.int +1) index)) )) (_.return (..tuple//make (_.- offset size) output)) @@ -230,7 +230,7 @@ (_.set! last_index_right (..normal_last_index tuple))) (_.set! right_index (_.+ (_.int +1) lefts)) (_.cond (list [(_.=== last_index_right right_index) - (_.return (_.nth right_index tuple))] + (_.return (_.item right_index tuple))] [(_.> last_index_right right_index) ## Needs recursion. <recur>]) @@ -274,12 +274,12 @@ (runtime: (sum//get sum wantsLast wantedTag) (let [no_match! (_.return _.null) - sum_tag (_.nth (_.string ..variant_tag_field) sum) - ## sum_tag (_.nth (_.int +0) sum) - sum_flag (_.nth (_.string ..variant_flag_field) sum) - ## sum_flag (_.nth (_.int +1) sum) - sum_value (_.nth (_.string ..variant_value_field) sum) - ## sum_value (_.nth (_.int +2) sum) + sum_tag (_.item (_.string ..variant_tag_field) sum) + ## sum_tag (_.item (_.int +0) sum) + sum_flag (_.item (_.string ..variant_flag_field) sum) + ## sum_flag (_.item (_.int +1) sum) + sum_value (_.item (_.string ..variant_value_field) sum) + ## sum_value (_.item (_.int +2) sum) is_last? (_.=== ..unit sum_flag) test_recursion! (_.if is_last? ## Must recurse. @@ -540,7 +540,7 @@ _.iconv/3 [(_.string "V")] _.unpack/2 - (_.nth (_.int +1))))) + (_.item (_.int +1))))) (_.throw (_.new (_.constant "Exception") (list (_.string "[Lux Error] Cannot get char from text.")))))) (def: runtime//text diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/case.lux index cdfaf74fe..fa1a42e49 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/case.lux @@ -117,7 +117,7 @@ (def: peek (Expression Any) - (_.nth (_.int -1) @cursor)) + (_.item (_.int -1) @cursor)) (def: save! (Statement Any) @@ -246,7 +246,7 @@ [/////synthesis.side/right /////synthesis.simple_right_side ..right_choice]) (^ (/////synthesis.member/left 0)) - (///////phase\in (|> ..peek (_.nth (_.int +0)) ..push!)) + (///////phase\in (|> ..peek (_.item (_.int +0)) ..push!)) (^template [<pm> <getter>] [(^ (<pm> lefts)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/function.lux index 58d814dcc..fd225dfe4 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/function.lux @@ -83,7 +83,7 @@ initialize! (list\fold (.function (_ post pre!) ($_ _.then pre! - (_.set (list (..input post)) (_.nth (|> post .int _.int) @curried)))) + (_.set (list (..input post)) (_.item (|> post .int _.int) @curried)))) initialize_self! (list.indices arity))]] (with_closure function_artifact @self environment diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/loop.lux index 830154cbd..37296dd7c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/loop.lux @@ -115,7 +115,7 @@ #let [re_binds (|> argsO+ list.enumeration (list\map (function (_ [idx _]) - (_.nth (_.int (.int idx)) @temp))))]] + (_.item (_.int (.int idx)) @temp))))]] (in ($_ _.then (_.set (list @temp) (_.list argsO+)) (..setup offset re_binds diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux index 44ea19376..b653d67b7 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux @@ -112,7 +112,7 @@ (syntax: #export (with_vars {vars (<code>.tuple (<>.some <code>.local_identifier))} body) (do {! meta.monad} - [ids (monad.seq ! (list.repeat (list.size vars) meta.count))] + [ids (monad.seq ! (list.repeat (list.size vars) meta.seed))] (in (list (` (let [(~+ (|> vars (list.zipped/2 ids) (list\map (function (_ [id var]) @@ -209,7 +209,7 @@ (with_expansions [<recur> (as_is ($_ _.then (_.set (list lefts) (_.- last_index_right lefts)) - (_.set (list tuple) (_.nth last_index_right tuple))))] + (_.set (list tuple) (_.item last_index_right tuple))))] (runtime: (tuple::left lefts tuple) (with_vars [last_index_right] (_.while (_.bool true) @@ -217,7 +217,7 @@ (_.set (list last_index_right) (..last_index tuple)) (_.if (_.> lefts last_index_right) ## No need for recursion - (_.return (_.nth lefts tuple)) + (_.return (_.item lefts tuple)) ## Needs recursion <recur>)) #.None))) @@ -229,7 +229,7 @@ (_.set (list last_index_right) (..last_index tuple)) (_.set (list right_index) (_.+ (_.int +1) lefts)) (_.cond (list [(_.= last_index_right right_index) - (_.return (_.nth right_index tuple))] + (_.return (_.item right_index tuple))] [(_.> last_index_right right_index) ## Needs recursion. <recur>]) @@ -238,9 +238,9 @@ (runtime: (sum::get sum wantsLast wantedTag) (let [no_match! (_.return _.none) - sum_tag (_.nth (_.int +0) sum) - sum_flag (_.nth (_.int +1) sum) - sum_value (_.nth (_.int +2) sum) + sum_tag (_.item (_.int +0) sum) + sum_flag (_.item (_.int +1) sum) + sum_value (_.item (_.int +2) sum) is_last? (_.= ..unit sum_flag) test_recursion! (_.if is_last? ## Must recurse. @@ -421,7 +421,7 @@ (runtime: (array::write idx value array) ($_ _.then - (_.set (list (_.nth idx array)) value) + (_.set (list (_.item idx array)) value) (_.return array))) (def: runtime::array diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/case.lux index 8ef713643..dcaf7f395 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/case.lux @@ -90,11 +90,11 @@ (def: (push! value var) (-> Expression SVar Expression) - (_.set_nth! (next var) value var)) + (_.set_item! (next var) value var)) (def: (pop! var) (-> SVar Expression) - (_.set_nth! (top var) _.null var)) + (_.set_item! (top var) _.null var)) (def: (push_cursor! value) (-> Expression Expression) @@ -107,11 +107,11 @@ (def: restore_cursor! Expression - (_.set! $cursor (_.nth (top $savepoint) $savepoint))) + (_.set! $cursor (_.item (top $savepoint) $savepoint))) (def: peek Expression - (|> $cursor (_.nth (top $cursor)))) + (|> $cursor (_.item (top $cursor)))) (def: pop_cursor! Expression @@ -190,7 +190,7 @@ [/////synthesis.side/right true inc]) (^ (/////synthesis.member/left 0)) - (///////phase\in (_.nth (_.int +1) ..peek)) + (///////phase\in (_.item (_.int +1) ..peek)) (^template [<pm> <getter>] [(^ (<pm> lefts)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/function.lux index a6497d206..850f99475 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/function.lux @@ -69,7 +69,7 @@ (def: (input_declaration register) (-> Register Expression) (_.set! (|> register inc //case.register) - (|> $curried (_.nth (|> register inc .int _.int))))) + (|> $curried (_.item (|> register inc .int _.int))))) (def: #export (function expression archive [environment arity bodyS]) (Generator (Abstraction Synthesis)) 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 0dcaf6ac8..f71070979 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 @@ -79,7 +79,7 @@ (syntax: #export (with_vars {vars (<code>.tuple (<>.some <code>.local_identifier))} body) (do {! meta.monad} - [ids (monad.seq ! (list.repeat (list.size vars) meta.count))] + [ids (monad.seq ! (list.repeat (list.size vars) meta.seed))] (in (list (` (let [(~+ (|> vars (list.zipped/2 ids) (list\map (function (_ [id var]) @@ -93,7 +93,7 @@ (<>.some <code>.local_identifier))))} code) (do meta.monad - [runtime_id meta.count] + [runtime_id meta.seed] (macro.with_gensyms [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.var (~ (code.text (%.code runtime)))))] @@ -180,14 +180,14 @@ (runtime: (i64::unsigned_low input) (with_vars [low] ($_ _.then - (_.set! low (|> input (_.nth (_.string ..i64_low_field)))) + (_.set! low (|> input (_.item (_.string ..i64_low_field)))) (_.if (|> low (_.>= (_.int +0))) low (|> low (_.+ f2^32)))))) (runtime: (i64::to_float input) (let [high (|> input - (_.nth (_.string ..i64_high_field)) + (_.item (_.string ..i64_high_field)) high_shift) low (|> input i64::unsigned_low)] @@ -227,8 +227,8 @@ [i64::max i\top] ) -(def: #export i64_high (_.nth (_.string ..i64_high_field))) -(def: #export i64_low (_.nth (_.string ..i64_low_field))) +(def: #export i64_high (_.item (_.string ..i64_high_field))) +(def: #export i64_low (_.item (_.string ..i64_low_field))) (runtime: (i64::not input) (i64::new (|> input i64_high _.bit_not) @@ -524,8 +524,8 @@ (..right value)) #.None (#.Some (_.function (list error) - (..left (_.nth (_.string "message") - error)))) + (..left (_.item (_.string "message") + error)))) #.None))) (runtime: (lux::program_args program_args) @@ -565,11 +565,11 @@ (def: (product_element product index) (-> Expression Expression Expression) - (|> product (_.nth (|> index (_.+ (_.int +1)))))) + (|> product (_.item (|> index (_.+ (_.int +1)))))) (def: (product_tail product) (-> SVar Expression) - (|> product (_.nth (_.length product)))) + (|> product (_.item (_.length product)))) (def: (updated_index min_length product) (-> Expression Expression Expression) @@ -602,9 +602,9 @@ (runtime: (sum::get sum wants_last? wanted_tag) (let [no_match _.null - sum_tag (|> sum (_.nth (_.string ..variant_tag_field))) - sum_flag (|> sum (_.nth (_.string ..variant_flag_field))) - sum_value (|> sum (_.nth (_.string ..variant_value_field))) + sum_tag (|> sum (_.item (_.string ..variant_tag_field))) + sum_flag (|> sum (_.item (_.string ..variant_flag_field))) + sum_value (|> sum (_.item (_.string ..variant_value_field))) is_last? (|> sum_flag (_.= (_.string ""))) test_recursion (_.if is_last? ## Must recurse. @@ -754,7 +754,7 @@ subject))) (list ["fixed" (_.bool #1)]) (_.var "regexpr")) - (_.nth (_.int +1)))) + (_.item (_.int +1)))) (_.if (|> idx (_.= (_.int -1))) ..none (..some (i64::of_float (|> idx (_.+ startF)))))) @@ -799,16 +799,16 @@ (with_vars [output] ($_ _.then (_.set! output (_.list (list))) - (_.set_nth! (|> size (_.+ (_.int +1))) - _.null - output) + (_.set_item! (|> size (_.+ (_.int +1))) + _.null + output) output))) (runtime: (array::get array idx) (with_vars [temp] (<| (check_index_out_of_bounds array idx) ($_ _.then - (_.set! temp (|> array (_.nth (_.+ (_.int +1) idx)))) + (_.set! temp (|> array (_.item (_.+ (_.int +1) idx)))) (_.if (|> temp (_.= _.null)) ..none (..some temp)))))) @@ -816,7 +816,7 @@ (runtime: (array::put array idx value) (<| (check_index_out_of_bounds array idx) ($_ _.then - (_.set_nth! (_.+ (_.int +1) idx) value array) + (_.set_item! (_.+ (_.int +1) idx) value array) array))) (def: runtime::array diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux index d1bbfae39..18185171c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux @@ -119,7 +119,7 @@ (def: peek Expression - (_.nth (_.int -1) @cursor)) + (_.item (_.int -1) @cursor)) (def: save! Statement @@ -287,7 +287,7 @@ [/////synthesis.side/right /////synthesis.simple_right_side ..right_choice]) (^ (/////synthesis.member/left 0)) - (///////phase\in (|> ..peek (_.nth (_.int +0)) ..push!)) + (///////phase\in (|> ..peek (_.item (_.int +0)) ..push!)) (^template [<pm> <getter>] [(^ (<pm> lefts)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux index 8c849da68..e7e831a77 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux @@ -80,7 +80,7 @@ initialize! (list\fold (.function (_ post pre!) ($_ _.then pre! - (_.set (list (..input post)) (_.nth (|> post .int _.int) @curried)))) + (_.set (list (..input post)) (_.item (|> post .int _.int) @curried)))) initialize_self! (list.indices arity)) [declaration instatiation] (with_closure closureO+ function_name diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/loop.lux index d021df198..5c255fcc9 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/loop.lux @@ -89,7 +89,7 @@ #let [re_binds (|> argsO+ list.enumeration (list\map (function (_ [idx _]) - (_.nth (_.int (.int idx)) @temp))))]] + (_.item (_.int (.int idx)) @temp))))]] (in ($_ _.then (_.set (list @temp) (_.array argsO+)) (..setup offset re_binds diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux index 1ab1ab616..989fdf220 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/runtime.lux @@ -74,7 +74,7 @@ (syntax: #export (with_vars {vars (<code>.tuple (<>.some <code>.local_identifier))} body) (do {! meta.monad} - [ids (monad.seq ! (list.repeat (list.size vars) meta.count))] + [ids (monad.seq ! (list.repeat (list.size vars) meta.seed))] (in (list (` (let [(~+ (|> vars (list.zipped/2 ids) (list\map (function (_ [id var]) @@ -91,7 +91,7 @@ (<>.some <code>.local_identifier))))} code) (do meta.monad - [runtime_id meta.count] + [runtime_id meta.seed] (macro.with_gensyms [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.local (~ (code.text (%.code runtime)))))] @@ -132,7 +132,7 @@ (with_expansions [<recur> (as_is ($_ _.then (_.set (list lefts) (_.- last_index_right lefts)) - (_.set (list tuple) (_.nth last_index_right tuple))))] + (_.set (list tuple) (_.item last_index_right tuple))))] (runtime: (tuple//left lefts tuple) (with_vars [last_index_right] (<| (_.while (_.bool true)) @@ -140,7 +140,7 @@ (_.set (list last_index_right) (..last_index tuple)) (_.if (_.> lefts last_index_right) ## No need for recursion - (_.return (_.nth lefts tuple)) + (_.return (_.item lefts tuple)) ## Needs recursion <recur>))))) @@ -151,7 +151,7 @@ (_.set (list last_index_right) (..last_index tuple)) (_.set (list right_index) (_.+ (_.int +1) lefts)) (_.cond (list [(_.= last_index_right right_index) - (_.return (_.nth right_index tuple))] + (_.return (_.item right_index tuple))] [(_.> last_index_right right_index) ## Needs recursion. <recur>]) @@ -189,9 +189,9 @@ (runtime: (sum//get sum wantsLast wantedTag) (let [no_match! (_.return _.nil) - sum_tag (_.nth (_.string ..variant_tag_field) sum) - sum_flag (_.nth (_.string ..variant_flag_field) sum) - sum_value (_.nth (_.string ..variant_value_field) sum) + sum_tag (_.item (_.string ..variant_tag_field) sum) + sum_flag (_.item (_.string ..variant_flag_field) sum) + sum_value (_.item (_.string ..variant_value_field) sum) is_last? (_.= ..unit sum_flag) test_recursion! (_.if is_last? ## Must recurse. @@ -369,7 +369,7 @@ (runtime: (array//write idx value array) ($_ _.then - (_.set (list (_.nth idx array)) value) + (_.set (list (_.item idx array)) value) (_.return array))) (def: runtime//array diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/runtime.lux index 2e5c8d495..72ec2ef27 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/runtime.lux @@ -61,7 +61,7 @@ (syntax: #export (with_vars {vars (<code>.tuple (<>.some <code>.local_identifier))} body) (do {! meta.monad} - [ids (monad.seq ! (list.repeat (list.size vars) meta.count))] + [ids (monad.seq ! (list.repeat (list.size vars) meta.seed))] (in (list (` (let [(~+ (|> vars (list.zipped/2 ids) (list\map (function (_ [id var]) @@ -75,7 +75,7 @@ (<>.some <code>.local_identifier))))} code) (do meta.monad - [runtime_id meta.count] + [runtime_id meta.seed] (macro.with_gensyms [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.var (~ (code.text (%.code runtime)))))] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux index 4dc984bae..b19403e90 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux @@ -30,7 +30,7 @@ (exception: #export (cannot_find_foreign_variable_in_environment {foreign Register} {environment (Environment Synthesis)}) (exception.report ["Foreign" (%.nat foreign)] - ["Environment" (exception.enumerate /.%synthesis environment)])) + ["Environment" (exception.listing /.%synthesis environment)])) (def: arity_arguments (-> Arity (List Synthesis)) @@ -83,7 +83,7 @@ (def: (find_foreign environment register) (-> (Environment Synthesis) Register (Operation Synthesis)) - (case (list.nth register environment) + (case (list.item register environment) (#.Some aliased) (phase\in aliased) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/loop.lux index f64693134..6e83a6a6a 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/loop.lux @@ -110,7 +110,7 @@ (^ (reference.foreign register)) (if true_loop? - (list.nth register scope_environment) + (list.item register scope_environment) (#.Some expr))) (^ (/.branch/case [input path])) 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 16b59870b..be1eead63 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/program.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/program.lux @@ -30,7 +30,7 @@ (exception: #export (cannot_find_program {modules (List Module)}) (exception.report - ["Modules" (exception.enumerate %.text modules)])) + ["Modules" (exception.listing %.text modules)])) (def: #export (context archive) (-> Archive (Try Context)) 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 d6c43e896..4c930475b 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux @@ -169,11 +169,11 @@ (template: (!failure parser where offset source_code) (#.Left [[where offset source_code] - (exception.construct ..unrecognized_input [where (%.name (name_of parser)) source_code offset])])) + (exception.error ..unrecognized_input [where (%.name (name_of parser)) source_code offset])])) (template: (!end_of_file where offset source_code current_module) (#.Left [[where offset source_code] - (exception.construct ..end_of_file current_module)])) + (exception.error ..end_of_file current_module)])) (type: (Parser a) (-> Source (Either [Source Text] [Source a]))) @@ -263,7 +263,7 @@ g!_ (#.Left [[where offset source_code] - (exception.construct ..text_cannot_contain_new_lines content)]))) + (exception.error ..text_cannot_contain_new_lines content)]))) (def: (text_parser where offset source_code) (-> Location Offset Text (Either [Source Text] [Source Code])) diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive.lux b/stdlib/source/library/lux/tool/compiler/meta/archive.lux index a45c7ad59..cd6b245ee 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive.lux @@ -45,7 +45,7 @@ {known_modules (List Module)}) (exception.report ["Module" (%.text module)] - ["Known Modules" (exception.enumerate %.text known_modules)])) + ["Known Modules" (exception.listing %.text known_modules)])) (exception: #export (cannot_replace_document {module Module} {old (Document Any)} diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive/artifact.lux b/stdlib/source/library/lux/tool/compiler/meta/archive/artifact.lux index 7feeac2a0..76266ad19 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive/artifact.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive/artifact.lux @@ -141,7 +141,7 @@ [5 #Directive <binary>.text] [6 #Custom <binary>.text]) - _ (<>.failure (exception.construct ..invalid_category [tag])))))] + _ (<>.failure (exception.error ..invalid_category [tag])))))] (|> (<binary>.row/64 category) (\ <>.monad map (row\fold (function (_ artifact registry) (product.right diff --git a/stdlib/source/library/lux/tool/compiler/meta/io/context.lux b/stdlib/source/library/lux/tool/compiler/meta/io/context.lux index 8903ab503..e049ef8b5 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/io/context.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/io/context.lux @@ -138,7 +138,7 @@ (type: #export Enumeration (Dictionary file.Path Binary)) -(def: (enumerate_context fs directory enumeration) +(def: (context_listing fs directory enumeration) (-> (file.System Async) Context Enumeration (Async (Try Enumeration))) (do {! (try.with async.monad)} [enumeration (|> directory @@ -153,17 +153,17 @@ (\ ! join))] (|> directory (\ fs sub_directories) - (\ ! map (monad.fold ! (enumerate_context fs) enumeration)) + (\ ! map (monad.fold ! (context_listing fs) enumeration)) (\ ! join)))) (def: Action (type (All [a] (Async (Try a))))) -(def: #export (enumerate fs contexts) +(def: #export (listing fs contexts) (-> (file.System Async) (List Context) (Action Enumeration)) (monad.fold (: (Monad Action) (try.with async.monad)) - (..enumerate_context fs) + (..context_listing fs) (: Enumeration (dictionary.empty text.hash)) contexts)) diff --git a/stdlib/source/library/lux/tool/compiler/phase.lux b/stdlib/source/library/lux/tool/compiler/phase.lux index ed4def938..0a0db986e 100644 --- a/stdlib/source/library/lux/tool/compiler/phase.lux +++ b/stdlib/source/library/lux/tool/compiler/phase.lux @@ -74,7 +74,7 @@ (def: #export (except exception parameters) (All [e] (-> (Exception e) e Operation)) - (..failure (ex.construct exception parameters))) + (..failure (ex.error exception parameters))) (def: #export (lift error) (All [s a] (-> (Try a) (Operation s a))) diff --git a/stdlib/source/library/lux/tool/interpreter.lux b/stdlib/source/library/lux/tool/interpreter.lux index ccd32f12a..c374d9bd1 100644 --- a/stdlib/source/library/lux/tool/interpreter.lux +++ b/stdlib/source/library/lux/tool/interpreter.lux @@ -221,6 +221,6 @@ (#try.Failure error) (if (ex.match? syntax.end_of_file error) (recur context #1) - (exec (log! (ex.construct ..error error)) + (exec (log! (ex.error ..error error)) (recur (set@ #source ..fresh_source context) #0)))))) ))) diff --git a/stdlib/source/library/lux/type.lux b/stdlib/source/library/lux/type.lux index f12adc89b..950d71c63 100644 --- a/stdlib/source/library/lux/type.lux +++ b/stdlib/source/library/lux/type.lux @@ -170,7 +170,7 @@ (n\encode index) " " (..format type)))) (text.join_with (text\compose text.new_line " "))))) - (list.nth idx env)) + (list.item idx env)) _ type diff --git a/stdlib/source/library/lux/type/check.lux b/stdlib/source/library/lux/type/check.lux index 882b723ff..dcdf4ba58 100644 --- a/stdlib/source/library/lux/type/check.lux +++ b/stdlib/source/library/lux/type/check.lux @@ -180,7 +180,7 @@ (def: #export (except exception message) (All [e a] (-> (Exception e) e (Check a))) - (..failure (exception.construct exception message))) + (..failure (exception.error exception message))) (def: #export existential {#.doc "A producer of existential types."} diff --git a/stdlib/source/library/lux/type/implicit.lux b/stdlib/source/library/lux/type/implicit.lux index 167c25c0e..80e2f1ca2 100644 --- a/stdlib/source/library/lux/type/implicit.lux +++ b/stdlib/source/library/lux/type/implicit.lux @@ -88,7 +88,7 @@ ["" simple_name] (meta.either (do meta.monad [member (meta.normal member) - _ (meta.resolve_tag member)] + _ (meta.tag member)] (in member)) (do {! meta.monad} [this_module_name meta.current_module_name @@ -114,7 +114,7 @@ (-> Name (Meta [Nat Type])) (do meta.monad [member (member_name member) - [idx tag_list sig_type] (meta.resolve_tag member)] + [idx tag_list sig_type] (meta.tag member)] (in [idx sig_type]))) (def: (available_definitions source_module target_module constants aggregate) diff --git a/stdlib/source/library/lux/type/resource.lux b/stdlib/source/library/lux/type/resource.lux index 2cda92c15..b61fb2d9f 100644 --- a/stdlib/source/library/lux/type/resource.lux +++ b/stdlib/source/library/lux/type/resource.lux @@ -119,7 +119,7 @@ (in (list)) (do ! [head <code>.nat - _ (<>.assertion (exception.construct ..index_cannot_be_repeated head) + _ (<>.assertion (exception.error ..index_cannot_be_repeated head) (not (set.member? seen head))) tail (recur (set.add head seen))] (in (list& head tail)))))))) @@ -142,7 +142,7 @@ #let [g!outputs (|> (monad.fold maybe.monad (function (_ from to) (do maybe.monad - [input (list.nth from g!inputs)] + [input (list.item from g!inputs)] (in (row.add input to)))) (: (Row Code) row.empty) swaps) @@ -163,7 +163,7 @@ (Parser Nat) (do <>.monad [raw <code>.nat - _ (<>.assertion (exception.construct ..amount_cannot_be_zero []) + _ (<>.assertion (exception.error ..amount_cannot_be_zero []) (n.> 0 raw))] (in raw))) diff --git a/stdlib/source/library/lux/world/db/sql.lux b/stdlib/source/library/lux/world/db/sql.lux index 656e079b4..4d29ad803 100644 --- a/stdlib/source/library/lux/world/db/sql.lux +++ b/stdlib/source/library/lux/world/db/sql.lux @@ -106,7 +106,7 @@ (-> Statement Text) (format (:representation action) ";")) - (def: enumerate + (def: listing (-> (List (SQL Any)) Text) (|>> (list\map (|>> :representation)) (text.join_with ", "))) @@ -133,7 +133,7 @@ (def: #export (call function parameters) (-> Function (List Value) Value) (:abstraction (format (:representation function) - (..parenthesize (..enumerate parameters))))) + (..parenthesize (..listing parameters))))) ## Condition (template [<name> <sql_op>] @@ -169,7 +169,7 @@ (:abstraction (format (:representation value) " IN " - (..parenthesize (enumerate options))))) + (..parenthesize (listing options))))) (template [<func_name> <sql_op>] [(def: #export (<func_name> left right) @@ -313,17 +313,17 @@ (:abstraction (format (:representation query) " GROUP BY " - (..enumerate pairs))))) + (..listing pairs))))) ## Command (def: #export (insert table columns rows) (-> Table (List Column) (List (List Value)) (Command Without_Where Without_Having)) (:abstraction (format "INSERT INTO " (:representation table) " " - (..parenthesize (..enumerate columns)) + (..parenthesize (..listing columns)) " VALUES " (|> rows - (list\map (|>> ..enumerate ..parenthesize)) + (list\map (|>> ..listing ..parenthesize)) (text.join_with ", ")) ))) @@ -399,7 +399,7 @@ "CREATE TABLE IF NOT EXISTS")] (:abstraction (format command " " (:representation table) - (..parenthesize (..enumerate columns)))))) + (..parenthesize (..listing columns)))))) (def: #export (create_table_as table query) (-> Table Any_Query Definition) @@ -462,7 +462,7 @@ (-> Index Table Bit (List Column) Definition) (:abstraction (format "CREATE " (if unique? "UNIQUE" "") " INDEX " (:representation index) - " ON " (:representation table) " " (..parenthesize (..enumerate columns))))) + " ON " (:representation table) " " (..parenthesize (..listing columns))))) (def: #export (with alias query body) (All [where having order group limit offset] diff --git a/stdlib/source/program/aedifex.lux b/stdlib/source/program/aedifex.lux index 664883ab0..060f38855 100644 --- a/stdlib/source/program/aedifex.lux +++ b/stdlib/source/program/aedifex.lux @@ -97,9 +97,9 @@ {options (Dictionary Text Address)}) (exception.report ["Repository" (%.text repository)] - ["Options" (exception.enumerate (function (_ [name repo]) - (format (%.text name) " := " (%.text repo))) - (dictionary.entries options))])) + ["Options" (exception.listing (function (_ [name repo]) + (format (%.text name) " := " (%.text repo))) + (dictionary.entries options))])) (def: succeed! (IO Any) diff --git a/stdlib/source/program/aedifex/command/deps.lux b/stdlib/source/program/aedifex/command/deps.lux index 0238f64cd..3d26a042b 100644 --- a/stdlib/source/program/aedifex/command/deps.lux +++ b/stdlib/source/program/aedifex/command/deps.lux @@ -60,18 +60,18 @@ _ (console.write_line (exception.report ["Local successes" (|> local_successes (list.sort (\ ///dependency.order <)) - (exception.enumerate ..format))] + (exception.listing ..format))] ["Local failures" (|> local_failures (list.sort (\ ///dependency.order <)) - (exception.enumerate ..format))] + (exception.listing ..format))] ["Remote successes" (|> remote_successes (set.of_list ///dependency.hash) (set.difference (set.of_list ///dependency.hash local_successes)) set.to_list (list.sort (\ ///dependency.order <)) - (exception.enumerate ..format))] + (exception.listing ..format))] ["Remote failures" (|> remote_failures (list.sort (\ ///dependency.order <)) - (exception.enumerate ..format))]) + (exception.listing ..format))]) console)] (in resolution)))) diff --git a/stdlib/source/program/compositor/export.lux b/stdlib/source/program/compositor/export.lux index 46cf9c8ec..239341e5d 100644 --- a/stdlib/source/program/compositor/export.lux +++ b/stdlib/source/program/compositor/export.lux @@ -42,7 +42,7 @@ (def: #export (library fs sources) (-> (file.System Async) (List Source) (Async (Try tar.Tar))) (do (try.with async.monad) - [files (io.enumerate fs sources)] + [files (io.listing fs sources)] (|> (dictionary.entries files) (monad.map try.monad (function (_ [path source_code]) diff --git a/stdlib/source/program/scriptum.lux b/stdlib/source/program/scriptum.lux index da76896eb..941c55087 100644 --- a/stdlib/source/program/scriptum.lux +++ b/stdlib/source/program/scriptum.lux @@ -41,7 +41,7 @@ (def: (parameter_type_name id) (-> Nat Text) - (case (text.nth id ..name_options) + (case (text.char id ..name_options) (#.Some char) (text.of_char char) @@ -51,7 +51,7 @@ (def: type_var_names (Sequence Text) - (|> 0 (sequence.iterate inc) (sequence\map parameter_type_name))) + (|> 0 (sequence.iterations inc) (sequence\map parameter_type_name))) (template [<name> <partition>] [(def: (<name> id) @@ -70,7 +70,7 @@ (-> [Text (List Text)] Nat Nat Text) (if (type_arg? id) (let [arg_id (..arg_id level id)] - (case (list.nth arg_id type_function_arguments) + (case (list.item arg_id type_function_arguments) (#.Some found) found @@ -78,7 +78,7 @@ (|> type_var_names (sequence.only (function (_ var_name) (not (list.member? text.equivalence type_function_arguments var_name)))) - (sequence.nth arg_id)))) + (sequence.item arg_id)))) type_func_name)) (def: (level_to_args offset level) @@ -378,7 +378,7 @@ ")")))) _ - (meta.failure (exception.construct anonymous_type_definition type)))) + (meta.failure (exception.error anonymous_type_definition type)))) (def: (document_types module types) (-> Text (List Value) (Meta (Markdown Block))) @@ -496,7 +496,7 @@ [outcome (\ file.default write (\ utf8.codec encode (md.markdown documentation)) path)] (in (case outcome (#try.Failure error) - (debug.log! (exception.construct io_error error)) + (debug.log! (exception.error io_error error)) (#try.Success _) []))))) diff --git a/stdlib/source/specification/compositor/generation/function.lux b/stdlib/source/specification/compositor/generation/function.lux index 5a5891088..5be34bfa5 100644 --- a/stdlib/source/specification/compositor/generation/function.lux +++ b/stdlib/source/specification/compositor/generation/function.lux @@ -53,7 +53,7 @@ [[arity local functionS] ..function partial_arity (|> r.nat (\ ! map (|>> (n.% arity) (n.max 1)))) inputs (r.list arity r.safe_frac) - #let [expectation (maybe.assume (list.nth (dec local) inputs)) + #let [expectation (maybe.assume (list.item (dec local) inputs)) inputsS (list\map (|>> synthesis.f64) inputs)]] ($_ _.and (_.test "Can read arguments." diff --git a/stdlib/source/test/aedifex/command/version.lux b/stdlib/source/test/aedifex/command/version.lux index f87424ab6..b501573d7 100644 --- a/stdlib/source/test/aedifex/command/version.lux +++ b/stdlib/source/test/aedifex/command/version.lux @@ -37,7 +37,7 @@ (if open? (try.of_maybe (do maybe.monad - [head (text.nth 0 state) + [head (text.char 0 state) [_ tail] (text.split 1 state)] (in [[open? tail] head]))) (exception.except ..console_is_closed! []))) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index 63d468945..ca533e853 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -10,8 +10,7 @@ ["@" target] ["." meta] [abstract - [monad (#+ do)] - [predicate (#+ Predicate)]] + [monad (#+ do)]] [control ["." io] [concurrency @@ -21,11 +20,13 @@ ["." text ("#\." equivalence) ["%" format (#+ format)]] [collection - ["." list]]] + ["." list] + ["." set (#+ Set)]]] ["." macro + [syntax (#+ syntax:)] ["." code ("#\." equivalence)]] ["." math - ["." random (#+ Random) ("#\." functor)] + ["." random ("#\." functor)] [number [i8 (#+)] [i16 (#+)] @@ -462,8 +463,7 @@ expected_left random.nat expected_right random.nat - #let [existential_type (: (Random /.Type) - (\ ! map (|>> #.Ex) random.nat))] + #let [existential_type (\ ! map (|>> #.Ex) random.nat)] expected/0 existential_type expected/1 existential_type] (<| (_.for [/.Type]) @@ -1051,6 +1051,46 @@ I16))) ))) +(def: possible_targets + (Set @.Target) + (<| (set.of_list text.hash) + (list @.old + @.js + @.jvm + @.lua + @.python + @.ruby))) + +(syntax: (for_meta|Info) + (function (_ lux) + (let [info (get@ #.info lux) + + conforming_target! + (set.member? ..possible_targets (get@ #.target info)) + + compiling! + (case (get@ #.mode info) + #.Build true + _ false)] + (#.Right [lux (list (code.bit (and conforming_target! + compiling!)))])))) + +(syntax: (for_meta|Module_State) + (do meta.monad + [prelude_module (meta.module .prelude_module)] + (in (list (code.bit (case (get@ #.module_state prelude_module) + #.Active false + _ true)))))) + +(def: for_meta + Test + ($_ _.and + (_.cover [/.Mode /.Info] + (for_meta|Info)) + (_.cover [/.Module_State] + (for_meta|Module_State)) + )) + (def: test Test (<| (_.covering /._) @@ -1076,6 +1116,7 @@ ..for_control_flow ..for_def: ..for_import + ..for_meta ..sub_tests ))) diff --git a/stdlib/source/test/lux/control/concurrency/frp.lux b/stdlib/source/test/lux/control/concurrency/frp.lux index 6d60c750f..539ed17f0 100644 --- a/stdlib/source/test/lux/control/concurrency/frp.lux +++ b/stdlib/source/test/lux/control/concurrency/frp.lux @@ -209,14 +209,14 @@ (in (do async.monad [#let [max_iterations 10] actual (|> [0 sample] - (/.iterate (function (_ [iterations current]) - (async.resolved - (if (n.< max_iterations iterations) - (#.Some [[(inc iterations) (n.+ shift current)] - current]) - #.None)))) + (/.iterations (function (_ [iterations current]) + (async.resolved + (if (n.< max_iterations iterations) + (#.Some [[(inc iterations) (n.+ shift current)] + current]) + #.None)))) /.consume)] - (_.cover' [/.iterate] + (_.cover' [/.iterations] (and (n.= max_iterations (list.size actual)) (list\= (list.folds n.+ sample (list.repeat (dec max_iterations) shift)) actual))))) diff --git a/stdlib/source/test/lux/control/exception.lux b/stdlib/source/test/lux/control/exception.lux index 7b1643b79..7d1cbcf53 100644 --- a/stdlib/source/test/lux/control/exception.lux +++ b/stdlib/source/test/lux/control/exception.lux @@ -45,16 +45,16 @@ (case (/.except ..an_exception []) (#try.Success _) false (#try.Failure _) true)) - (_.cover [/.construct] + (_.cover [/.error] (case (/.except ..an_exception []) (#try.Success _) false (#try.Failure message) - (text\= message (/.construct ..an_exception [])))) + (text\= message (/.error ..an_exception [])))) (_.cover [/.match?] (/.match? ..an_exception - (/.construct ..an_exception []))) + (/.error ..an_exception []))) (_.cover [/.assertion] (case (/.assertion ..an_exception [] assertion_succeeded?) (#try.Success _) @@ -62,7 +62,7 @@ (#try.Failure message) (and (not assertion_succeeded?) - (text\= message (/.construct ..an_exception []))))) + (text\= message (/.error ..an_exception []))))) (_.cover [/.catch] (and (n.= expected (|> (/.except ..an_exception []) @@ -85,8 +85,8 @@ (text.contains? value0 report) (text.contains? field1 report) (text.contains? value1 report)))) - (_.cover [/.enumerate] - (let [enumeration (/.enumerate %.text (list field0 value0 field1 value1))] + (_.cover [/.listing] + (let [enumeration (/.listing %.text (list field0 value0 field1 value1))] (and (text.contains? field0 enumeration) (text.contains? value0 enumeration) (text.contains? field1 enumeration) @@ -97,7 +97,7 @@ (#try.Failure _) false) (case (/.with ..an_exception [] (#try.Failure "")) (#try.Success _) false - (#try.Failure message) (text\= message (/.construct ..an_exception []))) + (#try.Failure message) (text\= message (/.error ..an_exception []))) (case (/.with ..an_exception [] (: (Try Nat) (/.except ..another_exception []))) @@ -105,8 +105,8 @@ false (#try.Failure message) - (and (text.contains? (/.construct ..an_exception []) message) - (text.contains? (/.construct ..another_exception []) message))))) + (and (text.contains? (/.error ..an_exception []) message) + (text.contains? (/.error ..another_exception []) message))))) (_.cover [/.exception:] (case (/.except ..custom_exception [expected]) (#try.Success _) diff --git a/stdlib/source/test/lux/control/parser/text.lux b/stdlib/source/test/lux/control/parser/text.lux index c8fa56388..1285428cd 100644 --- a/stdlib/source/test/lux/control/parser/text.lux +++ b/stdlib/source/test/lux/control/parser/text.lux @@ -160,7 +160,7 @@ (text.join_with "")))) expected (\ ! map (function (_ value) (|> options - (text.nth (n.% num_options value)) + (text.char (n.% num_options value)) maybe.assume)) random.nat) invalid (random.only (function (_ char) @@ -186,7 +186,7 @@ (text.join_with "")))) invalid (\ ! map (function (_ value) (|> options - (text.nth (n.% num_options value)) + (text.char (n.% num_options value)) maybe.assume)) random.nat) expected (random.only (function (_ char) diff --git a/stdlib/source/test/lux/control/region.lux b/stdlib/source/test/lux/control/region.lux index 9bd903d71..abda4177c 100644 --- a/stdlib/source/test/lux/control/region.lux +++ b/stdlib/source/test/lux/control/region.lux @@ -127,7 +127,7 @@ (do {! (/.monad !)} [_ (monad.map ! (/.acquire //@ count_clean_up) (enum.range n.enum 1 expected_clean_ups)) - _ (/.failure //@ (exception.construct ..oops []))] + _ (/.failure //@ (exception.error ..oops []))] (in []))) actual_clean_ups (thread.read clean_up_counter)] (in (and (..throws? ..oops outcome) diff --git a/stdlib/source/test/lux/control/remember.lux b/stdlib/source/test/lux/control/remember.lux index bd9833aec..2243f8584 100644 --- a/stdlib/source/test/lux/control/remember.lux +++ b/stdlib/source/test/lux/control/remember.lux @@ -114,9 +114,9 @@ ($_ _.and (_.cover [/.must_remember] (and (test_failure deadline message #.None - (exception.construct /.must_remember [deadline deadline message #.None])) + (exception.error /.must_remember [deadline deadline message #.None])) (test_failure deadline message (#.Some focus) - (exception.construct /.must_remember [deadline deadline message (#.Some focus)])))) + (exception.error /.must_remember [deadline deadline message (#.Some focus)])))) (_.cover [/.remember] (..test_macro /.remember "")) (_.cover [/.to_do] diff --git a/stdlib/source/test/lux/data/collection/list.lux b/stdlib/source/test/lux/data/collection/list.lux index 872c21e2d..209dfe143 100644 --- a/stdlib/source/test/lux/data/collection/list.lux +++ b/stdlib/source/test/lux/data/collection/list.lux @@ -165,9 +165,9 @@ (/\map product.right enumeration))] (and has_correct_indices! has_correct_values!))) - (_.cover [/.nth] + (_.cover [/.item] (/.every? (function (_ [index expected]) - (case (/.nth index sample) + (case (/.item index sample) (#.Some actual) (n.= expected actual) @@ -413,15 +413,15 @@ (and (n.= (|> (/.size sample) (n.* 2) dec) (/.size sample+)) (|> sample+ /.pairs (/.every? (|>> product.right (n.= separator)))))))) - (_.cover [/.iterate] + (_.cover [/.iterations] (or (/.empty? sample) (let [size (/.size sample)] (/\= (/.indices size) - (/.iterate (function (_ index) - (if (n.< size index) - (#.Some (inc index)) - #.None)) - 0))))) + (/.iterations (function (_ index) + (if (n.< size index) + (#.Some (inc index)) + #.None)) + 0))))) (_.cover [/.folds] (/\= (/\map (function (_ index) (\ /.fold fold n.+ 0 (/.take index sample))) diff --git a/stdlib/source/test/lux/data/collection/row.lux b/stdlib/source/test/lux/data/collection/row.lux index 902fec0d8..4eda82b14 100644 --- a/stdlib/source/test/lux/data/collection/row.lux +++ b/stdlib/source/test/lux/data/collection/row.lux @@ -91,8 +91,8 @@ random.nat) #let [sample (|> sample set.to_list /.of_list)]] ($_ _.and - (_.cover [/.nth] - (case (/.nth good_index sample) + (_.cover [/.item] + (case (/.item good_index sample) (#try.Success member) (/.member? n.equivalence sample member) @@ -102,14 +102,14 @@ (<| (try.else false) (do try.monad [sample (/.put good_index non_member sample) - actual (/.nth good_index sample)] + actual (/.item good_index sample)] (in (is? non_member actual))))) (_.cover [/.update] (<| (try.else false) (do try.monad [sample (/.put good_index non_member sample) sample (/.update good_index inc sample) - actual (/.nth good_index sample)] + actual (/.item good_index sample)] (in (n.= (inc non_member) actual))))) (_.cover [/.within_bounds?] (and (/.within_bounds? sample good_index) @@ -123,7 +123,7 @@ (#try.Failure error) (exception.match? /.index_out_of_bounds error))))] - (and (fails! (/.nth bad_index sample)) + (and (fails! (/.item bad_index sample)) (fails! (/.put bad_index non_member sample)) (fails! (/.update bad_index inc sample))))) )) diff --git a/stdlib/source/test/lux/data/collection/sequence.lux b/stdlib/source/test/lux/data/collection/sequence.lux index 5058fae08..a5ba1f1bc 100644 --- a/stdlib/source/test/lux/data/collection/sequence.lux +++ b/stdlib/source/test/lux/data/collection/sequence.lux @@ -47,57 +47,57 @@ (_.for [/.comonad] ($comonad.spec /.repeat ..equivalence /.comonad)) - (_.cover [/.iterate /.nth] + (_.cover [/.iterations /.item] (n.= (n.+ offset index) - (/.nth index (/.iterate inc offset)))) + (/.item index (/.iterations inc offset)))) (_.cover [/.repeat] (n.= repeated - (/.nth index (/.repeat repeated)))) + (/.item index (/.repeat repeated)))) (_.cover [/.take] (list\= (enum.range n.enum offset (dec (n.+ size offset))) - (/.take size (/.iterate inc offset)))) + (/.take size (/.iterations inc offset)))) (_.cover [/.drop] (list\= (enum.range n.enum offset (dec (n.+ size offset))) - (/.take size (/.drop offset (/.iterate inc 0))))) + (/.take size (/.drop offset (/.iterations inc 0))))) (_.cover [/.split] - (let [[drops takes] (/.split size (/.iterate inc 0))] + (let [[drops takes] (/.split size (/.iterations inc 0))] (and (list\= (enum.range n.enum 0 (dec size)) drops) (list\= (enum.range n.enum size (dec (n.* 2 size))) (/.take size takes))))) (_.cover [/.take_while] (list\= (enum.range n.enum 0 (dec size)) - (/.take_while (n.< size) (/.iterate inc 0)))) + (/.take_while (n.< size) (/.iterations inc 0)))) (_.cover [/.drop_while] (list\= (enum.range n.enum offset (dec (n.+ size offset))) (/.take_while (n.< (n.+ size offset)) - (/.drop_while (n.< offset) (/.iterate inc 0))))) + (/.drop_while (n.< offset) (/.iterations inc 0))))) (_.cover [/.split_while] - (let [[drops takes] (/.split_while (n.< size) (/.iterate inc 0))] + (let [[drops takes] (/.split_while (n.< size) (/.iterations inc 0))] (and (list\= (enum.range n.enum 0 (dec size)) drops) (list\= (enum.range n.enum size (dec (n.* 2 size))) (/.take_while (n.< (n.* 2 size)) takes))))) (_.cover [/.head] (n.= offset - (/.head (/.iterate inc offset)))) + (/.head (/.iterations inc offset)))) (_.cover [/.tail] (list\= (enum.range n.enum (inc offset) (n.+ size offset)) - (/.take size (/.tail (/.iterate inc offset))))) + (/.take size (/.tail (/.iterations inc offset))))) (_.cover [/.only] (list\= (list\map (n.* 2) (enum.range n.enum 0 (dec size))) - (/.take size (/.only n.even? (/.iterate inc 0))))) + (/.take size (/.only n.even? (/.iterations inc 0))))) (_.cover [/.partition] - (let [[evens odds] (/.partition n.even? (/.iterate inc 0))] + (let [[evens odds] (/.partition n.even? (/.iterations inc 0))] (and (n.= (n.* 2 offset) - (/.nth offset evens)) + (/.item offset evens)) (n.= (inc (n.* 2 offset)) - (/.nth offset odds))))) + (/.item offset odds))))) (_.cover [/.unfold] (let [(^open "/\.") /.functor (^open "list\.") (list.equivalence text.equivalence)] (list\= (/.take size - (/\map %.nat (/.iterate inc offset))) + (/\map %.nat (/.iterations inc offset))) (/.take size (/.unfold (function (_ n) [(inc n) (%.nat n)]) offset))))) @@ -107,7 +107,7 @@ (/.take (n.* size (list.size cycle)) (/.cycle [cycle_start cycle_next]))))) (_.cover [/.^sequence&] - (let [(/.^sequence& first second third next) (/.iterate inc offset)] + (let [(/.^sequence& first second third next) (/.iterations inc offset)] (and (n.= offset first) (n.= (n.+ 1 offset) second) (n.= (n.+ 2 offset) third)))) diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux index 063d3ef2f..940f22cd8 100644 --- a/stdlib/source/test/lux/data/format/json.lux +++ b/stdlib/source/test/lux/data/format/json.lux @@ -48,12 +48,12 @@ (syntax: (boolean) (do meta.monad - [value meta.count] + [value meta.seed] (in (list (code.bit (n.even? value)))))) (syntax: (number) (do meta.monad - [value meta.count] + [value meta.seed] (in (list (code.frac (n.frac value)))))) (syntax: (string) diff --git a/stdlib/source/test/lux/data/format/xml.lux b/stdlib/source/test/lux/data/format/xml.lux index e73e4960a..1fec8a797 100644 --- a/stdlib/source/test/lux/data/format/xml.lux +++ b/stdlib/source/test/lux/data/format/xml.lux @@ -37,7 +37,7 @@ (Random Nat) (do {! random.monad} [idx (|> random.nat (\ ! map (n.% (text.size char_range))))] - (in (maybe.assume (text.nth idx char_range))))) + (in (maybe.assume (text.char idx char_range))))) (def: (size bottom top) (-> Nat Nat (Random Nat)) diff --git a/stdlib/source/test/lux/data/text.lux b/stdlib/source/test/lux/data/text.lux index 82a364120..3e063f73a 100644 --- a/stdlib/source/test/lux/data/text.lux +++ b/stdlib/source/test/lux/data/text.lux @@ -168,8 +168,8 @@ characters (random.set /.hash size (random.ascii/alpha 1)) #let [sample (|> characters set.to_list /.concat)] expected (\ ! map (n.% size) random.nat)] - (_.cover [/.nth] - (case (/.nth expected sample) + (_.cover [/.char] + (case (/.char expected sample) (#.Some char) (case (/.index_of (/.of_char char) sample) (#.Some actual) diff --git a/stdlib/source/test/lux/data/text/encoding.lux b/stdlib/source/test/lux/data/text/encoding.lux index f5670b35f..4cdf461b7 100644 --- a/stdlib/source/test/lux/data/text/encoding.lux +++ b/stdlib/source/test/lux/data/text/encoding.lux @@ -215,7 +215,7 @@ (let [options (list.size ..all_encodings)] (do {! random.monad} [choice (\ ! map (n.% options) random.nat)] - (in (maybe.assume (list.nth choice ..all_encodings)))))) + (in (maybe.assume (list.item choice ..all_encodings)))))) (def: #export test Test diff --git a/stdlib/source/test/lux/data/text/escape.lux b/stdlib/source/test/lux/data/text/escape.lux index 6899c6f62..34f37de58 100644 --- a/stdlib/source/test/lux/data/text/escape.lux +++ b/stdlib/source/test/lux/data/text/escape.lux @@ -71,7 +71,7 @@ (syntax: (static_sample) (do meta.monad - [seed meta.count + [seed meta.seed #let [[_ expected] (random.run (random.pcg32 [seed seed]) (random.ascii 10))]] (in (list (code.text expected))))) diff --git a/stdlib/source/test/lux/locale/language.lux b/stdlib/source/test/lux/locale/language.lux index ed2e8401d..3fcda84d7 100644 --- a/stdlib/source/test/lux/locale/language.lux +++ b/stdlib/source/test/lux/locale/language.lux @@ -282,7 +282,7 @@ (do {! random.monad} [choice (\ ! map (n.% (list.size options)) random.nat)] - (in (maybe.assume (list.nth choice options)))))) + (in (maybe.assume (list.item choice options)))))) (def: #export test Test diff --git a/stdlib/source/test/lux/locale/territory.lux b/stdlib/source/test/lux/locale/territory.lux index a949e9bf0..e03bd8dc6 100644 --- a/stdlib/source/test/lux/locale/territory.lux +++ b/stdlib/source/test/lux/locale/territory.lux @@ -208,7 +208,7 @@ (do {! random.monad} [choice (\ ! map (n.% (list.size options)) random.nat)] - (in (maybe.assume (list.nth choice options)))))) + (in (maybe.assume (list.item choice options)))))) (def: #export test Test diff --git a/stdlib/source/test/lux/math/modulus.lux b/stdlib/source/test/lux/math/modulus.lux index 16fcdba76..7a3cde72c 100644 --- a/stdlib/source/test/lux/math/modulus.lux +++ b/stdlib/source/test/lux/math/modulus.lux @@ -20,7 +20,7 @@ (syntax: (|divisor|) (do meta.monad - [divisor meta.count] + [divisor meta.seed] (in (list (code.int (case divisor 0 +1 _ (.int divisor))))))) diff --git a/stdlib/source/test/lux/math/number/i64.lux b/stdlib/source/test/lux/math/number/i64.lux index 4024003c9..1d097ca27 100644 --- a/stdlib/source/test/lux/math/number/i64.lux +++ b/stdlib/source/test/lux/math/number/i64.lux @@ -103,7 +103,7 @@ offset (\ ! map (n.% spare) random.nat)] (_.cover [/.region] (case size - 0 (\= /.false (/.region size offset)) + 0 (\= /.false (/.region offset size)) _ (\= (|> pattern ## NNNNYYYYNNNN (/.right_shifted offset) @@ -115,7 +115,7 @@ (/.left_shifted offset) ## ____YYYY____ ) - (/.and (/.region size offset) pattern))))) + (/.and (/.region offset size) pattern))))) )))) (def: sub diff --git a/stdlib/source/test/lux/meta.lux b/stdlib/source/test/lux/meta.lux index 92f88dfc6..6855ada9a 100644 --- a/stdlib/source/test/lux/meta.lux +++ b/stdlib/source/test/lux/meta.lux @@ -312,10 +312,10 @@ #.extensions [] #.host []}]] ($_ _.and - (_.cover [/.count] + (_.cover [/.seed] (|> (do /.monad - [pre /.count - post /.count] + [pre /.seed + post /.seed] (in [pre post])) (/.run expected_lux) (!expect (^multi (#try.Success [actual_pre actual_post]) @@ -719,12 +719,12 @@ (/.run expected_lux) (try\map (\ (maybe.equivalence (list.equivalence name.equivalence)) = (#.Some tags_1))) (try.else false))) - (_.cover [/.resolve_tag] + (_.cover [/.tag] (|> tags_1 list.enumeration (list.every? (function (_ [expected_index tag]) (|> tag - /.resolve_tag + /.tag (/.run expected_lux) (!expect (^multi (^ (#try.Success [actual_index actual_tags actual_type])) (let [correct_index! diff --git a/stdlib/source/test/lux/target/jvm.lux b/stdlib/source/test/lux/target/jvm.lux index 1f52753d1..f15340fc4 100644 --- a/stdlib/source/test/lux/target/jvm.lux +++ b/stdlib/source/test/lux/target/jvm.lux @@ -1502,7 +1502,7 @@ (\ ! map (|>> (:as java/lang/Long) ffi.long_to_int ffi.int_to_long (:as Int))) (random.set i.hash options) (\ ! map set.to_list)) - #let [choice (maybe.assume (list.nth choice options))] + #let [choice (maybe.assume (list.item choice options))] expected ..$Long::random dummy ..$Long::random]) (..bytecode ((!::= java/lang/Long "jvm leq" "jvm long =") expected)) diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/case.lux b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/case.lux index 4afc28a2d..425872c1a 100644 --- a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/case.lux +++ b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/case.lux @@ -123,8 +123,8 @@ (r\map product.right _primitive.primitive) (do {! r.monad} [choice (|> r.nat (\ ! map (n.% (list.size variant_tags)))) - #let [choiceT (maybe.assume (list.nth choice variant_tags)) - choiceC (maybe.assume (list.nth choice primitivesC))]] + #let [choiceT (maybe.assume (list.item choice variant_tags)) + choiceC (maybe.assume (list.item choice primitivesC))]] (in (` ((~ choiceT) (~ choiceC))))) (do {! r.monad} [size (|> r.nat (\ ! map (n.% 3))) @@ -189,7 +189,7 @@ #let [redundant_branchesC (<| (list!map (branch outputC)) list.concat (list (list.take redundancy_idx redundant_patterns) - (list (maybe.assume (list.nth redundancy_idx redundant_patterns))) + (list (maybe.assume (list.item redundancy_idx redundant_patterns))) (list.drop redundancy_idx redundant_patterns)))]] (_.test "Will reject redundant pattern-matching." (|> (analyse_pm redundant_branchesC) @@ -199,7 +199,7 @@ _primitive.primitive) heterogeneous_idx (|> r.nat (\ ! map (n.% (list.size exhaustive_patterns)))) #let [heterogeneous_branchesC (list.concat (list (list.take heterogeneous_idx exhaustive_branchesC) - (list (let [[_pattern _body] (maybe.assume (list.nth heterogeneous_idx exhaustive_branchesC))] + (list (let [[_pattern _body] (maybe.assume (list.item heterogeneous_idx exhaustive_branchesC))] [_pattern heterogeneousC])) (list.drop (inc heterogeneous_idx) exhaustive_branchesC)))]] (_.test "Will reject pattern-matching if the bodies of the branches do not all have the same type." diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/function.lux b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/function.lux index 1cf61d839..c59de0da6 100644 --- a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/function.lux +++ b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/function.lux @@ -96,7 +96,7 @@ (list varT) (list.drop (inc var_idx) inputsT)))) varT) - poly_inputT (maybe.assume (list.nth var_idx inputsT)) + poly_inputT (maybe.assume (list.item var_idx inputsT)) partial_poly_inputsT (list.drop (inc var_idx) inputsT) partial_polyT1 (<| (type.function partial_poly_inputsT) poly_inputT) diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/structure.lux b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/structure.lux index c4f35feea..c4a1a50b9 100644 --- a/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/structure.lux +++ b/stdlib/source/test/lux/tool/compiler/language/lux/phase/analysis/structure.lux @@ -124,12 +124,12 @@ +choice (|> r.nat (\ ! map (n.% (inc size)))) [_ +valueC] _primitive.primitive #let [variantT (type.variant (list\map product.left primitives)) - [valueT valueC] (maybe.assume (list.nth choice primitives)) + [valueT valueC] (maybe.assume (list.item choice primitives)) +size (inc size) +primitives (list.concat (list (list.take choice primitives) (list [(#.Parameter 1) +valueC]) (list.drop choice primitives))) - [+valueT +valueC] (maybe.assume (list.nth +choice +primitives)) + [+valueT +valueC] (maybe.assume (list.item +choice +primitives)) +variantT (type.variant (list\map product.left +primitives))]] (<| (_.context (%.name (name_of /.sum))) ($_ _.and @@ -175,7 +175,7 @@ choice (|> r.nat (\ ! map (n.% size))) [_ +valueC] _primitive.primitive #let [tupleT (type.tuple (list\map product.left primitives)) - [singletonT singletonC] (|> primitives (list.nth choice) maybe.assume) + [singletonT singletonC] (|> primitives (list.item choice) maybe.assume) +primitives (list.concat (list (list.take choice primitives) (list [(#.Parameter 1) +valueC]) (list.drop choice primitives))) @@ -240,15 +240,15 @@ #let [with_name (|>> (#.Named [module_name type_name])) varT (#.Parameter 1) primitivesT (list\map product.left primitives) - [choiceT choiceC] (maybe.assume (list.nth choice primitives)) - [other_choiceT other_choiceC] (maybe.assume (list.nth other_choice primitives)) + [choiceT choiceC] (maybe.assume (list.item choice primitives)) + [other_choiceT other_choiceC] (maybe.assume (list.item other_choice primitives)) monoT (type.variant primitivesT) polyT (|> (type.variant (list.concat (list (list.take choice primitivesT) (list varT) (list.drop (inc choice) primitivesT)))) (type.univ_q 1)) - choice_tag (maybe.assume (list.nth choice tags)) - other_choice_tag (maybe.assume (list.nth other_choice tags))]] + choice_tag (maybe.assume (list.item choice tags)) + other_choice_tag (maybe.assume (list.item other_choice tags))]] (<| (_.context (%.name (name_of /.tagged_sum))) ($_ _.and (_.test "Can infer." diff --git a/stdlib/source/test/lux/type/resource.lux b/stdlib/source/test/lux/type/resource.lux index a281a476b..4bfb49503 100644 --- a/stdlib/source/test/lux/type/resource.lux +++ b/stdlib/source/test/lux/type/resource.lux @@ -32,7 +32,7 @@ [pre (\ ! map %.nat random.nat) post (\ ! map %.nat random.nat) #let [! identity.monad]] - (_.for [/.Linear /.run] + (_.for [/.Linear /.run /.monad] (`` ($_ _.and (~~ (template [<coverage> <bindings>] [(_.cover <coverage> @@ -74,7 +74,7 @@ [pre (\ ! map %.nat random.nat) post (\ ! map %.nat random.nat) #let [! io.monad]] - (_.for [/.Linear /.run] + (_.for [/.Linear /.run /.monad] (`` ($_ _.and (~~ (template [<coverage> <bindings>] [(_.cover <coverage> @@ -117,7 +117,7 @@ [pre (\ ! map %.nat random.nat) post (\ ! map %.nat random.nat) #let [! async.monad]] - (_.for [/.Linear /.run] + (_.for [/.Linear /.run /.monad] (`` ($_ _.and (~~ (template [<coverage> <bindings>] [(in (monad.do ! diff --git a/stdlib/source/test/lux/type/unit.lux b/stdlib/source/test/lux/type/unit.lux index 683bf504c..9557d522d 100644 --- a/stdlib/source/test/lux/type/unit.lux +++ b/stdlib/source/test/lux/type/unit.lux @@ -80,7 +80,7 @@ (syntax: (natural) (\ meta.monad map (|>> code.nat list) - meta.count)) + meta.seed)) (with_expansions [<from> (..natural) <to> (..natural)] diff --git a/stdlib/source/test/lux/world/console.lux b/stdlib/source/test/lux/world/console.lux index 5a815c294..003c20c34 100644 --- a/stdlib/source/test/lux/world/console.lux +++ b/stdlib/source/test/lux/world/console.lux @@ -25,7 +25,7 @@ (implementation (def: (on_read [dead? content]) (do try.monad - [char (try.of_maybe (text.nth 0 content)) + [char (try.of_maybe (text.char 0 content)) [_ content] (try.of_maybe (text.split 1 content))] (if dead? (exception.except ..dead []) diff --git a/stdlib/source/test/lux/world/input/keyboard.lux b/stdlib/source/test/lux/world/input/keyboard.lux index 24b657f0d..e0064f29b 100644 --- a/stdlib/source/test/lux/world/input/keyboard.lux +++ b/stdlib/source/test/lux/world/input/keyboard.lux @@ -140,7 +140,7 @@ (let [count (list.size ..listing)] (do {! random.monad} [choice (\ ! map (n.% count) random.nat)] - (in (maybe.assume (list.nth choice ..listing)))))) + (in (maybe.assume (list.item choice ..listing)))))) (def: #export test Test diff --git a/stdlib/source/test/lux/world/output/video/resolution.lux b/stdlib/source/test/lux/world/output/video/resolution.lux index 411ae288d..378352c57 100644 --- a/stdlib/source/test/lux/world/output/video/resolution.lux +++ b/stdlib/source/test/lux/world/output/video/resolution.lux @@ -47,7 +47,7 @@ (let [count (list.size ..listing)] (do {! random.monad} [choice (\ ! map (n.% count) random.nat)] - (in (maybe.assume (list.nth choice ..listing)))))) + (in (maybe.assume (list.item choice ..listing)))))) (def: #export test Test |