From a62ce3f9c2b605e0033f4772b0f64c4525de4d86 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 11 Aug 2021 02:38:59 -0400 Subject: Relocated maybe and lazy from data to control. --- stdlib/source/library/lux.lux | 420 ++++++++++----------- stdlib/source/library/lux/abstract/comonad.lux | 24 +- .../source/library/lux/abstract/comonad/cofree.lux | 2 +- stdlib/source/library/lux/abstract/equivalence.lux | 2 +- stdlib/source/library/lux/abstract/fold.lux | 2 +- stdlib/source/library/lux/abstract/functor.lux | 4 +- .../library/lux/abstract/functor/contravariant.lux | 2 +- stdlib/source/library/lux/abstract/hash.lux | 4 +- stdlib/source/library/lux/abstract/interval.lux | 12 +- stdlib/source/library/lux/abstract/monad.lux | 26 +- .../source/library/lux/abstract/monad/indexed.lux | 2 +- stdlib/source/library/lux/abstract/monoid.lux | 4 +- stdlib/source/library/lux/abstract/order.lux | 14 +- stdlib/source/library/lux/abstract/predicate.lux | 16 +- .../source/library/lux/control/concatenative.lux | 161 ++++---- .../library/lux/control/concurrency/actor.lux | 80 ++-- .../library/lux/control/concurrency/async.lux | 76 ++-- .../library/lux/control/concurrency/atom.lux | 40 +- .../source/library/lux/control/concurrency/frp.lux | 33 +- .../library/lux/control/concurrency/semaphore.lux | 22 +- .../source/library/lux/control/concurrency/stm.lux | 16 +- .../library/lux/control/concurrency/thread.lux | 10 +- stdlib/source/library/lux/control/continuation.lux | 12 +- stdlib/source/library/lux/control/exception.lux | 46 +-- stdlib/source/library/lux/control/function.lux | 28 +- .../library/lux/control/function/contract.lux | 28 +- .../source/library/lux/control/function/memo.lux | 21 +- .../source/library/lux/control/function/mixin.lux | 22 +- .../source/library/lux/control/function/mutual.lux | 60 +-- stdlib/source/library/lux/control/io.lux | 26 +- stdlib/source/library/lux/control/lazy.lux | 74 ++++ stdlib/source/library/lux/control/maybe.lux | 171 +++++++++ stdlib/source/library/lux/control/parser.lux | 46 +-- .../source/library/lux/control/parser/analysis.lux | 18 +- .../source/library/lux/control/parser/binary.lux | 32 +- stdlib/source/library/lux/control/parser/cli.lux | 12 +- stdlib/source/library/lux/control/parser/code.lux | 8 +- .../library/lux/control/parser/environment.lux | 14 +- stdlib/source/library/lux/control/parser/json.lux | 24 +- .../library/lux/control/parser/synthesis.lux | 28 +- stdlib/source/library/lux/control/parser/text.lux | 32 +- stdlib/source/library/lux/control/parser/tree.lux | 18 +- stdlib/source/library/lux/control/parser/type.lux | 56 +-- stdlib/source/library/lux/control/parser/xml.lux | 36 +- stdlib/source/library/lux/control/pipe.lux | 150 ++++---- stdlib/source/library/lux/control/reader.lux | 8 +- stdlib/source/library/lux/control/region.lux | 16 +- stdlib/source/library/lux/control/remember.lux | 30 +- .../library/lux/control/security/capability.lux | 28 +- .../source/library/lux/control/security/policy.lux | 64 ++-- stdlib/source/library/lux/control/state.lux | 8 +- stdlib/source/library/lux/control/thread.lux | 18 +- stdlib/source/library/lux/control/try.lux | 28 +- stdlib/source/library/lux/control/writer.lux | 4 +- stdlib/source/library/lux/data/binary.lux | 38 +- stdlib/source/library/lux/data/bit.lux | 4 +- .../source/library/lux/data/collection/array.lux | 27 +- stdlib/source/library/lux/data/collection/bits.lux | 10 +- .../library/lux/data/collection/dictionary.lux | 20 +- .../lux/data/collection/dictionary/ordered.lux | 15 +- .../lux/data/collection/dictionary/plist.lux | 4 +- stdlib/source/library/lux/data/collection/list.lux | 62 +-- .../source/library/lux/data/collection/queue.lux | 4 +- .../library/lux/data/collection/queue/priority.lux | 3 +- stdlib/source/library/lux/data/collection/row.lux | 12 +- .../library/lux/data/collection/sequence.lux | 42 +-- stdlib/source/library/lux/data/collection/set.lux | 4 +- .../library/lux/data/collection/set/multi.lux | 15 +- .../library/lux/data/collection/set/ordered.lux | 6 +- .../source/library/lux/data/collection/stack.lux | 4 +- stdlib/source/library/lux/data/collection/tree.lux | 16 +- .../library/lux/data/collection/tree/finger.lux | 10 +- .../library/lux/data/collection/tree/zipper.lux | 3 +- stdlib/source/library/lux/data/color.lux | 26 +- stdlib/source/library/lux/data/color/named.lux | 2 +- stdlib/source/library/lux/data/format/binary.lux | 20 +- stdlib/source/library/lux/data/format/css.lux | 3 +- .../source/library/lux/data/format/css/value.lux | 2 +- stdlib/source/library/lux/data/format/html.lux | 7 +- stdlib/source/library/lux/data/format/json.lux | 26 +- stdlib/source/library/lux/data/format/tar.lux | 6 +- stdlib/source/library/lux/data/format/xml.lux | 10 +- stdlib/source/library/lux/data/identity.lux | 2 +- stdlib/source/library/lux/data/lazy.lux | 73 ---- stdlib/source/library/lux/data/maybe.lux | 171 --------- stdlib/source/library/lux/data/name.lux | 2 +- stdlib/source/library/lux/data/product.lux | 16 +- stdlib/source/library/lux/data/sum.lux | 6 +- stdlib/source/library/lux/data/text.lux | 15 +- stdlib/source/library/lux/data/text/encoding.lux | 16 +- .../source/library/lux/data/text/encoding/utf8.lux | 2 +- stdlib/source/library/lux/data/text/escape.lux | 11 +- stdlib/source/library/lux/data/text/format.lux | 4 +- stdlib/source/library/lux/data/text/regex.lux | 150 ++++---- .../source/library/lux/data/text/unicode/block.lux | 4 +- stdlib/source/library/lux/data/trace.lux | 2 +- stdlib/source/library/lux/debug.lux | 2 +- stdlib/source/library/lux/extension.lux | 16 +- stdlib/source/library/lux/ffi.js.lux | 12 +- stdlib/source/library/lux/ffi.jvm.lux | 318 ++++++++-------- stdlib/source/library/lux/ffi.lua.lux | 10 +- stdlib/source/library/lux/ffi.old.lux | 308 +++++++-------- stdlib/source/library/lux/ffi.php.lux | 20 +- stdlib/source/library/lux/ffi.py.lux | 10 +- stdlib/source/library/lux/ffi.rb.lux | 10 +- stdlib/source/library/lux/ffi.scm.lux | 18 +- stdlib/source/library/lux/locale.lux | 3 +- stdlib/source/library/lux/locale/language.lux | 2 +- stdlib/source/library/lux/locale/territory.lux | 2 +- stdlib/source/library/lux/macro.lux | 52 +-- stdlib/source/library/lux/macro/local.lux | 2 +- stdlib/source/library/lux/macro/poly.lux | 12 +- stdlib/source/library/lux/macro/syntax.lux | 42 +-- .../library/lux/macro/syntax/annotations.lux | 2 +- stdlib/source/library/lux/macro/syntax/check.lux | 2 +- .../library/lux/macro/syntax/declaration.lux | 10 +- .../source/library/lux/macro/syntax/definition.lux | 4 +- stdlib/source/library/lux/macro/syntax/export.lux | 2 +- stdlib/source/library/lux/macro/syntax/input.lux | 2 +- .../library/lux/macro/syntax/type/variable.lux | 2 +- stdlib/source/library/lux/macro/template.lux | 4 +- stdlib/source/library/lux/math/infix.lux | 64 ++-- .../source/library/lux/math/logic/continuous.lux | 6 +- stdlib/source/library/lux/math/logic/fuzzy.lux | 4 +- stdlib/source/library/lux/math/modular.lux | 2 +- stdlib/source/library/lux/math/modulus.lux | 12 +- stdlib/source/library/lux/math/number.lux | 6 +- stdlib/source/library/lux/math/number/complex.lux | 12 +- stdlib/source/library/lux/math/number/frac.lux | 2 +- stdlib/source/library/lux/math/number/i16.lux | 4 +- stdlib/source/library/lux/math/number/i32.lux | 8 +- stdlib/source/library/lux/math/number/i64.lux | 34 +- stdlib/source/library/lux/math/number/i8.lux | 4 +- stdlib/source/library/lux/math/number/int.lux | 14 +- stdlib/source/library/lux/math/number/nat.lux | 5 +- stdlib/source/library/lux/math/number/ratio.lux | 12 +- stdlib/source/library/lux/math/number/rev.lux | 4 +- stdlib/source/library/lux/math/random.lux | 14 +- stdlib/source/library/lux/meta.lux | 10 +- stdlib/source/library/lux/meta/annotation.lux | 5 +- stdlib/source/library/lux/meta/location.lux | 4 +- stdlib/source/library/lux/program.lux | 50 +-- stdlib/source/library/lux/target/jvm/bytecode.lux | 10 +- .../jvm/bytecode/environment/limit/stack.lux | 2 +- .../lux/target/jvm/bytecode/instruction.lux | 2 +- stdlib/source/library/lux/target/jvm/class.lux | 2 +- stdlib/source/library/lux/target/jvm/loader.lux | 6 +- stdlib/source/library/lux/target/jvm/method.lux | 2 +- stdlib/source/library/lux/target/jvm/modifier.lux | 4 +- .../source/library/lux/target/jvm/reflection.lux | 2 +- stdlib/source/library/lux/target/jvm/type.lux | 3 +- .../source/library/lux/target/jvm/type/alias.lux | 20 +- .../library/lux/target/jvm/type/descriptor.lux | 3 +- stdlib/source/library/lux/target/jvm/type/lux.lux | 2 +- .../source/library/lux/target/jvm/type/parser.lux | 16 +- stdlib/source/library/lux/target/r.lux | 2 +- stdlib/source/library/lux/test.lux | 54 +-- stdlib/source/library/lux/time.lux | 6 +- stdlib/source/library/lux/time/date.lux | 12 +- stdlib/source/library/lux/time/day.lux | 4 +- stdlib/source/library/lux/time/duration.lux | 2 +- stdlib/source/library/lux/time/instant.lux | 10 +- stdlib/source/library/lux/time/month.lux | 8 +- stdlib/source/library/lux/time/year.lux | 20 +- .../library/lux/tool/compiler/default/init.lux | 10 +- .../library/lux/tool/compiler/default/platform.lux | 16 +- .../lux/tool/compiler/language/lux/analysis.lux | 2 +- .../compiler/language/lux/analysis/evaluation.lux | 12 +- .../lux/tool/compiler/language/lux/generation.lux | 2 +- .../compiler/language/lux/phase/analysis/case.lux | 2 +- .../language/lux/phase/analysis/case/coverage.lux | 2 +- .../language/lux/phase/analysis/function.lux | 2 +- .../language/lux/phase/analysis/inference.lux | 2 +- .../compiler/language/lux/phase/analysis/scope.lux | 6 +- .../language/lux/phase/analysis/structure.lux | 2 +- .../tool/compiler/language/lux/phase/extension.lux | 2 +- .../language/lux/phase/extension/analysis/jvm.lux | 6 +- .../language/lux/phase/extension/analysis/lux.lux | 4 +- .../language/lux/phase/extension/directive/lux.lux | 3 +- .../extension/generation/common_lisp/common.lux | 22 +- .../lux/phase/extension/generation/js/common.lux | 44 +-- .../lux/phase/extension/generation/js/host.lux | 2 +- .../lux/phase/extension/generation/jvm/common.lux | 2 +- .../lux/phase/extension/generation/jvm/host.lux | 4 +- .../lux/phase/extension/generation/lua/common.lux | 50 +-- .../lux/phase/extension/generation/lua/host.lux | 2 +- .../lux/phase/extension/generation/php/common.lux | 46 +-- .../phase/extension/generation/python/common.lux | 50 +-- .../lux/phase/extension/generation/python/host.lux | 2 +- .../lux/phase/extension/generation/r/common.lux | 22 +- .../lux/phase/extension/generation/ruby/common.lux | 46 +-- .../phase/extension/generation/scheme/common.lux | 52 +-- .../generation/common_lisp/extension/common.lux | 38 +- .../lux/phase/generation/common_lisp/function.lux | 2 +- .../lux/phase/generation/common_lisp/runtime.lux | 2 +- .../language/lux/phase/generation/extension.lux | 6 +- .../language/lux/phase/generation/js/case.lux | 3 +- .../language/lux/phase/generation/js/runtime.lux | 2 +- .../language/lux/phase/generation/jvm/function.lux | 4 +- .../language/lux/phase/generation/jvm/host.lux | 36 +- .../language/lux/phase/generation/jvm/program.lux | 2 +- .../language/lux/phase/generation/jvm/runtime.lux | 4 +- .../language/lux/phase/generation/lua/runtime.lux | 6 +- .../language/lux/phase/generation/php/case.lux | 4 - .../lux/phase/generation/php/extension/common.lux | 48 +-- .../language/lux/phase/generation/php/runtime.lux | 6 +- .../language/lux/phase/generation/python/case.lux | 6 +- .../language/lux/phase/generation/python/loop.lux | 2 +- .../lux/phase/generation/python/runtime.lux | 4 +- .../language/lux/phase/generation/r/loop.lux | 2 +- .../lux/phase/generation/r/procedure/common.lux | 8 +- .../language/lux/phase/generation/r/runtime.lux | 2 +- .../language/lux/phase/generation/ruby/case.lux | 10 +- .../language/lux/phase/generation/ruby/loop.lux | 2 +- .../language/lux/phase/generation/ruby/runtime.lux | 6 +- .../phase/generation/scheme/extension/common.lux | 10 +- .../lux/phase/generation/scheme/runtime.lux | 2 +- .../tool/compiler/language/lux/phase/synthesis.lux | 5 +- .../compiler/language/lux/phase/synthesis/case.lux | 2 +- .../language/lux/phase/synthesis/function.lux | 2 +- .../compiler/language/lux/phase/synthesis/loop.lux | 3 +- .../language/lux/phase/synthesis/variable.lux | 4 +- .../lux/tool/compiler/language/lux/program.lux | 2 +- .../lux/tool/compiler/language/lux/syntax.lux | 2 +- .../lux/tool/compiler/language/lux/synthesis.lux | 2 +- .../library/lux/tool/compiler/meta/archive.lux | 4 +- .../lux/tool/compiler/meta/cache/dependency.lux | 4 +- .../library/lux/tool/compiler/meta/io/archive.lux | 2 +- .../lux/tool/compiler/meta/packager/jvm.lux | 6 +- .../lux/tool/compiler/meta/packager/scheme.lux | 2 +- stdlib/source/library/lux/tool/compiler/phase.lux | 8 +- stdlib/source/library/lux/tool/interpreter.lux | 10 +- stdlib/source/library/lux/type.lux | 16 +- stdlib/source/library/lux/type/abstract.lux | 166 ++++---- stdlib/source/library/lux/type/check.lux | 24 +- stdlib/source/library/lux/type/dynamic.lux | 14 +- stdlib/source/library/lux/type/implicit.lux | 98 ++--- stdlib/source/library/lux/type/quotient.lux | 28 +- stdlib/source/library/lux/type/refinement.lux | 26 +- stdlib/source/library/lux/type/resource.lux | 82 ++-- stdlib/source/library/lux/type/unit.lux | 28 +- stdlib/source/library/lux/type/variance.lux | 6 +- stdlib/source/library/lux/world/console.lux | 6 + stdlib/source/library/lux/world/db/jdbc.lux | 2 +- stdlib/source/library/lux/world/db/sql.lux | 4 +- stdlib/source/library/lux/world/file.lux | 22 +- stdlib/source/library/lux/world/file/watch.lux | 11 +- stdlib/source/library/lux/world/input/keyboard.lux | 2 + stdlib/source/library/lux/world/net.lux | 12 +- .../source/library/lux/world/net/http/client.lux | 58 ++- .../source/library/lux/world/net/http/cookie.lux | 2 +- stdlib/source/library/lux/world/net/http/query.lux | 2 +- .../source/library/lux/world/net/http/request.lux | 12 +- stdlib/source/library/lux/world/net/http/route.lux | 2 +- .../source/library/lux/world/net/http/status.lux | 23 +- stdlib/source/library/lux/world/net/uri.lux | 3 + .../library/lux/world/output/video/resolution.lux | 29 +- stdlib/source/library/lux/world/program.lux | 12 +- 258 files changed, 2918 insertions(+), 2812 deletions(-) create mode 100644 stdlib/source/library/lux/control/lazy.lux create mode 100644 stdlib/source/library/lux/control/maybe.lux delete mode 100644 stdlib/source/library/lux/data/lazy.lux delete mode 100644 stdlib/source/library/lux/data/maybe.lux (limited to 'stdlib/source/library') diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index 5e27a94c4..9034ba1fd 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -1752,7 +1752,7 @@ (identifier$ ["library/lux" "List"])))] (form$ (list (text$ "lux type check") type expression)))) -(def:''' .private (spliced replace? untemplate elems) +(def:''' .private (spliced replace? untemplated elems) #End (-> Bit (-> Code ($' Meta Code)) ($' List Code) ($' Meta Code)) ({#1 @@ -1766,7 +1766,7 @@ _ (do meta_monad - [lastO (untemplate lastI)] + [lastO (untemplated lastI)] (in (code_list (form$ (list (tag$ ["library/lux" "Item"]) (tuple$ (list lastO (tag$ ["library/lux" "End"]))))))))} lastI)] @@ -1780,7 +1780,7 @@ _ (do meta_monad - [leftO (untemplate leftI)] + [leftO (untemplated leftI)] (in (form$ (list (tag$ ["library/lux" "Item"]) (tuple$ (list leftO rightO))))))} leftI)) lastO @@ -1788,7 +1788,7 @@ (list\reverse elems)) #0 (do meta_monad - [=elems (monad\map meta_monad untemplate elems)] + [=elems (monad\map meta_monad untemplated elems)] (in (untemplated_list =elems)))} replace?)) @@ -1797,7 +1797,7 @@ (-> Text Code) (with_location (form$ (list (tag$ ["library/lux" "Text"]) (text$ value))))) -(def:''' .private (untemplate replace? subst token) +(def:''' .private (untemplated replace? subst token) #End (-> Bit Text Code ($' Meta Code)) ({[_ [_ (#Bit value)]] @@ -1853,24 +1853,24 @@ [#1 [_ (#Form (#Item [[_ (#Identifier ["" "~!"])] (#Item [dependent #End])]))]] (do meta_monad - [independent (untemplate replace? subst dependent)] + [independent (untemplated replace? subst dependent)] (in (with_location (form$ (list (tag$ ["library/lux" "Form"]) (untemplated_list (list (untemplated_text "lux in-module") (untemplated_text subst) independent))))))) [#1 [_ (#Form (#Item [[_ (#Identifier ["" "~'"])] (#Item [keep_quoted #End])]))]] - (untemplate #0 subst keep_quoted) + (untemplated #0 subst keep_quoted) [_ [meta (#Form elems)]] (do meta_monad - [output (spliced replace? (untemplate replace? subst) elems) + [output (spliced replace? (untemplated replace? subst) elems) .let' [[_ output'] (with_location (form$ (list (tag$ ["library/lux" "Form"]) output)))]] (in [meta output'])) [_ [meta (#Tuple elems)]] (do meta_monad - [output (spliced replace? (untemplate replace? subst) elems) + [output (spliced replace? (untemplated replace? subst) elems) .let' [[_ output'] (with_location (form$ (list (tag$ ["library/lux" "Tuple"]) output)))]] (in [meta output'])) @@ -1881,8 +1881,8 @@ (function' [kv] (let' [[k v] kv] (do meta_monad - [=k (untemplate replace? subst k) - =v (untemplate replace? subst v)] + [=k (untemplated replace? subst k) + =v (untemplated replace? subst v)] (in (tuple$ (list =k =v))))))) fields)] (in (with_location (form$ (list (tag$ ["library/lux" "Record"]) (untemplated_list =fields))))))} @@ -1928,7 +1928,7 @@ ({(#Item template #End) (do meta_monad [current_module current_module_name - =template (untemplate #1 current_module template)] + =template (untemplated #1 current_module template)] (in (list (form$ (list (text$ "lux type check") (identifier$ ["library/lux" "Code"]) =template))))) @@ -1944,7 +1944,7 @@ "(`' (def: (~ name) (function (_ (~+ args)) (~ body))))"))]) ({(#Item template #End) (do meta_monad - [=template (untemplate #1 "" template)] + [=template (untemplated #1 "" template)] (in (list (form$ (list (text$ "lux type check") (identifier$ ["library/lux" "Code"]) =template))))) _ @@ -1958,7 +1958,7 @@ "(' YOLO)"))]) ({(#Item template #End) (do meta_monad - [=template (untemplate #0 "" template)] + [=template (untemplated #0 "" template)] (in (list (form$ (list (text$ "lux type check") (identifier$ ["library/lux" "Code"]) =template))))) _ @@ -1969,9 +1969,9 @@ (list [(tag$ ["library/lux" "doc"]) (text$ ($_ "lux text concat" "... Piping macro." __paragraph - "(|> elems (list\map int\encode) (interpose '' '') (fold text\compose ''''))" __paragraph + "(|> elems (list\map int\encode) (interposed '' '') (fold text\compose ''''))" __paragraph "... =>" __paragraph - "(fold text\compose '''' (interpose '' '' (list\map int\encode elems)))"))]) + "(fold text\compose '''' (interposed '' '' (list\map int\encode elems)))"))]) ({(#Item [init apps]) (in_meta (list (list\fold ("lux type check" (-> Code Code Code) (function' [app acc] @@ -1995,9 +1995,9 @@ (list [(tag$ ["library/lux" "doc"]) (text$ ($_ "lux text concat" "... Reverse piping macro." __paragraph - "(<| (fold text\compose '''') (interpose '' '') (list\map int\encode) elems)" __paragraph + "(<| (fold text\compose '''') (interposed '' '') (list\map int\encode) elems)" __paragraph "... =>" __paragraph - "(fold text\compose '''' (interpose '' '' (list\map int\encode elems)))"))]) + "(fold text\compose '''' (interposed '' '' (list\map int\encode elems)))"))]) ({(#Item [init apps]) (in_meta (list (list\fold ("lux type check" (-> Code Code Code) (function' [app acc] @@ -2064,7 +2064,7 @@ #None} tuple)) -(def:''' .private (apply_template env template) +(def:''' .private (realized_template env template) #End (-> Replacement_Environment Code Code) ({[_ (#Identifier "" sname)] @@ -2076,16 +2076,16 @@ (..replacement sname env)) [meta (#Tuple elems)] - [meta (#Tuple (list\map (apply_template env) elems))] + [meta (#Tuple (list\map (realized_template env) elems))] [meta (#Form elems)] - [meta (#Form (list\map (apply_template env) elems))] + [meta (#Form (list\map (realized_template env) elems))] [meta (#Record members)] [meta (#Record (list\map ("lux type check" (-> (Tuple Code Code) (Tuple Code Code)) (function' [kv] (let' [[slot value] kv] - [(apply_template env slot) (apply_template env value)]))) + [(realized_template env slot) (realized_template env value)]))) members))] _ @@ -2150,7 +2150,7 @@ ({(#Item [[_ (#Tuple bindings)] (#Item [[_ (#Tuple templates)] data])]) ({[(#Some bindings') (#Some data')] (let' [apply ("lux type check" (-> Replacement_Environment ($' List Code)) - (function' [env] (list\map (apply_template env) templates))) + (function' [env] (list\map (realized_template env) templates))) num_bindings (list\size bindings')] (if (every? (function' [size] ("lux i64 =" num_bindings size)) (list\map list\size data')) @@ -2348,7 +2348,7 @@ #None #0} output)))) -(def:''' .private (interpose sep xs) +(def:''' .private (list\interposed sep xs) #End (All [a] (-> a ($' List a) ($' List a))) @@ -2359,7 +2359,7 @@ xs (#Item [x xs']) - (list& x sep (interpose sep xs'))} + (list& x sep (list\interposed sep xs'))} xs)) (def:''' .private (single_expansion token) @@ -2591,7 +2591,7 @@ (failure "Improper type-definition syntax")} type_codes)) -(def:''' .private (gensym prefix state) +(def:''' .private (identifier prefix state) #End (-> Text ($' Meta Code)) ({{#info info #source source #current_module _ #modules modules @@ -2721,14 +2721,14 @@ [_ (#Form xs)] ($_ text\compose "(" (|> xs (list\map code\encode) - (interpose " ") + (list\interposed " ") list\reverse (list\fold text\compose "")) ")") [_ (#Tuple xs)] ($_ text\compose "[" (|> xs (list\map code\encode) - (interpose " ") + (list\interposed " ") list\reverse (list\fold text\compose "")) "]") @@ -2736,7 +2736,7 @@ ($_ text\compose "{" (|> kvs (list\map (function' [kv] ({[k v] ($_ text\compose (code\encode k) " " (code\encode v))} kv))) - (interpose " ") + (list\interposed " ") list\reverse (list\fold text\compose "")) "}")} code)) @@ -2769,7 +2769,7 @@ _ (failure ($_ text\compose "'lux.case' expects an even number of tokens: " (|> branches (list\map code\encode) - (interpose " ") + (list\interposed " ") list\reverse (list\fold text\compose ""))))} branches)) @@ -3090,7 +3090,7 @@ (case tokens (^ (list else then)) (do meta_monad - [g!_ (gensym "g!_")] + [g!_ (..identifier "g!_")] (in (list (` (..case (~ then) (#..Some (~ g!_)) (#..Some (~ g!_)) @@ -3313,10 +3313,10 @@ (-> Text Text (Maybe Nat)) ("lux text index" 0 part text)) -(def: .public (error! message) +(def: .public (panic! message) {#.doc (text$ ($_ "lux text concat" "... Causes an error, with the given error message." ..\n - "(error! ''OH NO!'')"))} + "(panic! ''OH NO!'')"))} (-> Text Nothing) ("lux io error" message)) @@ -3745,7 +3745,7 @@ {#.doc (text$ ($_ "lux text concat" "... The type-definition macro." ..\n "(type: (List a)" ..\n - " {#.doc (doc (: (List Nat) (list 0 1 2 3)))}" ..\n + " {#.doc (example (: (List Nat) (list 0 1 2 3)))}" ..\n " #End" ..\n " (#Item a (List a)))"))} (case (typeP tokens) @@ -4022,7 +4022,7 @@ _ #.None)) -(def: (count_relatives relatives input) +(def: (relative_ups relatives input) (-> Nat Text Nat) (case ("lux text index" relatives ..module_separator input) #None @@ -4030,7 +4030,7 @@ (#Some found) (if ("lux i64 =" relatives found) - (count_relatives ("lux i64 +" 1 relatives) input) + (relative_ups ("lux i64 +" 1 relatives) input) relatives))) (def: (list\take amount list) @@ -4053,7 +4053,7 @@ (def: (absolute_module_name nested? relative_root module) (-> Bit Text Text (Meta Text)) - (case (count_relatives 0 module) + (case (relative_ups 0 module) 0 (in_meta (if nested? ($_ "lux text concat" relative_root ..module_separator module) @@ -4067,7 +4067,7 @@ list\reverse (list\drop jumps) list\reverse - (interpose ..module_separator) + (list\interposed ..module_separator) (text\join_with "")) clean ("lux text clip" relatives (|> module "lux text size" ("lux i64 -" relatives)) module) output (case ("lux text size" clean) @@ -4370,16 +4370,16 @@ name _ - ($_ text\compose "(" name " " (|> params (list\map type\encode) (interpose " ") list\reverse (list\fold text\compose "")) ")")) + ($_ text\compose "(" name " " (|> params (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) ")")) (#Sum _) - ($_ text\compose "(Or " (|> (flat_variant type) (list\map type\encode) (interpose " ") list\reverse (list\fold text\compose "")) ")") + ($_ text\compose "(Or " (|> (flat_variant type) (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) ")") (#Product _) - ($_ text\compose "[" (|> (flat_tuple type) (list\map type\encode) (interpose " ") list\reverse (list\fold text\compose "")) "]") + ($_ text\compose "[" (|> (flat_tuple type) (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) "]") (#Function _) - ($_ text\compose "(-> " (|> (flat_lambda type) (list\map type\encode) (interpose " ") list\reverse (list\fold text\compose "")) ")") + ($_ text\compose "(-> " (|> (flat_lambda type) (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) ")") (#Parameter id) (nat\encode id) @@ -4400,7 +4400,7 @@ (let [[func args] (flat_application type)] ($_ text\compose "(" (type\encode func) " " - (|> args (list\map type\encode) (interpose " ") list\reverse (list\fold text\compose "")) + (|> args (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) ")")) (#Named name _) @@ -4417,7 +4417,7 @@ (case tokens (^ (list& [_ (#Form (list [_ (#Text alias)]))] body branches)) (do meta_monad - [g!temp (gensym "temp")] + [g!temp (..identifier "temp")] (in (list& g!temp (` (..^open (~ g!temp) (~ (text$ alias)) (~ body))) branches))) (^ (list [_ (#Identifier name)] [_ (#Text alias)] body)) @@ -4510,8 +4510,8 @@ [slot (normal slot') output (..type_tag slot) .let [[idx tags exported? type] output] - g!_ (gensym "_") - g!output (gensym "")] + g!_ (..identifier "_") + g!output (..identifier "")] (case (interface_methods type) (#Some members) (let [pattern (record$ (list\map (: (-> [Name [Nat Type]] [Code Code]) @@ -4535,8 +4535,8 @@ (^ (list selector)) (do meta_monad - [g!_ (gensym "_") - g!record (gensym "record")] + [g!_ (..identifier "_") + g!record (..identifier "record")] (in (list (` (function ((~ g!_) (~ g!record)) (..get@ (~ selector) (~ g!record))))))) _ @@ -4546,7 +4546,7 @@ (-> Text (List Name) Nat Name Code Type (Meta (List Code))) (do meta_monad [output (record_slots type) - g!_ (gensym "g!_") + g!_ (..identifier "g!_") .let [g!output (local_identifier$ short) pattern (|> tags enumeration @@ -4606,7 +4606,7 @@ _ (do meta_monad - [g!struct (gensym "struct")] + [g!struct (..identifier "struct")] (in_meta (list (` ("lux def" (~ g!struct) (~ struct) [(~ location_code) (#.Record #End)] #0)) @@ -4618,23 +4618,23 @@ (macro: .public (|>> tokens) {#.doc (text$ ($_ "lux text concat" "... Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it." ..\n - "(|>> (list\map int\encode) (interpose '' '') (fold text\compose ''''))" ..\n + "(|>> (list\map int\encode) (interposed '' '') (fold text\compose ''''))" ..\n "... =>" ..\n - "(function (_ ) (fold text\compose '''' (interpose '' '' (list\map int\encode ))))"))} + "(function (_ ) (fold text\compose '''' (interposed '' '' (list\map int\encode ))))"))} (do meta_monad - [g!_ (gensym "_") - g!arg (gensym "arg")] + [g!_ (..identifier "_") + g!arg (..identifier "arg")] (in_meta (list (` (function ((~ g!_) (~ g!arg)) (|> (~ g!arg) (~+ tokens)))))))) (macro: .public (<<| tokens) {#.doc (text$ ($_ "lux text concat" "... Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it." ..\n - "(<<| (fold text\compose '''') (interpose '' '') (list\map int\encode))" ..\n + "(<<| (fold text\compose '''') (interposed '' '') (list\map int\encode))" ..\n "... =>" ..\n - "(function (_ ) (fold text\compose '''' (interpose '' '' (list\map int\encode ))))"))} + "(function (_ ) (fold text\compose '''' (interposed '' '' (list\map int\encode ))))"))} (do meta_monad - [g!_ (gensym "_") - g!arg (gensym "arg")] + [g!_ (..identifier "_") + g!arg (..identifier "arg")] (in_meta (list (` (function ((~ g!_) (~ g!arg)) (<| (~+ tokens) (~ g!arg)))))))) (def: (imported_by? import_name module_name) @@ -4661,7 +4661,7 @@ (failure ($_ text\compose "Wrong syntax for refer @ " current_module ..\n (|> options (list\map code\encode) - (interpose " ") + (list\interposed " ") (list\fold text\compose ""))))))) (def: (referral_definitions module_name [r_defs r_opens]) @@ -4831,7 +4831,7 @@ (: (-> [Name [Nat Type]] (Meta [Name Nat Code])) (function (_ [r_slot_name [r_idx r_type]]) (do meta_monad - [g!slot (gensym "")] + [g!slot (..identifier "")] (in_meta [r_slot_name r_idx g!slot])))) (zipped/2 tags (enumeration members)))] (let [pattern (record$ (list\map (: (-> [Name Nat Code] [Code Code]) @@ -4860,7 +4860,7 @@ (do meta_monad [bindings (monad\map meta_monad (: (-> Code (Meta Code)) - (function (_ _) (gensym "temp"))) + (function (_ _) (..identifier "temp"))) slots) .let [pairs (zipped/2 slots bindings) update_expr (list\fold (: (-> [Code Code] Code Code) @@ -4880,16 +4880,16 @@ (^ (list selector value)) (do meta_monad - [g!_ (gensym "_") - g!record (gensym "record")] + [g!_ (..identifier "_") + g!record (..identifier "record")] (in (list (` (function ((~ g!_) (~ g!record)) (..set@ (~ selector) (~ value) (~ g!record))))))) (^ (list selector)) (do meta_monad - [g!_ (gensym "_") - g!value (gensym "value") - g!record (gensym "record")] + [g!_ (..identifier "_") + g!value (..identifier "value") + g!record (..identifier "record")] (in (list (` (function ((~ g!_) (~ g!value) (~ g!record)) (..set@ (~ selector) (~ g!value) (~ g!record))))))) @@ -4920,7 +4920,7 @@ (: (-> [Name [Nat Type]] (Meta [Name Nat Code])) (function (_ [r_slot_name [r_idx r_type]]) (do meta_monad - [g!slot (gensym "")] + [g!slot (..identifier "")] (in_meta [r_slot_name r_idx g!slot])))) (zipped/2 tags (enumeration members)))] (let [pattern (record$ (list\map (: (-> [Name Nat Code] [Code Code]) @@ -4947,24 +4947,24 @@ _ (do meta_monad - [g!record (gensym "record") - g!temp (gensym "temp")] + [g!record (..identifier "record") + g!temp (..identifier "temp")] (in (list (` (let [(~ g!record) (~ record) (~ g!temp) (get@ [(~+ slots)] (~ g!record))] (set@ [(~+ slots)] ((~ fun) (~ g!temp)) (~ g!record)))))))) (^ (list selector fun)) (do meta_monad - [g!_ (gensym "_") - g!record (gensym "record")] + [g!_ (..identifier "_") + g!record (..identifier "record")] (in (list (` (function ((~ g!_) (~ g!record)) (..update@ (~ selector) (~ fun) (~ g!record))))))) (^ (list selector)) (do meta_monad - [g!_ (gensym "_") - g!fun (gensym "fun") - g!record (gensym "record")] + [g!_ (..identifier "_") + g!fun (..identifier "fun") + g!record (..identifier "record")] (in (list (` (function ((~ g!_) (~ g!fun) (~ g!record)) (..update@ (~ selector) (~ g!fun) (~ g!record))))))) @@ -5019,7 +5019,7 @@ (if (every? (|>> ("lux i64 =" num_bindings)) (list\map list\size data')) (let [apply (: (-> Replacement_Environment (List Code)) - (function (_ env) (list\map (apply_template env) templates)))] + (function (_ env) (list\map (realized_template env) templates)))] (|> data' (list\map (compose apply (replacement_environment bindings'))) list\join @@ -5106,11 +5106,11 @@ (-> Text Nat) ("lux text size" x)) -(def: (update_location [file line column] code_text) +(def: (updated_location [file line column] code_text) (-> Location Text Location) [file line ("lux i64 +" column (text\size code_text))]) -(def: (delim_update_location [file line column]) +(def: (delimiter_updated_location [file line column]) (-> Location Location) [file line (inc column)]) @@ -5129,7 +5129,7 @@ (^template [ ] [[new_location ( value)] (let [as_text ( value)] - [(update_location new_location as_text) + [(updated_location new_location as_text) (text\compose (location_padding baseline prev_location new_location) as_text)])]) ([#Bit bit\encode] @@ -5145,9 +5145,9 @@ (let [[group_location' parts_text] (list\fold (function (_ part [last_location text_accum]) (let [[part_location part_text] (example_documentation last_location baseline part)] [part_location (text\compose text_accum part_text)])) - [(delim_update_location group_location) ""] + [(delimiter_updated_location group_location) ""] ( parts))] - [(delim_update_location group_location') + [(delimiter_updated_location group_location') ($_ text\compose (location_padding baseline prev_location group_location) parts_text @@ -5179,18 +5179,18 @@ [_ text] (..example_documentation (with_baseline baseline location) baseline example)] (text\compose text __paragraph)))) -(macro: .public (doc tokens) +(macro: .public (example tokens) {#.doc (text$ ($_ "lux text concat" "... Creates code documentation, embedding text as comments and properly formatting the forms it's being given." __paragraph "... For Example:" ..\n - "(doc ''Allows arbitrary looping, using the 'recur' form to re-start the loop.''" ..\n - " ''Can be used in monadic code to create monadic loops.''" ..\n - " (loop [count +0" ..\n - " x init]" ..\n - " (if (< +10 count)" ..\n - " (recur (inc count) (f x))" ..\n - " x)))"))} + "(example ''Allows arbitrary looping, using the 'recur' form to re-start the loop.''" ..\n + " ''Can be used in monadic code to create monadic loops.''" ..\n + " (loop [count +0" ..\n + " x init]" ..\n + " (if (< +10 count)" ..\n + " (recur (inc count) (f x))" ..\n + " x)))"))} (in_meta (list (` [(~ location_code) (#.Text (~ (|> tokens (list\map (|>> ..documentation_fragment ..fragment_documentation)) @@ -5243,21 +5243,21 @@ (identifier$ [module name]))) (macro: .public (loop tokens) - {#.doc (doc "Allows arbitrary looping, using the 'recur' form to re-start the loop." - "Can be used in monadic code to create monadic loops." - (loop [count +0 + {#.doc (example "Allows arbitrary looping, using the 'recur' form to re-start the loop." + "Can be used in monadic code to create monadic loops." + (loop [count +0 + x init] + (if (< +10 count) + (recur (inc count) (f x)) + x)) + + "Loops can also be given custom names." + (loop my_loop + [count +0 x init] - (if (< +10 count) - (recur (inc count) (f x)) - x)) - - "Loops can also be given custom names." - (loop my_loop - [count +0 - x init] - (if (< +10 count) - (my_loop (inc count) (f x)) - x)))} + (if (< +10 count) + (my_loop (inc count) (f x)) + x)))} (let [?params (case tokens (^ (list name [_ (#Tuple bindings)] body)) (#.Some [name bindings body]) @@ -5289,7 +5289,7 @@ (do meta_monad [aliases (monad\map meta_monad (: (-> Code (Meta Code)) - (function (_ _) (gensym ""))) + (function (_ _) (..identifier ""))) inits)] (in_meta (list (` (let [(~+ (..interleaved aliases inits))] (.loop (~ name) @@ -5300,10 +5300,10 @@ (failure "Wrong syntax for loop")))) (macro: .public (^slots tokens) - {#.doc (doc "Allows you to extract record members as local variables with the same names." - "For example:" - (let [(^slots [#foo #bar #baz]) quux] - (f foo bar baz)))} + {#.doc (example "Allows you to extract record members as local variables with the same names." + "For example:" + (let [(^slots [#foo #bar #baz]) quux] + (f foo bar baz)))} (case tokens (^ (list& [_ (#Form (list [_ (#Tuple (list& hslot' tslots'))]))] body branches)) (do meta_monad @@ -5322,7 +5322,7 @@ hslot (..normal hslot) tslots (monad\map meta_monad ..normal tslots) output (..type_tag hslot) - g!_ (gensym "_") + g!_ (..identifier "_") .let [[idx tags exported? type] output slot_pairings (list\map (: (-> Name [Text Code]) (function (_ [module name]) @@ -5378,25 +5378,25 @@ (in (list [location (#Record =pairs)]))))) (macro: .public (with_expansions tokens) - {#.doc (doc "Controlled macro-expansion." - "Bind an arbitraty number of Code nodes resulting from macro-expansion to local bindings." - "Wherever a binding appears, the bound Code nodes will be spliced in there." - (test: "Code operations & implementations" - (with_expansions - [ (template [ ] - [(compare (\ Code/encode encode ))] - - [(bit #1) "#1"] - [(int +123) "+123"] - [(frac +123.0) "+123.0"] - [(text "123") "'123'"] - [(tag ["yolo" "lol"]) "#yolo.lol"] - [(identifier ["yolo" "lol"]) "yolo.lol"] - [(form (list (bit #1))) "(#1)"] - [(tuple (list (bit #1))) "[#1]"] - [(record (list [(bit #1) (int +123)])) "{#1 +123}"] - )] - (test_all ))))} + {#.doc (example "Controlled macro-expansion." + "Bind an arbitraty number of Code nodes resulting from macro-expansion to local bindings." + "Wherever a binding appears, the bound Code nodes will be spliced in there." + (test: "Code operations & implementations" + (with_expansions + [ (template [ ] + [(compare (\ Code/encode encode ))] + + [(bit #1) "#1"] + [(int +123) "+123"] + [(frac +123.0) "+123.0"] + [(text "123") "'123'"] + [(tag ["yolo" "lol"]) "#yolo.lol"] + [(identifier ["yolo" "lol"]) "yolo.lol"] + [(form (list (bit #1))) "(#1)"] + [(tuple (list (bit #1))) "[#1]"] + [(record (list [(bit #1) (int +123)])) "{#1 +123}"] + )] + (test_all ))))} (case tokens (^ (list& [_ (#Tuple bindings)] bodies)) (case bindings @@ -5550,26 +5550,26 @@ (list init_pattern inner_pattern_body))) (macro: .public (^multi tokens) - {#.doc (doc "Multi-level pattern matching." - "Useful in situations where the result of a branch depends on further refinements on the values being matched." - "For example:" - (case (split (size static) uri) - (^multi (#.Some [chunk uri']) - {(text\= static chunk) #1}) - (match_uri endpoint? parts' uri') + {#.doc (example "Multi-level pattern matching." + "Useful in situations where the result of a branch depends on further refinements on the values being matched." + "For example:" + (case (split (size static) uri) + (^multi (#.Some [chunk uri']) + {(text\= static chunk) #1}) + (match_uri endpoint? parts' uri') - _ - (#.Left (format "Static part " (%t static) " does not match URI: " uri))) + _ + (#.Left (format "Static part " (%t static) " does not match URI: " uri))) - "Short-cuts can be taken when using bit tests." - "The example above can be rewritten as..." - (case (split (size static) uri) - (^multi (#.Some [chunk uri']) - (text\= static chunk)) - (match_uri endpoint? parts' uri') + "Short-cuts can be taken when using bit tests." + "The example above can be rewritten as..." + (case (split (size static) uri) + (^multi (#.Some [chunk uri']) + (text\= static chunk)) + (match_uri endpoint? parts' uri') - _ - (#.Left (format "Static part " (%t static) " does not match URI: " uri))))} + _ + (#.Left (format "Static part " (%t static) " does not match URI: " uri))))} (case tokens (^ (list& [_meta (#Form levels)] body next_branches)) (do meta_monad @@ -5581,7 +5581,7 @@ _ #0)] expected get_expected_type - g!temp (gensym "temp")] + g!temp (..identifier "temp")] (let [output (list g!temp (` ({(#Some (~ g!temp)) (~ g!temp) @@ -5610,10 +5610,10 @@ (text\compose "Wrong syntax for "))) (macro: .public (name_of tokens) - {#.doc (doc "Given an identifier or a tag, gives back a 2 tuple with the module and name parts, both as Text." - (name_of #.doc) - "=>" - ["library/lux" "doc"])} + {#.doc (example "Given an identifier or a tag, gives back a 2 tuple with the module and name parts, both as Text." + (name_of #.doc) + "=>" + ["library/lux" "doc"])} (case tokens (^template [] [(^ (list [_ ( [module name])])) @@ -5634,14 +5634,14 @@ )) (macro: .public (:parameter tokens) - {#.doc (doc "Allows you to refer to the type-variables in a polymorphic function's type, by their index." - "In the example below, 0 corresponds to the 'a' variable." - (def: .public (of_list list) - (All [a] (-> (List a) (Row a))) - (list\fold add - (: (Row (:parameter 0)) - empty) - list)))} + {#.doc (example "Allows you to refer to the type-variables in a polymorphic function's type, by their index." + "In the example below, 0 corresponds to the 'a' variable." + (def: .public (of_list list) + (All [a] (-> (List a) (Row a))) + (list\fold add + (: (Row (:parameter 0)) + empty) + list)))} (case tokens (^ (list [_ (#Nat idx)])) (do meta_monad @@ -5657,22 +5657,22 @@ (failure (..wrong_syntax_error (name_of ..$))))) (def: .public (is? reference sample) - {#.doc (doc "Tests whether the 2 values are identical (not just 'equal')." - "This one should succeed:" - (let [value +5] - (is? value value)) + {#.doc (example "Tests whether the 2 values are identical (not just 'equal')." + "This one should succeed:" + (let [value +5] + (is? value value)) - "This one should fail:" - (is? +5 (+ +2 +3)))} + "This one should fail:" + (is? +5 (+ +2 +3)))} (All [a] (-> a a Bit)) ("lux is" reference sample)) (macro: .public (^@ tokens) - {#.doc (doc "Allows you to simultaneously bind and de-structure a value." - (def: (hash (^@ set [Hash _])) - (list\fold (function (_ elem acc) (+ (\ Hash hash elem) acc)) - 0 - (to_list set))))} + {#.doc (example "Allows you to simultaneously bind and de-structure a value." + (def: (hash (^@ set [Hash _])) + (list\fold (function (_ elem acc) (+ (\ Hash hash elem) acc)) + 0 + (to_list set))))} (case tokens (^ (list& [_meta (#Form (list [_ (#Identifier ["" name])] pattern))] body branches)) (let [g!whole (local_identifier$ name)] @@ -5684,10 +5684,10 @@ (failure (..wrong_syntax_error (name_of ..^@))))) (macro: .public (^|> tokens) - {#.doc (doc "Pipes the value being pattern-matched against prior to binding it to a variable." - (case input - (^|> value [inc (% 10) (max 1)]) - (foo value)))} + {#.doc (example "Pipes the value being pattern-matched against prior to binding it to a variable." + (case input + (^|> value [inc (% 10) (max 1)]) + (foo value)))} (case tokens (^ (list& [_meta (#Form (list [_ (#Identifier ["" name])] [_ (#Tuple steps)]))] body branches)) (let [g!name (local_identifier$ name)] @@ -5700,8 +5700,8 @@ (failure (..wrong_syntax_error (name_of ..^|>))))) (macro: .public (:assume tokens) - {#.doc (doc "Coerces the given expression to the type of whatever is expected." - (: Dinosaur (:assume (list +1 +2 +3))))} + {#.doc (example "Coerces the given expression to the type of whatever is expected." + (: Dinosaur (:assume (list +1 +2 +3))))} (case tokens (^ (list expr)) (do meta_monad @@ -5718,12 +5718,12 @@ (#Right [compiler (get@ #location compiler)]))) (macro: .public (undefined tokens) - {#.doc (doc "Meant to be used as a stand-in for functions with undefined implementations." - "Undefined expressions will type-check against everything, so they make good dummy implementations." - "However, if an undefined expression is ever evaluated, it will raise a runtime error." - (def: (square x) - (-> Int Int) - (undefined)))} + {#.doc (example "Meant to be used as a stand-in for functions with undefined implementations." + "Undefined expressions will type-check against everything, so they make good dummy implementations." + "However, if an undefined expression is ever evaluated, it will raise a runtime error." + (def: (square x) + (-> Int Int) + (undefined)))} (case tokens #End (do meta_monad @@ -5731,23 +5731,23 @@ .let [[module line column] location location ($_ "lux text concat" (text\encode module) "," (nat\encode line) "," (nat\encode column)) message ($_ "lux text concat" "Undefined behavior @ " location)]] - (in (list (` (..error! (~ (text$ message))))))) + (in (list (` (..panic! (~ (text$ message))))))) _ (failure (..wrong_syntax_error (name_of ..undefined))))) (macro: .public (:of tokens) - {#.doc (doc "Generates the type corresponding to a given expression." - "Example #1:" - (let [my_num +123] - (:of my_num)) - "==" - Int - "-------------------" - "Example #2:" - (:of +123) - "==" - Int)} + {#.doc (example "Generates the type corresponding to a given expression." + "Example #1:" + (let [my_num +123] + (:of my_num)) + "==" + Int + "-------------------" + "Example #2:" + (:of +123) + "==" + Int)} (case tokens (^ (list [_ (#Identifier var_name)])) (do meta_monad @@ -5756,7 +5756,7 @@ (^ (list expression)) (do meta_monad - [g!temp (gensym "g!temp")] + [g!temp (..identifier "g!temp")] (in (list (` (let [(~ g!temp) (~ expression)] (..:of (~ g!temp))))))) @@ -5804,16 +5804,16 @@ )) (macro: .public (template: tokens) - {#.doc (doc "Define macros in the style of template and ^template." - "For simple macros that do not need any fancy features." - (template: (square x) - (* x x)))} + {#.doc (example "Define macros in the style of template and ^template." + "For simple macros that do not need any fancy features." + (template: (square x) + (* x x)))} (case (templateP tokens) (#.Some [export_policy name args anns input_templates]) (do meta_monad - [g!tokens (gensym "tokens") - g!compiler (gensym "compiler") - g!_ (gensym "_") + [g!tokens (..identifier "tokens") + g!compiler (..identifier "compiler") + g!_ (..identifier "_") .let [rep_env (list\map (function (_ arg) [arg (` ((~' ~) (~ (local_identifier$ arg))))]) args)] @@ -5924,7 +5924,7 @@ (case code (^ [ann (#Form (list [_ (#Identifier ["" "~~"])] expansion))]) (do meta_monad - [g!expansion (gensym "g!expansion")] + [g!expansion (..identifier "g!expansion")] (in [(list [g!expansion expansion]) g!expansion])) (^template [] @@ -6015,7 +6015,7 @@ (def: (untemplated_pattern pattern) (-> Code (Meta Code)) (do meta_monad - [g!meta (gensym "g!meta")] + [g!meta (..identifier "g!meta")] (case pattern (^template [ ] [[_ ( value)] @@ -6035,9 +6035,9 @@ [_ (#Form (#Item [[_ (#Identifier ["" "~+"])] (#Item [spliced #End])]))] (failure "Cannot use (~+) inside of ^code unless it is the last element in a form or a tuple.") - (^template [ ] + (^template [ ] [[_ ( elems)] - ( g!meta untemplated_pattern elems)]) + ( g!meta untemplated_pattern elems)]) ([#.Tuple ..untemplated_tuple] [#.Form ..untemplated_form]) @@ -6084,16 +6084,16 @@ (..failure (..wrong_syntax_error (name_of ..:let))))) (macro: .public (try tokens) - {#.doc (doc (case (try (risky_computation input)) - (#.Right success) - (do_something success) + {#.doc (example (case (try (risky_computation input)) + (#.Right success) + (do_something success) - (#.Left error) - (recover_from_failure error)))} + (#.Left error) + (recover_from_failure error)))} (case tokens (^ (list expression)) (do meta_monad - [g!_ (gensym "g!_")] + [g!_ (..identifier "g!_")] (in (list (` ("lux try" (.function ((~ g!_) (~ g!_)) (~ expression))))))) diff --git a/stdlib/source/library/lux/abstract/comonad.lux b/stdlib/source/library/lux/abstract/comonad.lux index 589ed47f2..6de44d5f2 100644 --- a/stdlib/source/library/lux/abstract/comonad.lux +++ b/stdlib/source/library/lux/abstract/comonad.lux @@ -13,8 +13,8 @@ [functor (#+ Functor)]]) (interface: .public (CoMonad w) - {#.doc (doc "CoMonads are the opposite/complement to monads." - "CoMonadic structures are often infinite in size and built upon lazily-evaluated functions.")} + {#.doc (example "CoMonads are the opposite/complement to monads." + "CoMonadic structures are often infinite in size and built upon lazily-evaluated functions.")} (: (Functor w) &functor) (: (All [a] @@ -25,11 +25,11 @@ split)) (macro: .public (be tokens state) - {#.doc (doc "A co-monadic parallel to the 'do' macro." - (let [square (function (_ n) (* n n))] - (be comonad - [inputs (iterate inc +2)] - (square (head inputs)))))} + {#.doc (example "A co-monadic parallel to the 'do' macro." + (let [square (function (_ n) (* n n))] + (be comonad + [inputs (iterate inc +2)] + (square (head inputs)))))} (case (: (Maybe [(Maybe Text) Code (List Code) Code]) (case tokens (^ (list [_ (#.Record (list [[_ (#.Identifier ["" name])] comonad]))] [_ (#.Tuple bindings)] body)) @@ -43,11 +43,11 @@ (#.Some [?name comonad bindings body]) (if (|> bindings list.size (n.% 2) (n.= 0)) (let [[module short] (name_of ..be) - gensym (: (-> Text Code) - (|>> ($_ "lux text concat" module " " short " ") [""] #.Identifier [location.dummy])) - g!_ (gensym "_") - g!map (gensym "map") - g!split (gensym "split") + identifier (: (-> Text Code) + (|>> ($_ "lux text concat" module " " short " ") [""] #.Identifier [location.dummy])) + g!_ (identifier "_") + g!map (identifier "map") + g!split (identifier "split") body' (list\fold (: (-> [Code Code] Code Code) (function (_ binding body') (with_expansions [ (` (|> (~ value) (~ g!split) ((~ g!map) (function ((~ g!_) (~ var)) (~ body')))))] diff --git a/stdlib/source/library/lux/abstract/comonad/cofree.lux b/stdlib/source/library/lux/abstract/comonad/cofree.lux index 271795e14..1431ee3cc 100644 --- a/stdlib/source/library/lux/abstract/comonad/cofree.lux +++ b/stdlib/source/library/lux/abstract/comonad/cofree.lux @@ -6,7 +6,7 @@ [functor (#+ Functor)]]]) (type: .public (CoFree F a) - {#.doc (doc "The CoFree CoMonad.")} + {#.doc "The CoFree CoMonad."} [a (F (CoFree F a))]) (implementation: .public (functor dsl) diff --git a/stdlib/source/library/lux/abstract/equivalence.lux b/stdlib/source/library/lux/abstract/equivalence.lux index 7834363bf..ad3e90d00 100644 --- a/stdlib/source/library/lux/abstract/equivalence.lux +++ b/stdlib/source/library/lux/abstract/equivalence.lux @@ -11,7 +11,7 @@ =)) (def: .public (rec sub) - {#.doc (doc "A recursive equivalence combinator.")} + {#.doc (example "A recursive equivalence combinator.")} (All [a] (-> (-> (Equivalence a) (Equivalence a)) (Equivalence a))) (implementation (def: (= left right) diff --git a/stdlib/source/library/lux/abstract/fold.lux b/stdlib/source/library/lux/abstract/fold.lux index b2ce974da..1a7ba054f 100644 --- a/stdlib/source/library/lux/abstract/fold.lux +++ b/stdlib/source/library/lux/abstract/fold.lux @@ -11,7 +11,7 @@ fold)) (def: .public (with_monoid monoid fold value) - {#.doc (doc "Fold over a foldable structure using the monoid's identity as the initial value.")} + {#.doc "Fold over a foldable structure using the monoid's identity as the initial value."} (All [F a] (-> (Monoid a) (Fold F) (F a) a)) (let [(^open "/\.") monoid] diff --git a/stdlib/source/library/lux/abstract/functor.lux b/stdlib/source/library/lux/abstract/functor.lux index 32e1c6671..3d6e38883 100644 --- a/stdlib/source/library/lux/abstract/functor.lux +++ b/stdlib/source/library/lux/abstract/functor.lux @@ -15,7 +15,7 @@ (All [a] (.Or (f a) (g a)))) (def: .public (sum (^open "f\.") (^open "g\.")) - {#.doc (doc "Co-product (sum) composition for functors.")} + {#.doc (example "Co-product (sum) composition for functors.")} (All [F G] (-> (Functor F) (Functor G) (Functor (..Or F G)))) (implementation (def: (map f fa|ga) @@ -30,7 +30,7 @@ (All [a] (.And (f a) (g a)))) (def: .public (product (^open "f\.") (^open "g\.")) - {#.doc (doc "Product composition for functors.")} + {#.doc (example "Product composition for functors.")} (All [F G] (-> (Functor F) (Functor G) (Functor (..And F G)))) (implementation (def: (map f [fa ga]) diff --git a/stdlib/source/library/lux/abstract/functor/contravariant.lux b/stdlib/source/library/lux/abstract/functor/contravariant.lux index 659105afa..1cf16ce24 100644 --- a/stdlib/source/library/lux/abstract/functor/contravariant.lux +++ b/stdlib/source/library/lux/abstract/functor/contravariant.lux @@ -3,7 +3,7 @@ [lux #*]]) (interface: .public (Functor f) - {#.doc (doc "The contravariant functor.")} + {#.doc (example "The contravariant functor.")} (: (All [a b] (-> (-> b a) diff --git a/stdlib/source/library/lux/abstract/hash.lux b/stdlib/source/library/lux/abstract/hash.lux index 84f80723c..3a27317de 100644 --- a/stdlib/source/library/lux/abstract/hash.lux +++ b/stdlib/source/library/lux/abstract/hash.lux @@ -7,8 +7,8 @@ ["." contravariant]]]) (interface: .public (Hash a) - {#.doc (doc "A way to produce hash-codes for a type's instances." - "A necessity when working with some data-structures, such as dictionaries or sets.")} + {#.doc (example "A way to produce hash-codes for a type's instances." + "A necessity when working with some data-structures, such as dictionaries or sets.")} (: (Equivalence a) &equivalence) (: (-> a Nat) diff --git a/stdlib/source/library/lux/abstract/interval.lux b/stdlib/source/library/lux/abstract/interval.lux index acd7be087..5961039b9 100644 --- a/stdlib/source/library/lux/abstract/interval.lux +++ b/stdlib/source/library/lux/abstract/interval.lux @@ -26,7 +26,7 @@ (def: top top))) (def: .public (singleton enum elem) - {#.doc (doc "An interval where both top and bottom are the same value.")} + {#.doc (example "An interval where both top and bottom are the same value.")} (All [a] (-> (Enum a) a (Interval a))) (implementation (def: &enum enum) @@ -70,13 +70,13 @@ ) (def: .public (borders? interval elem) - {#.doc (doc "Where a value is at the border of an interval.")} + {#.doc (example "Where a value is at the border of an interval.")} (All [a] (-> (Interval a) a Bit)) (or (starts_with? elem interval) (ends_with? elem interval))) (implementation: .public (union left right) - {#.doc (doc "An interval that spans both predecessors.")} + {#.doc (example "An interval that spans both predecessors.")} (All [a] (-> (Interval a) (Interval a) (Interval a))) (def: &enum (get@ #&enum right)) @@ -84,7 +84,7 @@ (def: top (order.max (\ right &order) (\ left top) (\ right top)))) (implementation: .public (intersection left right) - {#.doc (doc "An interval spanned by both predecessors.")} + {#.doc (example "An interval spanned by both predecessors.")} (All [a] (-> (Interval a) (Interval a) (Interval a))) (def: &enum (get@ #&enum right)) @@ -92,7 +92,7 @@ (def: top (order.min (\ right &order) (\ left top) (\ right top)))) (implementation: .public (complement interval) - {#.doc (doc "The inverse of an interval.")} + {#.doc (example "The inverse of an interval.")} (All [a] (-> (Interval a) (Interval a))) (def: &enum (get@ #&enum interval)) @@ -122,7 +122,7 @@ ) (def: .public (meets? reference sample) - {#.doc (doc "Whether an interval meets another one on its bottom/lower side.")} + {#.doc (example "Whether an interval meets another one on its bottom/lower side.")} (All [a] (-> (Interval a) (Interval a) Bit)) (let [(^open ",\.") reference limit (\ reference bottom)] diff --git a/stdlib/source/library/lux/abstract/monad.lux b/stdlib/source/library/lux/abstract/monad.lux index 01e22b7a7..31002b5be 100644 --- a/stdlib/source/library/lux/abstract/monad.lux +++ b/stdlib/source/library/lux/abstract/monad.lux @@ -44,8 +44,8 @@ #.End)) (interface: .public (Monad m) - {#.doc (doc "A monad is a monoid in the category of endofunctors." - "What's the problem?")} + {#.doc (example "A monad is a monoid in the category of endofunctors." + "What's the problem?")} (: (Functor m) &functor) @@ -57,11 +57,11 @@ join)) (macro: .public (do tokens state) - {#.doc (doc "Macro for easy concatenation of monadic operations." - (do monad - [y (f1 x) - z (f2 z)] - (in (f3 z))))} + {#.doc (example "Macro for easy concatenation of monadic operations." + (do monad + [y (f1 x) + z (f2 z)] + (in (f3 z))))} (case (: (Maybe [(Maybe Text) Code (List Code) Code]) (case tokens (^ (list [_ (#.Record (list [[_ (#.Identifier ["" name])] monad]))] [_ (#.Tuple bindings)] body)) @@ -75,11 +75,11 @@ (#.Some [?name monad bindings body]) (if (|> bindings list\size .int ("lux i64 %" +2) ("lux i64 =" +0)) (let [[module short] (name_of ..do) - gensym (: (-> Text Code) - (|>> ($_ "lux text concat" module " " short " ") [""] #.Identifier [location.dummy])) - g!_ (gensym "_") - g!map (gensym "map") - g!join (gensym "join") + identifier (: (-> Text Code) + (|>> ($_ "lux text concat" module " " short " ") [""] #.Identifier [location.dummy])) + g!_ (identifier "_") + g!map (identifier "map") + g!join (identifier "join") body' (list\fold (: (-> [Code Code] Code Code) (function (_ binding body') (with_expansions [ (` (|> (~ value) ((~ g!map) (function ((~ g!_) (~ var)) (~ body'))) (~ g!join)))] @@ -114,7 +114,7 @@ (#.Left "Wrong syntax for 'do'"))) (def: .public (bind monad f) - {#.doc (doc "Apply a function with monadic effects to a monadic value and yield a new monadic value.")} + {#.doc (example "Apply a function with monadic effects to a monadic value and yield a new monadic value.")} (All [! a b] (-> (Monad !) (-> a (! b)) (-> (! a) (! b)))) diff --git a/stdlib/source/library/lux/abstract/monad/indexed.lux b/stdlib/source/library/lux/abstract/monad/indexed.lux index 290db1419..2c2700f8d 100644 --- a/stdlib/source/library/lux/abstract/monad/indexed.lux +++ b/stdlib/source/library/lux/abstract/monad/indexed.lux @@ -62,7 +62,7 @@ (syntax: .public (do {[?name monad] ..named_monad} {context (.tuple (<>.some context))} expression) - (macro.with_gensyms [g!_ g!bind] + (macro.with_identifiers [g!_ g!bind] (let [body (list\fold (function (_ context next) (case context (#Macro macro parameter) diff --git a/stdlib/source/library/lux/abstract/monoid.lux b/stdlib/source/library/lux/abstract/monoid.lux index 800a14c50..4e55a9a3b 100644 --- a/stdlib/source/library/lux/abstract/monoid.lux +++ b/stdlib/source/library/lux/abstract/monoid.lux @@ -3,8 +3,8 @@ [lux #*]]) (interface: .public (Monoid a) - {#.doc (doc "A way to compose values." - "Includes an identity value which does not alter any other value when combined with.")} + {#.doc (example "A way to compose values." + "Includes an identity value which does not alter any other value when combined with.")} (: a identity) (: (-> a a a) diff --git a/stdlib/source/library/lux/abstract/order.lux b/stdlib/source/library/lux/abstract/order.lux index 2dbd078e3..17bb2109d 100644 --- a/stdlib/source/library/lux/abstract/order.lux +++ b/stdlib/source/library/lux/abstract/order.lux @@ -19,37 +19,37 @@ ) (type: .public (Comparison a) - {#.doc (doc "An arbitrary comparison between two values, with the knowledge of how to order them.")} + {#.doc (example "An arbitrary comparison between two values, with the knowledge of how to order them.")} (-> (Order a) a a Bit)) (def: .public (<= order parameter subject) - {#.doc (doc "Less than or equal.")} + {#.doc (example "Less than or equal.")} Comparison (or (\ order < parameter subject) (\ order = parameter subject))) (def: .public (> order parameter subject) - {#.doc (doc "Greater than.")} + {#.doc (example "Greater than.")} Comparison (\ order < subject parameter)) (def: .public (>= order parameter subject) - {#.doc (doc "Greater than or equal.")} + {#.doc (example "Greater than or equal.")} Comparison (or (\ order < subject parameter) (\ order = subject parameter))) (type: .public (Choice a) - {#.doc (doc "A choice comparison between two values, with the knowledge of how to order them.")} + {#.doc (example "A choice comparison between two values, with the knowledge of how to order them.")} (-> (Order a) a a a)) (def: .public (min order x y) - {#.doc (doc "Minimum.")} + {#.doc (example "Minimum.")} Choice (if (\ order < y x) x y)) (def: .public (max order x y) - {#.doc (doc "Maximum.")} + {#.doc (example "Maximum.")} Choice (if (\ order < y x) y x)) diff --git a/stdlib/source/library/lux/abstract/predicate.lux b/stdlib/source/library/lux/abstract/predicate.lux index 625cd42ec..a3702c20c 100644 --- a/stdlib/source/library/lux/abstract/predicate.lux +++ b/stdlib/source/library/lux/abstract/predicate.lux @@ -9,7 +9,7 @@ ["." contravariant]]]) (type: .public (Predicate a) - {#.doc (doc "A question that can be asked of a value, yield either false (#0) or true (#1).")} + {#.doc (example "A question that can be asked of a value, yield either false (#0) or true (#1).")} (-> a Bit)) (template [ @@ -27,11 +27,11 @@ (right value))))] [none #0 or .or - (doc "A predicate that always fails.") - (doc "A predicate that meets either predecessor.")] + (example "A predicate that always fails.") + (example "A predicate that meets either predecessor.")] [all #1 and .and - (doc "A predicate that always succeeds.") - (doc "A predicate that meets both predecessors.")] + (example "A predicate that always succeeds.") + (example "A predicate that meets both predecessors.")] ) (template [ ] @@ -46,19 +46,19 @@ ) (def: .public (complement predicate) - {#.doc (doc "The opposite of a predicate.")} + {#.doc (example "The opposite of a predicate.")} (All [a] (-> (Predicate a) (Predicate a))) (|>> predicate not)) (def: .public (difference sub base) - {#.doc (doc "A predicate that meeds 'base', but not 'sub'.")} + {#.doc (example "A predicate that meeds 'base', but not 'sub'.")} (All [a] (-> (Predicate a) (Predicate a) (Predicate a))) (function (_ value) (.and (base value) (not (sub value))))) (def: .public (rec predicate) - {#.doc (doc "Ties the knot for a recursive predicate.")} + {#.doc (example "Ties the knot for a recursive predicate.")} (All [a] (-> (-> (Predicate a) (Predicate a)) (Predicate a))) diff --git a/stdlib/source/library/lux/control/concatenative.lux b/stdlib/source/library/lux/control/concatenative.lux index 91dd6740d..554e6b21d 100644 --- a/stdlib/source/library/lux/control/concatenative.lux +++ b/stdlib/source/library/lux/control/concatenative.lux @@ -4,13 +4,14 @@ ["." meta] [abstract ["." monad]] + [control + ["." maybe ("#\." monad)]] [data - ["." maybe ("#\." monad)] ["." text ["%" format (#+ format)]] [collection ["." list ("#\." fold functor)]]] - ["." macro (#+ with_gensyms) + ["." macro (#+ with_identifiers) ["." code] ["." template] [syntax (#+ syntax:) @@ -71,15 +72,15 @@ (syntax: .public (=> {aliases aliases^} {inputs stack^} {outputs stack^}) - {#.doc (doc "Concatenative function types." - (=> [Nat] [Nat]) - (All [a] (-> a (=> [] [a]))) - (All [t] (=> [t] [])) - (All [a b c] (=> [a b c] [b c a])) - (All [___a ___z] - (=> {then (=> ___a ___z) - else (=> ___a ___z)} - ___a [Bit then else] ___z)))} + {#.doc (example "Concatenative function types." + (=> [Nat] [Nat]) + (All [a] (-> a (=> [] [a]))) + (All [t] (=> [t] [])) + (All [a b c] (=> [a b c] [b c a])) + (All [___a ___z] + (=> {then (=> ___a ___z) + else (=> ___a ___z)} + ___a [Bit then else] ___z)))} (let [de_alias (function (_ aliased) (list\fold (function (_ [from to] pre) (code.replaced (code.local_identifier from) to pre)) @@ -95,7 +96,7 @@ (~ (de_alias outputC))))))) [?bottomI ?bottomO] - (with_gensyms [g!stack] + (with_identifiers [g!stack] (monad.do meta.monad [inputC (singleton (macro.full_expansion (stack_fold (get@ #top inputs) (maybe.else g!stack ?bottomI)))) outputC (singleton (macro.full_expansion (stack_fold (get@ #top outputs) (maybe.else g!stack ?bottomO))))] @@ -111,13 +112,13 @@ top)) (syntax: .public (||> {commands (<>.some .any)}) - {#.doc (doc "A self-contained sequence of concatenative instructions." - (is? value - (||> (..push sample))) + {#.doc (example "A self-contained sequence of concatenative instructions." + (is? value + (||> (..push sample))) - (||> (push 123) - dup - n/=))} + (||> (push 123) + dup + n/=))} (in (list (` (|> (~! ..begin!) (~+ commands) ((~! ..end!))))))) (def: word @@ -135,24 +136,24 @@ (syntax: .public (word: {[export_policy name annotations type commands] ..word}) - {#.doc (doc "A named concatenative function." - (word: square - (=> [Nat] [Nat]) + {#.doc (example "A named concatenative function." + (word: square + (=> [Nat] [Nat]) - dup - (apply/2 n.*)))} + dup + (apply/2 n.*)))} (in (list (` (def: (~ export_policy) (~ (code.local_identifier name)) (~ (|annotations|.format annotations)) (~ type) (|>> (~+ commands))))))) (syntax: .public (apply {arity (<>.only (n.> 0) .nat)}) - {#.doc (doc "A generator for functions that turn arity N functions into arity N concatenative functions." - (: (=> [Nat] [Nat]) - ((apply 1) inc)))} - (with_gensyms [g! g!func g!stack g!output] + {#.doc (example "A generator for functions that turn arity N functions into arity N concatenative functions." + (: (=> [Nat] [Nat]) + ((apply 1) inc)))} + (with_identifiers [g! g!func g!stack g!output] (monad.do {! meta.monad} - [g!inputs (|> (macro.gensym "input") (list.repeated arity) (monad.seq !))] + [g!inputs (|> (macro.identifier "input") (list.repeated arity) (monad.seq !))] (in (list (` (: (All [(~+ g!inputs) (~ g!output)] (-> (-> (~+ g!inputs) (~ g!output)) (=> [(~+ g!inputs)] [(~ g!output)]))) @@ -165,7 +166,7 @@ (template.text ["Lift a function of arity " " into a concatenative function of arity " "."])] (def: .public - {#.doc (doc )} + {#.doc (example )} (apply )))] [1] [2] [3] [4] @@ -173,68 +174,68 @@ ) (def: .public (push x) - {#.doc (doc "Push a value onto the stack.")} + {#.doc (example "Push a value onto the stack.")} (All [a] (-> a (=> [] [a]))) (function (_ stack) [stack x])) (def: .public drop - {#.doc (doc "Drop/pop a value from the top of the stack.")} + {#.doc (example "Drop/pop a value from the top of the stack.")} (All [t] (=> [t] [])) (function (_ [stack top]) stack)) (def: .public nip - {#.doc (doc "Drop the second-to-last value from the top of the stack.")} + {#.doc (example "Drop the second-to-last value from the top of the stack.")} (All [_ a] (=> [_ a] [a])) (function (_ [[stack _] top]) [stack top])) (def: .public dup - {#.doc (doc "Duplicate the top of the stack.")} + {#.doc (example "Duplicate the top of the stack.")} (All [a] (=> [a] [a a])) (function (_ [stack top]) [[stack top] top])) (def: .public swap - {#.doc (doc "Swaps the 2 topmost stack values.")} + {#.doc (example "Swaps the 2 topmost stack values.")} (All [a b] (=> [a b] [b a])) (function (_ [[stack l] r]) [[stack r] l])) (def: .public rotL - {#.doc (doc "Rotes the 3 topmost stack values to the left.")} + {#.doc (example "Rotes the 3 topmost stack values to the left.")} (All [a b c] (=> [a b c] [b c a])) (function (_ [[[stack a] b] c]) [[[stack b] c] a])) (def: .public rotR - {#.doc (doc "Rotes the 3 topmost stack values to the right.")} + {#.doc (example "Rotes the 3 topmost stack values to the right.")} (All [a b c] (=> [a b c] [c a b])) (function (_ [[[stack a] b] c]) [[[stack c] a] b])) (def: .public && - {#.doc (doc "Groups the 2 topmost stack values as a 2-tuple.")} + {#.doc (example "Groups the 2 topmost stack values as a 2-tuple.")} (All [a b] (=> [a b] [(Tuple a b)])) (function (_ [[stack l] r]) [stack [l r]])) (def: .public ||L - {#.doc (doc "Left-injects the top into sum.")} + {#.doc (example "Left-injects the top into sum.")} (All [a b] (=> [a] [(Or a b)])) (function (_ [stack l]) [stack (0 #0 l)])) (def: .public ||R - {#.doc (doc "Right-injects the top into sum.")} + {#.doc (example "Right-injects the top into sum.")} (All [a b] (=> [b] [(Or a b)])) (function (_ [stack r]) [stack (0 #1 r)])) (template [ ] [(`` (def: .public - {#.doc (doc (~~ (template.text [ " for " " arithmetic."])))} + {#.doc (example (~~ (template.text [ " for " " arithmetic."])))} (=> [ ] []) (function (_ [[stack subject] param]) [stack ( param subject)])))] @@ -285,12 +286,12 @@ ) (def: .public if - {#.doc (doc "If expression." - (is? "then" - (||> (push true) - (push "then") - (push "else") - if)))} + {#.doc (example "If expression." + (is? "then" + (||> (push true) + (push "then") + (push "else") + if)))} (All [___a ___z] (=> {then (=> ___a ___z) else (=> ___a ___z)} @@ -301,7 +302,7 @@ (else stack)))) (def: .public call - {#.doc (doc "Executes an anonymous block on the stack.")} + {#.doc (example "Executes an anonymous block on the stack.")} (All [___a ___z] (=> {quote (=> ___a ___z)} ___a [quote] ___z)) @@ -309,7 +310,7 @@ (quote stack))) (def: .public loop - {#.doc (doc "Executes a block as a loop until it yields #0 to stop.")} + {#.doc (example "Executes a block as a loop until it yields #0 to stop.")} (All [___] (=> {test (=> ___ ___ [Bit])} ___ [test] ___)) @@ -320,7 +321,7 @@ stack')))) (def: .public dip - {#.doc (doc "Executes a block on the stack, save for the topmost value.")} + {#.doc (example "Executes a block on the stack, save for the topmost value.")} (All [___ a] (=> ___ [a (=> ___ ___)] ___ [a])) @@ -328,7 +329,7 @@ [(quote stack) a])) (def: .public dip/2 - {#.doc (doc "Executes a block on the stack, save for the 2 topmost values.")} + {#.doc (example "Executes a block on the stack, save for the 2 topmost values.")} (All [___ a b] (=> ___ [a b (=> ___ ___)] ___ [a b])) @@ -336,12 +337,12 @@ [[(quote stack) a] b])) (def: .public do - {#.doc (doc "Do-while loop expression." - (n.= (inc sample) - (||> (push sample) - (push (push false)) - (push (|>> (push 1) n/+)) - do while)))} + {#.doc (example "Do-while loop expression." + (n.= (inc sample) + (||> (push sample) + (push (push false)) + (push (|>> (push 1) n/+)) + do while)))} (All [___a ___z] (=> {body (=> ___a ___z) pred (=> ___z ___a [Bit])} @@ -351,14 +352,14 @@ [[(body stack) pred] body])) (def: .public while - {#.doc (doc "While loop expression." - (n.= (n.+ distance start) - (||> (push start) - (push (|>> dup - (push start) n/- - (push distance) n/<)) - (push (|>> (push 1) n/+)) - while)))} + {#.doc (example "While loop expression." + (n.= (n.+ distance start) + (||> (push start) + (push (|>> dup + (push start) n/- + (push distance) n/<)) + (push (|>> (push 1) n/+)) + while)))} (All [___a ___z] (=> {body (=> ___z ___a) pred (=> ___a ___z [Bit])} @@ -371,13 +372,13 @@ stack')))) (def: .public compose - {#.doc (doc "Function composition." - (n.= (n.+ 2 sample) - (||> (push sample) - (push (|>> (push 1) n/+)) - (push (|>> (push 1) n/+)) - compose - call)))} + {#.doc (example "Function composition." + (n.= (n.+ 2 sample) + (||> (push sample) + (push (|>> (push 1) n/+)) + (push (|>> (push 1) n/+)) + compose + call)))} (All [___a ___ ___z] (=> [(=> ___a ___) (=> ___ ___z)] [(=> ___a ___z)])) @@ -385,13 +386,13 @@ [stack (|>> f g)])) (def: .public partial - {#.doc (doc "Partial application." - (n.= (n.+ sample sample) - (||> (push sample) - (push sample) - (push n/+) - partial - call)))} + {#.doc (example "Partial application." + (n.= (n.+ sample sample) + (||> (push sample) + (push sample) + (push n/+) + partial + call)))} (All [___a ___z a] (=> ___a [a (=> ___a [a] ___z)] ___a [(=> ___a ___z)])) @@ -399,7 +400,7 @@ [stack (|>> (push arg) quote)])) (word: .public when - {#.doc (doc "Only execute the block when #1.")} + {#.doc (example "Only execute the block when #1.")} (All [___] (=> {body (=> ___ ___)} ___ [Bit body] @@ -410,7 +411,7 @@ if) (word: .public ? - {#.doc (doc "Choose the top value when #0 and the second-to-top when #1.")} + {#.doc (example "Choose the top value when #0 and the second-to-top when #1.")} (All [a] (=> [Bit a a] [a])) rotL diff --git a/stdlib/source/library/lux/control/concurrency/actor.lux b/stdlib/source/library/lux/control/concurrency/actor.lux index ee3a1e5d3..84d41564c 100644 --- a/stdlib/source/library/lux/control/concurrency/actor.lux +++ b/stdlib/source/library/lux/control/concurrency/actor.lux @@ -20,7 +20,7 @@ ["%" format (#+ format)]] [collection ["." list ("#\." monoid monad fold)]]] - ["." macro (#+ with_gensyms) + ["." macro (#+ with_identifiers) ["." code] [syntax (#+ syntax:) ["|.|" input] @@ -64,27 +64,27 @@ (in #.End)))) (abstract: .public (Actor s) - {#.doc (doc "An entity that can react to messages (mail) sent to it concurrently.")} + {#.doc (example "An entity that can react to messages (mail) sent to it concurrently.")} {#obituary [(Async ) (Resolver )] #mailbox (Atom )} (type: .public (Mail s) - {#.doc (doc "A one-way message sent to an actor, without expecting a reply.")} + {#.doc (example "A one-way message sent to an actor, without expecting a reply.")} ) (type: .public (Obituary s) - {#.doc (doc "Details on the death of an actor.")} + {#.doc (example "Details on the death of an actor.")} ) (type: .public (Behavior o s) - {#.doc (doc "An actor's behavior when mail is received and when a fatal error occurs.")} + {#.doc (example "An actor's behavior when mail is received and when a fatal error occurs.")} {#on_init (-> o s) #on_mail (-> (Mail s) s (Actor s) (Async (Try s)))}) (def: .public (spawn! behavior init) - {#.doc (doc "Given a behavior and initial state, spawns an actor and returns it.")} + {#.doc (example "Given a behavior and initial state, spawns an actor and returns it.")} (All [o s] (-> (Behavior o s) o (IO (Actor s)))) (io (let [[on_init on_mail] behavior self (:sharing [o s] @@ -95,14 +95,14 @@ (:abstraction {#obituary (async.async []) #mailbox (atom (async.async []))})) process (loop [state (on_init init) - [|mailbox| _] (io.run (atom.read! (get@ #mailbox (:representation self))))] + [|mailbox| _] (io.run! (atom.read! (get@ #mailbox (:representation self))))] (do {! async.monad} [[head tail] |mailbox| ?state' (on_mail head state self)] (case ?state' (#try.Failure error) (let [[_ resolve] (get@ #obituary (:representation self))] - (exec (io.run + (exec (io.run! (do io.monad [pending (..pending tail)] (resolve [error state (#.Item head pending)]))) @@ -130,14 +130,14 @@ (async.poll obituary))) (def: .public obituary - {#.doc (doc "Await for an actor to stop working.")} + {#.doc (example "Await for an actor to stop working.")} (All [s] (-> (Actor s) (Async (Obituary s)))) (|>> :representation (get@ #obituary) product.left)) (def: .public (mail! mail actor) - {#.doc (doc "Send mail to an actor.")} + {#.doc (example "Send mail to an actor.")} (All [s] (-> (Mail s) (Actor s) (IO (Try Any)))) (do {! io.monad} [alive? (..alive? actor)] @@ -163,7 +163,7 @@ (in (exception.except ..dead []))))) (type: .public (Message s o) - {#.doc (doc "A two-way message sent to an actor, expecting a reply.")} + {#.doc (example "A two-way message sent to an actor, expecting a reply.")} (-> s (Actor s) (Async (Try [s o])))) (def: (mail message) @@ -181,15 +181,17 @@ [outcome (message state self)] (case outcome (#try.Success [state' return]) - (exec (io.run (resolve (#try.Success return))) + (exec + (io.run! (resolve (#try.Success return))) (async.resolved (#try.Success state'))) (#try.Failure error) - (exec (io.run (resolve (#try.Failure error))) + (exec + (io.run! (resolve (#try.Failure error))) (async.resolved (#try.Failure error))))))])) (def: .public (tell! message actor) - {#.doc (doc "Communicate with an actor through message-passing.")} + {#.doc (example "Communicate with an actor through message-passing.")} (All [s o] (-> (Message s o) (Actor s) (Async (Try o)))) (let [[async mail] (..mail message)] (do async.monad @@ -208,14 +210,14 @@ (mail state self)) (def: .public default - {#.doc (doc "Default actor behavior.")} + {#.doc (example "Default actor behavior.")} (All [s] (Behavior s s)) {#on_init function.identity #on_mail ..default_on_mail}) (def: .public (poison! actor) - {#.doc (doc "Kills the actor by sending mail that will kill it upon processing," - "but allows the actor to handle previous mail.")} + {#.doc (example "Kills the actor by sending mail that will kill it upon processing," + "but allows the actor to handle previous mail.")} (All [s] (-> (Actor s) (IO (Try Any)))) (..mail! (function (_ state self) (async.resolved (exception.except ..poisoned []))) @@ -300,12 +302,12 @@ (async.resolved (#try.Success [state state])))))] (syntax: .public (actor: {[export_policy [name vars] annotations state_type [?on_mail messages]] ..actorP}) - {#.doc (doc "Defines a named actor, with its behavior and internal state." - "Messages for the actor must be defined after the on_mail handler." - )} - (with_gensyms [g!_] + {#.doc (example "Defines a named actor, with its behavior and internal state." + "Messages for the actor must be defined after the on_mail handler." + )} + (with_identifiers [g!_] (do meta.monad - [g!type (macro.gensym (format name "_abstract_type")) + [g!type (macro.identifier (format name "_abstract_type")) .let [g!actor (code.local_identifier name) g!vars (list\map code.local_identifier vars)]] (in (list (` ((~! abstract:) (~ export_policy) ((~ g!type) (~+ g!vars)) @@ -323,13 +325,13 @@ (syntax: .public (actor {[state_type init] (.record (<>.and .any .any))} {[?on_mail messages] behavior^}) - {#.doc (doc "Defines an anonymous actor, with its behavior and internal state." - "Messages for the actor must be defined after the on_mail handler." - (actor {Nat - 123} - ((on_mail message state self) - (message (inc state) self))))} - (with_gensyms [g!_] + {#.doc (example "Defines an anonymous actor, with its behavior and internal state." + "Messages for the actor must be defined after the on_mail handler." + (actor {Nat + 123} + ((on_mail message state self) + (message (inc state) self))))} + (with_identifiers [g!_] (in (list (` (: ((~! io.IO) (..Actor (~ state_type))) (..spawn! (: (..Behavior (~ state_type) (~ state_type)) {#..on_init (|>>) @@ -371,13 +373,13 @@ (syntax: .public (message: {[export_policy signature annotations output_type body] ..messageP}) - {#.doc (doc "A message can access the actor's state through the state parameter." - "A message can also access the actor itself through the self parameter." - "A message's output must be an async containing a 2-tuple with the updated state and a return value." - "A message may succeed or fail (in case of failure, the actor dies)." + {#.doc (example "A message can access the actor's state through the state parameter." + "A message can also access the actor itself through the self parameter." + "A message's output must be an async containing a 2-tuple with the updated state and a return value." + "A message may succeed or fail (in case of failure, the actor dies)." - )} - (with_gensyms [g!_ g!return] + )} + (with_identifiers [g!_ g!return] (do meta.monad [actor_scope abstract.current .let [g!type (code.local_identifier (get@ #abstract.name actor_scope)) @@ -405,16 +407,16 @@ )))))) (type: .public Stop - {#.doc (doc "A signal to stop an actor from observing a channel.")} + {#.doc (example "A signal to stop an actor from observing a channel.")} (IO Any)) (def: continue! true) (def: stop! false) (def: .public (observe! action channel actor) - {#.doc (doc "Use an actor to observe a channel by transforming each datum" - "flowing through the channel into mail the actor can process." - "Can stop observing the channel by executing the Stop value.")} + {#.doc (example "Use an actor to observe a channel by transforming each datum" + "flowing through the channel into mail the actor can process." + "Can stop observing the channel by executing the Stop value.")} (All [e s] (-> (-> e Stop (Mail s)) (Channel e) (Actor s) (IO Any))) (let [signal (: (Atom Bit) (atom.atom ..continue!)) diff --git a/stdlib/source/library/lux/control/concurrency/async.lux b/stdlib/source/library/lux/control/concurrency/async.lux index 72736ef94..35ab37cac 100644 --- a/stdlib/source/library/lux/control/concurrency/async.lux +++ b/stdlib/source/library/lux/control/concurrency/async.lux @@ -23,8 +23,8 @@ (Atom [(Maybe a) (List (-> a (IO Any)))]) (type: .public (Resolver a) - {#.doc (doc "The function used to give a value to an async." - "Will signal 'true' if the async has been resolved for the 1st time, 'false' otherwise.")} + {#.doc (example "The function used to give a value to an async." + "Will signal 'true' if the async has been resolved for the 1st time, 'false' otherwise.")} (-> a (IO Bit))) (def: (resolver async) @@ -50,12 +50,12 @@ (resolve value)))))))) (def: .public (resolved value) - {#.doc (doc "Produces an async that has already been resolved to the given value.")} + {#.doc (example "Produces an async that has already been resolved to the given value.")} (All [a] (-> a (Async a))) (:abstraction (atom [(#.Some value) (list)]))) (def: .public (async _) - {#.doc (doc "Creates a fresh async that has not been resolved yet.")} + {#.doc (example "Creates a fresh async that has not been resolved yet.")} (All [a] (-> Any [(Async a) (Resolver a)])) (let [async (:abstraction (atom [#.None (list)]))] [async (..resolver async)])) @@ -68,7 +68,7 @@ (\ io.functor map product.left))) (def: .public (upon! f async) - {#.doc (doc "Executes the given function as soon as the async has been resolved.")} + {#.doc (example "Executes the given function as soon as the async has been resolved.")} (All [a] (-> (-> a (IO Any)) (Async a) (IO Any))) (do {! io.monad} [.let [async (:representation async)] @@ -102,7 +102,8 @@ (def: (map f fa) (let [[fb resolve] (..async [])] - (exec (io.run (..upon! (|>> f resolve) fa)) + (exec + (io.run! (..upon! (|>> f resolve) fa)) fb)))) (implementation: .public apply @@ -112,9 +113,10 @@ (def: (apply ff fa) (let [[fb resolve] (..async [])] - (exec (io.run (..upon! (function (_ f) - (..upon! (|>> f resolve) fa)) - ff)) + (exec + (io.run! (..upon! (function (_ f) + (..upon! (|>> f resolve) fa)) + ff)) fb)))) (implementation: .public monad @@ -126,11 +128,12 @@ (def: (join mma) (let [[ma resolve] (async [])] - (exec (io.run (..upon! (..upon! resolve) mma)) + (exec + (io.run! (..upon! (..upon! resolve) mma)) ma)))) (def: .public (and left right) - {#.doc (doc "Combines the results of both asyncs, in-order.")} + {#.doc (example "Combines the results of both asyncs, in-order.")} (All [a b] (-> (Async a) (Async b) (Async [a b]))) (let [[read! write!] (:sharing [a b] [(Async a) (Async b)] @@ -139,55 +142,58 @@ [(Async [a b]) (Resolver [a b])] (..async [])) - _ (io.run (..upon! (function (_ left) - (..upon! (function (_ right) - (write! [left right])) - right)) - left))] + _ (io.run! (..upon! (function (_ left) + (..upon! (function (_ right) + (write! [left right])) + right)) + left))] read!)) (def: .public (or left right) - {#.doc (doc "Yields the results of whichever async gets resolved first." - "You can tell which one was resolved first through pattern-matching.")} + {#.doc (example "Yields the results of whichever async gets resolved first." + "You can tell which one was resolved first through pattern-matching.")} (All [a b] (-> (Async a) (Async b) (Async (Or a b)))) (let [[a|b resolve] (..async [])] (with_expansions [ (template [ ] - [(io.run (upon! (|>> resolve) ))] + [(io.run! (upon! (|>> resolve) ))] [left #.Left] [right #.Right] )] - (exec + (exec + a|b)))) (def: .public (either left right) - {#.doc (doc "Yields the results of whichever async gets resolved first." - "You cannot tell which one was resolved first.")} + {#.doc (example "Yields the results of whichever async gets resolved first." + "You cannot tell which one was resolved first.")} (All [a] (-> (Async a) (Async a) (Async a))) (let [[left||right resolve] (..async [])] - (`` (exec (~~ (template [] - [(io.run (upon! resolve ))] + (`` (exec + (~~ (template [] + [(io.run! (upon! resolve ))] - [left] - [right])) + [left] + [right])) left||right)))) (def: .public (schedule! millis_delay computation) - {#.doc (doc "Runs an I/O computation on its own thread (after a specified delay)." - "Returns an async that will eventually host its result.")} + {#.doc (example "Runs an I/O computation on its own thread (after a specified delay)." + "Returns an async that will eventually host its result.")} (All [a] (-> Nat (IO a) (Async a))) (let [[!out resolve] (..async [])] - (exec (|> (do io.monad - [value computation] - (resolve value)) - (thread.schedule! millis_delay) - io.run) + (exec + (|> (do io.monad + [value computation] + (resolve value)) + (thread.schedule! millis_delay) + io.run!) !out))) (def: .public future - {#.doc (doc "Runs an I/O computation on its own thread." - "Returns an async that will eventually host its result.")} + {#.doc (example "Runs an I/O computation on its own thread." + "Returns an async that will eventually host its result.")} (All [a] (-> (IO a) (Async a))) (..schedule! 0)) diff --git a/stdlib/source/library/lux/control/concurrency/atom.lux b/stdlib/source/library/lux/control/concurrency/atom.lux index a607fa8d3..0f42393ee 100644 --- a/stdlib/source/library/lux/control/concurrency/atom.lux +++ b/stdlib/source/library/lux/control/concurrency/atom.lux @@ -7,7 +7,7 @@ [monad (#+ do)]] [control ["." function] - ["." io (#- run) ("#\." functor)]] + ["." io (#+ IO) ("#\." functor)]] [data ["." product] [collection @@ -63,29 +63,29 @@ (def: .public (read! atom) (All [a] (-> (Atom a) (IO a))) - (io (with_expansions [ (java/util/concurrent/atomic/AtomicReference::get (:representation atom))] - (for {@.old - @.jvm } - ( 0 (:representation atom)))))) + (io.io (with_expansions [ (java/util/concurrent/atomic/AtomicReference::get (:representation atom))] + (for {@.old + @.jvm } + ( 0 (:representation atom)))))) (def: .public (compare_and_swap! current new atom) - {#.doc (doc "Only mutates an atom if you can present its current value." - "That guarantees that atom was not updated since you last read from it.")} + {#.doc (example "Only mutates an atom if you can present its current value." + "That guarantees that atom was not updated since you last read from it.")} (All [a] (-> a a (Atom a) (IO Bit))) - (io (with_expansions [ (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (:representation atom))] - (for {@.old - @.jvm } - (let [old ( 0 (:representation atom))] - (if (is? old current) - (exec ( 0 new (:representation atom)) - true) - false)))))) + (io.io (with_expansions [ (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (:representation atom))] + (for {@.old + @.jvm } + (let [old ( 0 (:representation atom))] + (if (is? old current) + (exec ( 0 new (:representation atom)) + true) + false)))))) )) (def: .public (update! f atom) - {#.doc (doc "Updates an atom by applying a function to its current value." - "If it fails to update it (because some other process wrote to it first), it will retry until it succeeds." - "The retries will be done with the new values of the atom, as they show up.")} + {#.doc (example "Updates an atom by applying a function to its current value." + "If it fails to update it (because some other process wrote to it first), it will retry until it succeeds." + "The retries will be done with the new values of the atom, as they show up.")} (All [a] (-> (-> a a) (Atom a) (IO [a a]))) (loop [_ []] (do io.monad @@ -97,8 +97,8 @@ (recur []))))) (def: .public (write! value atom) - {#.doc (doc "Writes the given value to an atom." - "If it fails to write it (because some other process wrote to it first), it will retry until it succeeds.")} + {#.doc (example "Writes the given value to an atom." + "If it fails to write it (because some other process wrote to it first), it will retry until it succeeds.")} (All [a] (-> a (Atom a) (IO a))) (|> atom (..update! (function.constant value)) diff --git a/stdlib/source/library/lux/control/concurrency/frp.lux b/stdlib/source/library/lux/control/concurrency/frp.lux index 7d22b5924..32cc8118a 100644 --- a/stdlib/source/library/lux/control/concurrency/frp.lux +++ b/stdlib/source/library/lux/control/concurrency/frp.lux @@ -7,11 +7,10 @@ [apply (#+ Apply)] ["." monad (#+ Monad do)]] [control + ["." maybe ("#\." functor)] ["." try (#+ Try)] ["." exception (#+ exception:)] ["." io (#+ IO io)]] - [data - ["." maybe ("#\." functor)]] [type (#+ :sharing) abstract]]] [// @@ -25,7 +24,7 @@ (exception: .public channel_is_already_closed) (interface: .public (Sink a) - {#.doc (doc "The tail-end of a channel, which can be written-to to fee the channel.")} + {#.doc (example "The tail-end of a channel, which can be written-to to fee the channel.")} (: (IO (Try Any)) close) (: (-> a (IO (Try Any))) @@ -81,7 +80,7 @@ (recur [])))))))))) (def: .public (channel _) - {#.doc (doc "Creates a brand-new channel and hands it over, along with the sink to write to it.")} + {#.doc (example "Creates a brand-new channel and hands it over, along with the sink to write to it.")} (All [a] (-> Any [(Channel a) (Sink a)])) (let [[async resolve] (async.async [])] [async (..sink resolve)])) @@ -137,7 +136,7 @@ [?ma ma] (case ?ma (#.Some [a ma']) - (exec (io.run (\ sink feed a)) + (exec (io.run! (\ sink feed a)) (recur ma')) #.None @@ -145,11 +144,11 @@ (recur mma')) #.None - (in (: Any (io.run (\ sink close)))))))) + (in (: Any (io.run! (\ sink close)))))))) output)))) (type: .public (Subscriber a) - {#.doc (doc "A function that can receive every value fed into a channel.")} + {#.doc (example "A function that can receive every value fed into a channel.")} (-> a (IO (Maybe Any)))) (def: .public (subscribe subscriber channel) @@ -160,7 +159,7 @@ [item channel] (case item (#.Some [head tail]) - (case (io.run (subscriber head)) + (case (io.run! (subscriber head)) (#.Some _) (recur tail) @@ -172,8 +171,8 @@ []))) (def: .public (only pass? channel) - {#.doc (doc "Produces a new channel based on the old one, only with values" - "that pass the test.")} + {#.doc (example "Produces a new channel based on the old one, only with values" + "that pass the test.")} (All [a] (-> (-> a Bit) (Channel a) (Channel a))) (do async.monad [item channel] @@ -188,7 +187,7 @@ (in #.None)))) (def: .public (of_async async) - {#.doc (doc "A one-element channel containing the output from an async.")} + {#.doc (example "A one-element channel containing the output from an async.")} (All [a] (-> (Async a) (Channel a))) (async\map (function (_ value) (#.Some [value ..empty])) @@ -229,11 +228,11 @@ (All [a] (-> Nat (IO a) [(Channel a) (Sink a)])) (let [[output sink] (channel [])] - (exec (io.run (loop [_ []] - (do io.monad - [value action - _ (\ sink feed value)] - (async.upon! recur (async.delay milli_seconds))))) + (exec (io.run! (loop [_ []] + (do io.monad + [value action + _ (\ sink feed value)] + (async.upon! recur (async.delay milli_seconds))))) [output sink]))) (def: .public (periodic milli_seconds) @@ -288,7 +287,7 @@ (in #.End)))) (def: .public (sequential milli_seconds values) - {#.doc (doc "Transforms the given list into a channel with the same elements.")} + {#.doc (example "Transforms the given list into a channel with the same elements.")} (All [a] (-> Nat (List a) (Channel a))) (case values #.End diff --git a/stdlib/source/library/lux/control/concurrency/semaphore.lux b/stdlib/source/library/lux/control/concurrency/semaphore.lux index 046651c1b..06bb81b4e 100644 --- a/stdlib/source/library/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/library/lux/control/concurrency/semaphore.lux @@ -46,13 +46,13 @@ #waiting_list queue.empty})))) (def: .public (wait semaphore) - {#.doc (doc "Wait on a semaphore until there are open positions." - "After finishing your work, you must 'signal' to the semaphore that you're done.")} + {#.doc (example "Wait on a semaphore until there are open positions." + "After finishing your work, you must 'signal' to the semaphore that you're done.")} (Ex [k] (-> Semaphore (Async Any))) (let [semaphore (:representation semaphore) [signal sink] (: [(Async Any) (Resolver Any)] (async.async []))] - (exec (io.run + (exec (io.run! (with_expansions [ (as_is (get@ #open_positions) (i.> -1))] (do io.monad [[_ state'] (atom.update! (|>> (update@ #open_positions dec) @@ -72,7 +72,7 @@ ["Max Positions" (%.nat max_positions)])) (def: .public (signal semaphore) - {#.doc (doc "Signal to a semaphore that you're done with your work, and that there is a new open position.")} + {#.doc (example "Signal to a semaphore that you're done with your work, and that there is a new open position.")} (Ex [k] (-> Semaphore (Async (Try Int)))) (let [semaphore (:representation semaphore)] (async.future @@ -103,7 +103,7 @@ Semaphore (def: .public (mutex _) - {#.doc (doc "Creates a brand-new mutex.")} + {#.doc (example "Creates a brand-new mutex.")} (-> Any Mutex) (:abstraction (semaphore 1))) @@ -116,21 +116,21 @@ (|>> :representation ..signal)) (def: .public (synchronize mutex procedure) - {#.doc (doc "Runs the procedure with exclusive control of the mutex.")} + {#.doc (example "Runs the procedure with exclusive control of the mutex.")} (All [a] (-> Mutex (IO (Async a)) (Async a))) (do async.monad [_ (..acquire mutex) - output (io.run procedure) + output (io.run! procedure) _ (..release mutex)] (in output))) ) (def: .public limit - {#.doc (doc "Produce a limit for a barrier.")} + {#.doc (example "Produce a limit for a barrier.")} (refinement.refiner (n.> 0))) (type: .public Limit - {#.doc (doc "A limit for barriers.")} + {#.doc (example "A limit for barriers.")} (:~ (refinement.type limit))) (abstract: .public Barrier @@ -163,7 +163,7 @@ (do async.monad [.let [limit (refinement.value (get@ #limit barrier)) goal - [_ count] (io.run (atom.update! (get@ #count barrier))) + [_ count] (io.run! (atom.update! (get@ #count barrier))) reached? (n.= goal count)]] (if reached? (..un_block (dec limit) (get@ barrier)) @@ -174,7 +174,7 @@ ) (def: .public (block barrier) - {#.doc (doc "Wait on a barrier until all processes have arrived and met the barrier's limit.")} + {#.doc (example "Wait on a barrier until all processes have arrived and met the barrier's limit.")} (-> Barrier (Async Any)) (do async.monad [_ (..start barrier)] diff --git a/stdlib/source/library/lux/control/concurrency/stm.lux b/stdlib/source/library/lux/control/concurrency/stm.lux index 1ad5d9ac0..321e8bfa8 100644 --- a/stdlib/source/library/lux/control/concurrency/stm.lux +++ b/stdlib/source/library/lux/control/concurrency/stm.lux @@ -7,10 +7,10 @@ ["." monad (#+ Monad do)]] [control ["." io (#+ IO io)] + ["." maybe] ["." try]] [data ["." product] - ["." maybe] [collection ["." list]]] [type @@ -35,7 +35,7 @@ (def: read! (All [a] (-> (Var a) a)) - (|>> :representation atom.read! io.run product.left)) + (|>> :representation atom.read! io.run! product.left)) (def: (un_follow sink var) (All [a] (-> (Sink a) (Var a) (IO Any))) @@ -262,12 +262,12 @@ ))) (def: .public (commit stm_proc) - {#.doc (doc "Commits a transaction and returns its result (asynchronously)." - "Note that a transaction may be re-run an indeterminate number of times if other transactions involving the same variables successfully commit first." - "For this reason, it's important to note that transactions must be free from side-effects, such as I/O.")} + {#.doc (example "Commits a transaction and returns its result (asynchronously)." + "Note that a transaction may be re-run an indeterminate number of times if other transactions involving the same variables successfully commit first." + "For this reason, it's important to note that transactions must be free from side-effects, such as I/O.")} (All [a] (-> (STM a) (Async a))) (let [[output resolver] (async.async [])] - (exec (io.run (do io.monad - [_ init_processor!] - (issue_commit [stm_proc output resolver]))) + (exec (io.run! (do io.monad + [_ init_processor!] + (issue_commit [stm_proc output resolver]))) output))) diff --git a/stdlib/source/library/lux/control/concurrency/thread.lux b/stdlib/source/library/lux/control/concurrency/thread.lux index 767107af7..6d47059b0 100644 --- a/stdlib/source/library/lux/control/concurrency/thread.lux +++ b/stdlib/source/library/lux/control/concurrency/thread.lux @@ -65,7 +65,7 @@ )) (def: .public parallelism - {#.doc (doc "How many processes can run in parallel.")} + {#.doc (example "How many processes can run in parallel.")} Nat (with_expansions [ (|> (java/lang/Runtime::getRuntime) (java/lang/Runtime::availableProcessors) @@ -90,7 +90,7 @@ (def: (execute! action) (-> (IO Any) Any) - (case (try (io.run action)) + (case (try (io.run! action)) (#try.Failure error) (exec ("lux io log" ($_ "lux text concat" @@ -102,7 +102,7 @@ [])) (def: .public (schedule! milli_seconds action) - {#.doc (doc "Executes an I/O procedure after some milli-seconds.")} + {#.doc (example "Executes an I/O procedure after some milli-seconds.")} (-> Nat (IO Any) (IO Any)) (with_expansions [ (as_is (let [runnable (ffi.object [] [java/lang/Runnable] [] @@ -146,7 +146,7 @@ ... https://en.wikipedia.org/wiki/Event_loop (def: .public run! - {#.doc (doc "Starts the event-loop.")} + {#.doc (example "Starts the event-loop.")} (IO Any) (loop [_ []] (do {! io.monad} @@ -169,6 +169,6 @@ (do ! [_ (monad.map ! (|>> (get@ #action) ..execute! io.io) ready)] (recur [])) - (error! (exception.error ..cannot_continue_running_threads [])))) + (panic! (exception.error ..cannot_continue_running_threads [])))) )))) )) diff --git a/stdlib/source/library/lux/control/continuation.lux b/stdlib/source/library/lux/control/continuation.lux index ef0392fe9..7a46ed8a7 100644 --- a/stdlib/source/library/lux/control/continuation.lux +++ b/stdlib/source/library/lux/control/continuation.lux @@ -9,7 +9,7 @@ ["." function] [parser ["s" code]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code]]]]) @@ -22,7 +22,7 @@ (All [i o] (-> (-> i o) (Cont i o) o)) (cont next)) -(def: .public (run cont) +(def: .public (result cont) {#.doc "Forces a continuation thunk to be evaluated."} (All [a] (-> (Cont a a) a)) (cont function.identity)) @@ -38,15 +38,15 @@ k))) (syntax: .public (pending expr) - {#.doc (doc "Turns any expression into a function that is pending a continuation." - (pending (some_function some_input)))} - (with_gensyms [g!_ g!k] + {#.doc (example "Turns any expression into a function that is pending a continuation." + (pending (some_function some_input)))} + (with_identifiers [g!_ g!k] (in (list (` (.function ((~ g!_) (~ g!k)) ((~ g!k) (~ expr)))))))) (def: .public (reset scope) (All [i o] (-> (Cont i i) (Cont i o))) (function (_ k) - (k (run scope)))) + (k (result scope)))) (def: .public (shift f) (All [a] diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux index 1edd4bc04..ee5fd753a 100644 --- a/stdlib/source/library/lux/control/exception.lux +++ b/stdlib/source/library/lux/control/exception.lux @@ -7,10 +7,10 @@ [abstract [monad (#+ do)]] [control + ["." maybe] ["<>" parser ("#\." monad) ["<.>" code (#+ Parser)]]] [data - ["." maybe] ["." product] ["." text ("#\." monoid)] [collection @@ -33,13 +33,13 @@ #constructor (-> a Text)}) (def: .public (match? exception error) - {#.doc (doc "Is this exception the cause of the error message?")} + {#.doc (example "Is this exception the cause of the error message?")} (All [e] (-> (Exception e) Text Bit)) (text.starts_with? (get@ #label exception) error)) (def: .public (when exception then try) - {#.doc (doc "If a particular exception is detected on a possibly-erroneous value, handle it." - "If no exception was detected, or a different one from the one being checked, then pass along the original value.")} + {#.doc (example "If a particular exception is detected on a possibly-erroneous value, handle it." + "If no exception was detected, or a different one from the one being checked, then pass along the original value.")} (All [e a] (-> (Exception e) (-> Text a) (Try a) (Try a))) @@ -98,16 +98,16 @@ ))) (syntax: .public (exception: {[export_policy t_vars [name inputs] body] ..exception}) - {#.doc (doc "Define a new exception type." - "It mostly just serves as a way to tag error messages for later catching." - "" - "Simple case:" - (exception: .public some_exception) - "" - "Complex case:" - (exception: .public [arbitrary type variables] (some_exception {optional Text} {arguments Int}) - optional_body))} - (macro.with_gensyms [g!descriptor] + {#.doc (example "Define a new exception type." + "It mostly just serves as a way to tag error messages for later catching." + "" + "Simple case:" + (exception: .public some_exception) + "" + "Complex case:" + (exception: .public [arbitrary type variables] (some_exception {optional Text} {arguments Int}) + optional_body))} + (macro.with_identifiers [g!descriptor] (do meta.monad [current_module meta.current_module_name .let [descriptor ($_ text\compose "{" current_module "." name "}" text.new_line) @@ -154,19 +154,19 @@ tail)))) (syntax: .public (report {entries (<>.many (.tuple (<>.and .any .any)))}) - {#.doc (doc "An error report." - (: Text - (report ["Row 0" value/0] - ["Row 1" value/1] - ,,, - ["Row N" value/N])))} + {#.doc (example "An error report." + (: Text + (report ["Row 0" value/0] + ["Row 1" value/1] + ,,, + ["Row N" value/N])))} (in (list (` ((~! report') (list (~+ (|> entries (list\map (function (_ [header message]) (` [(~ header) (~ message)]))))))))))) (def: .public (listing format entries) - {#.doc (doc "A numbered report of the entries on a list." - "NOTE: 0-based numbering.")} + {#.doc (example "A numbered report of the entries on a list." + "NOTE: 0-based numbering.")} (All [a] (-> (-> a Text) (List a) Text)) (|> entries @@ -195,7 +195,7 @@ error)) (def: .public (with exception message computation) - {#.doc (doc "If a computation fails, prepends the exception to the error.")} + {#.doc (example "If a computation fails, prepends the exception to the error.")} (All [e a] (-> (Exception e) e (Try a) (Try a))) (case computation (#//.Failure error) diff --git a/stdlib/source/library/lux/control/function.lux b/stdlib/source/library/lux/control/function.lux index 3e0669133..2f31e896a 100644 --- a/stdlib/source/library/lux/control/function.lux +++ b/stdlib/source/library/lux/control/function.lux @@ -5,38 +5,38 @@ [monoid (#+ Monoid)]]]]) (def: .public identity - {#.doc (doc "Identity function." - "Does nothing to its argument and just returns it." - (is? (identity value) - value))} + {#.doc (example "Identity function." + "Does nothing to its argument and just returns it." + (is? (identity value) + value))} (All [a] (-> a a)) (|>>)) (def: .public (compose f g) - {#.doc (doc "Function composition." - (= ((compose f g) "foo") - (f (g "foo"))))} + {#.doc (example "Function composition." + (= ((compose f g) "foo") + (f (g "foo"))))} (All [a b c] (-> (-> b c) (-> a b) (-> a c))) (|>> g f)) (def: .public (constant value) - {#.doc (doc "Create constant functions." - (= ((constant "foo") "bar") - "foo"))} + {#.doc (example "Create constant functions." + (= ((constant "foo") "bar") + "foo"))} (All [o] (-> o (All [i] (-> i o)))) (function (_ _) value)) (def: .public (flip f) - {#.doc (doc "Flips the order of the arguments of a function." - (= ((flip f) "foo" "bar") - (f "bar" "foo")))} + {#.doc (example "Flips the order of the arguments of a function." + (= ((flip f) "foo" "bar") + (f "bar" "foo")))} (All [a b c] (-> (-> a b c) (-> b a c))) (function (_ x y) (f y x))) (def: .public (apply input function) - {#.doc (doc "Simple 1-argument function application.")} + {#.doc (example "Simple 1-argument function application.")} (All [i o] (-> i (-> i o) o)) (function input)) diff --git a/stdlib/source/library/lux/control/function/contract.lux b/stdlib/source/library/lux/control/function/contract.lux index 8b0baca0f..ce62f8c45 100644 --- a/stdlib/source/library/lux/control/function/contract.lux +++ b/stdlib/source/library/lux/control/function/contract.lux @@ -6,7 +6,7 @@ [data [text ["%" format (#+ format)]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code]] [math @@ -26,27 +26,27 @@ (-> Text Bit []) (if test [] - (error! message))) + (panic! message))) (syntax: .public (pre test expr) - {#.doc (doc "Pre-conditions." - "Given a test and an expression to run, only runs the expression if the test passes." - "Otherwise, an error is raised." - (pre (i.= +4 (i.+ +2 +2)) - (foo +123 +456 +789)))} + {#.doc (example "Pre-conditions." + "Given a test and an expression to run, only runs the expression if the test passes." + "Otherwise, an error is raised." + (pre (i.= +4 (i.+ +2 +2)) + (foo +123 +456 +789)))} (in (list (` (exec ((~! ..assert!) (~ (code.text (exception.error ..pre_condition_failed test))) (~ test)) (~ expr)))))) (syntax: .public (post test expr) - {#.doc (doc "Post-conditions." - "Given a predicate and an expression to run, evaluates the expression and then tests the output with the predicate." - "If the predicate returns #1, returns the value of the expression." - "Otherwise, an error is raised." - (post i.even? - (i.+ +2 +2)))} - (with_gensyms [g!output] + {#.doc (example "Post-conditions." + "Given a predicate and an expression to run, evaluates the expression and then tests the output with the predicate." + "If the predicate returns #1, returns the value of the expression." + "Otherwise, an error is raised." + (post i.even? + (i.+ +2 +2)))} + (with_identifiers [g!output] (in (list (` (let [(~ g!output) (~ expr)] (exec ((~! ..assert!) (~ (code.text (exception.error ..post_condition_failed test))) diff --git a/stdlib/source/library/lux/control/function/memo.lux b/stdlib/source/library/lux/control/function/memo.lux index 87131ad57..924ec4c00 100644 --- a/stdlib/source/library/lux/control/function/memo.lux +++ b/stdlib/source/library/lux/control/function/memo.lux @@ -1,6 +1,5 @@ ... Inspired by; ... "The Different Aspects of Monads and Mixins" by Bruno C. d. S. Oliveira - (.module: [library [lux #* @@ -37,28 +36,28 @@ (Recursive i (State (Dictionary i o) o))) (def: .public (open memo) - {#.doc (doc "Memoization where the memoized results can be re-used accross invocations.")} + {#.doc (example "Memoization where the memoized results can be re-used accross invocations.")} (All [i o] (:let [Memory (Dictionary i o)] (-> (Memo i o) (-> [Memory i] [Memory o])))) - (let [memo (//.mixin (//.inherit ..memoization (//.of_recursive memo)))] + (let [memo (//.mixin (//.with ..memoization (//.of_recursive memo)))] (function (_ [memory input]) - (|> input memo (state.run memory))))) + (|> input memo (state.result memory))))) (def: .public (closed hash memo) - {#.doc (doc "Memoization confined to a single invocation to the function (not counting any subsequent recursive invocations)." - "Memoized results will be re-used during recursive invocations, but cannot be accessed after the main invocation has ended.")} + {#.doc (example "Memoization confined to a single invocation to the function (not counting any subsequent recursive invocations)." + "Memoized results will be re-used during recursive invocations, but cannot be accessed after the main invocation has ended.")} (All [i o] (-> (Hash i) (Memo i o) (-> i o))) - (let [memo (//.mixin (//.inherit ..memoization (//.of_recursive memo))) + (let [memo (//.mixin (//.with ..memoization (//.of_recursive memo))) empty (dictionary.empty hash)] - (|>> memo (state.run empty) product.right))) + (|>> memo (state.result empty) product.right))) (def: .public (none hash memo) - {#.doc (doc "No memoization at all." - "This is useful as a test control when measuring the effect of using memoization.")} + {#.doc (example "No memoization at all." + "This is useful as a test control when measuring the effect of using memoization.")} (All [i o] (-> (Hash i) (Memo i o) (-> i o))) (let [memo (//.mixin (//.of_recursive memo)) empty (dictionary.empty hash)] - (|>> memo (state.run empty) product.right))) + (|>> memo (state.result empty) product.right))) diff --git a/stdlib/source/library/lux/control/function/mixin.lux b/stdlib/source/library/lux/control/function/mixin.lux index 25ca0240b..cdaa35a6c 100644 --- a/stdlib/source/library/lux/control/function/mixin.lux +++ b/stdlib/source/library/lux/control/function/mixin.lux @@ -10,23 +10,23 @@ [monad (#+ Monad do)]]]]) (type: .public (Mixin i o) - {#.doc (doc "A function which can be mixed with others to inherit their behavior.")} + {#.doc (example "A function which can be mixed with others to inherit their behavior.")} (-> (-> i o) (-> i o) (-> i o))) (def: .public (mixin f) - {#.doc (doc "Given a mixin, produces a normal function.")} + {#.doc (example "Given a mixin, produces a normal function.")} (All [i o] (-> (Mixin i o) (-> i o))) (function (mix input) ((f mix mix) input))) (def: .public nothing - {#.doc (doc "A mixin that does nothing and just delegates work to the next mixin.")} + {#.doc (example "A mixin that does nothing and just delegates work to the next mixin.")} Mixin (function (_ delegate recur) delegate)) -(def: .public (inherit parent child) - {#.doc (doc "Produces a new mixin, where the behavior of the child can make use of the behavior of the parent.")} +(def: .public (with parent child) + {#.doc (example "Produces a new mixin, where the behavior of the child can make use of the behavior of the parent.")} (All [i o] (-> (Mixin i o) (Mixin i o) (Mixin i o))) (function (_ delegate recur) (parent (child delegate recur) recur))) @@ -35,10 +35,10 @@ (All [i o] (Monoid (Mixin i o))) (def: identity ..nothing) - (def: compose ..inherit)) + (def: compose ..with)) (def: .public (advice when then) - {#.doc (doc "Only apply then mixin when the input meets some criterion.")} + {#.doc (example "Only apply then mixin when the input meets some criterion.")} (All [i o] (-> (Predicate i) (Mixin i o) (Mixin i o))) (function (_ delegate recur input) (if (when input) @@ -46,7 +46,7 @@ (delegate input)))) (def: .public (before monad action) - {#.doc (doc "Executes an action before doing the main work.")} + {#.doc (example "Executes an action before doing the main work.")} (All [! i o] (-> (Monad !) (-> i (! Any)) (Mixin i (! o)))) (function (_ delegate recur input) (do monad @@ -54,7 +54,7 @@ (delegate input)))) (def: .public (after monad action) - {#.doc (doc "Executes an action after doing the main work.")} + {#.doc (example "Executes an action after doing the main work.")} (All [! i o] (-> (Monad !) (-> i o (! Any)) (Mixin i (! o)))) (function (_ delegate recur input) (do monad @@ -63,11 +63,11 @@ (in output)))) (type: .public (Recursive i o) - {#.doc (doc "An indirectly recursive function.")} + {#.doc (example "An indirectly recursive function.")} (-> (-> i o) (-> i o))) (def: .public (of_recursive recursive) - {#.doc (doc "Transform an indirectly recursive function into a mixin.")} + {#.doc (example "Transform an indirectly recursive function into a mixin.")} (All [i o] (-> (Recursive i o) (Mixin i o))) (function (_ delegate recur) (recursive recur))) diff --git a/stdlib/source/library/lux/control/function/mutual.lux b/stdlib/source/library/lux/control/function/mutual.lux index 6f0479cc6..e9cac3871 100644 --- a/stdlib/source/library/lux/control/function/mutual.lux +++ b/stdlib/source/library/lux/control/function/mutual.lux @@ -1,5 +1,5 @@ (.module: - {#.doc (.doc "Macros for implementing mutually-recursive functions.")} + {#.doc (.example "Macros for implementing mutually-recursive functions.")} [library [lux (#- Definition let def:) ["." meta] @@ -54,20 +54,20 @@ (syntax: .public (let {functions (.tuple (<>.some ..mutual))} body) - {#.doc (doc "Locally-defined mutually-recursive functions." - (let [(even? number) - (-> Nat Bit) - (case number - 0 true - _ (odd? (dec number))) + {#.doc (example "Locally-defined mutually-recursive functions." + (let [(even? number) + (-> Nat Bit) + (case number + 0 true + _ (odd? (dec number))) - (odd? number) - (-> Nat Bit) - (case number - 0 false - _ (even? (dec number)))] - (and (even? 4) - (odd? 5))))} + (odd? number) + (-> Nat Bit) + (case number + 0 false + _ (even? (dec number)))] + (and (even? 4) + (odd? 5))))} (case functions #.End (in (list body)) @@ -80,10 +80,10 @@ (~ body)))))) _ - (macro.with_gensyms [g!context g!output] + (macro.with_identifiers [g!context g!output] (do {! meta.monad} [here_name meta.current_module_name - hidden_names (monad.map ! (//.constant (macro.gensym "mutual_function#")) + hidden_names (monad.map ! (//.constant (macro.identifier "mutual_function#")) functions) .let [definitions (list\map (..mutual_definition hidden_names g!context) (list.zipped/2 hidden_names @@ -119,19 +119,19 @@ (<>.and (<>\in (` .private)) ..mutual)))) (syntax: .public (def: {functions (<>.many ..definition)}) - {#.doc (doc "Globally-defined mutually-recursive functions." - (def: - [.public (even? number) - (-> Nat Bit) - (case number - 0 true - _ (odd? (dec number)))] + {#.doc (example "Globally-defined mutually-recursive functions." + (def: + [.public (even? number) + (-> Nat Bit) + (case number + 0 true + _ (odd? (dec number)))] - [.public (odd? number) - (-> Nat Bit) - (case number - 0 false - _ (even? (dec number)))]))} + [.public (odd? number) + (-> Nat Bit) + (case number + 0 false + _ (even? (dec number)))]))} (case functions #.End (in (list)) @@ -144,10 +144,10 @@ (~ body)))))) _ - (macro.with_gensyms [g!context g!output] + (macro.with_identifiers [g!context g!output] (do {! meta.monad} [here_name meta.current_module_name - hidden_names (monad.map ! (//.constant (macro.gensym "mutual_function#")) + hidden_names (monad.map ! (//.constant (macro.identifier "mutual_function#")) functions) .let [definitions (list\map (..mutual_definition hidden_names g!context) (list.zipped/2 hidden_names diff --git a/stdlib/source/library/lux/control/io.lux b/stdlib/source/library/lux/control/io.lux index 801be1c2a..bcb0f4d8c 100644 --- a/stdlib/source/library/lux/control/io.lux +++ b/stdlib/source/library/lux/control/io.lux @@ -11,7 +11,7 @@ ["s" code]]] [type abstract] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." template]]]]) @@ -29,30 +29,30 @@ (function (g!func g!arg) computation)))]) - (template: (!run io) + (template: (run!' io) ... creatio ex nihilo [((:representation io) [])]) (syntax: .public (io computation) - {#.doc (doc "Delays the evaluation of an expression, by wrapping it in an IO 'thunk'." - "Great for wrapping effectful computations (which will not be performed until the IO is 'run')." - (io (exec - (log! msg) - "Some value...")))} - (with_gensyms [g!func g!arg] + {#.doc (example "Delays the evaluation of an expression, by wrapping it in an IO 'thunk'." + "Great for wrapping effectful computations (which will not be performed until the IO is 'run!')." + (io (exec + (log! msg) + "Some value...")))} + (with_identifiers [g!func g!arg] (in (list (` ((~! ..label) (function ((~ g!func) (~ g!arg)) (~ computation)))))))) - (def: .public run + (def: .public run! {#.doc "A way to execute IO computations and perform their side-effects."} (All [a] (-> (IO a) a)) - (|>> !run)) + (|>> run!')) (implementation: .public functor (Functor IO) (def: (map f) - (|>> !run f !io))) + (|>> run!' f !io))) (implementation: .public apply (Apply IO) @@ -60,7 +60,7 @@ (def: &functor ..functor) (def: (apply ff fa) - (!io ((!run ff) (!run fa))))) + (!io ((run!' ff) (run!' fa))))) (implementation: .public monad (Monad IO) @@ -69,5 +69,5 @@ (def: in (|>> !io)) - (def: join (|>> !run !run !io))) + (def: join (|>> run!' run!' !io))) ) diff --git a/stdlib/source/library/lux/control/lazy.lux b/stdlib/source/library/lux/control/lazy.lux new file mode 100644 index 000000000..677832ebd --- /dev/null +++ b/stdlib/source/library/lux/control/lazy.lux @@ -0,0 +1,74 @@ +(.module: + [library + [lux #* + [abstract + [functor (#+ Functor)] + [apply (#+ Apply)] + [monad (#+ Monad do)] + [equivalence (#+ Equivalence)]] + [control + ["." io] + [parser + ["s" code]] + [concurrency + ["." atom]]] + [macro (#+ with_identifiers) + [syntax (#+ syntax:)]] + [type + abstract]]]) + +(abstract: .public (Lazy a) + {#.doc (example "A value specified by an expression that is calculated only at the last moment possible." + "Afterwards, the value is cached for future reference.")} + + (-> [] a) + + (def: (lazy' generator) + (All [a] (-> (-> [] a) (Lazy a))) + (let [cache (atom.atom #.None)] + (:abstraction (function (_ _) + (case (io.run! (atom.read! cache)) + (#.Some value) + value + + _ + (let [value (generator [])] + (exec + (io.run! (atom.compare_and_swap! _ (#.Some value) cache)) + value))))))) + + (def: .public (value lazy) + (All [a] (-> (Lazy a) a)) + ((:representation lazy) []))) + +(syntax: .public (lazy expression) + {#.doc (example "Specifies a lazy value by providing the expression that computes it.")} + (with_identifiers [g!_] + (in (list (` ((~! lazy') (function ((~ g!_) (~ g!_)) (~ expression)))))))) + +(implementation: .public (equivalence (^open "\.")) + (All [a] (-> (Equivalence a) (Equivalence (Lazy a)))) + + (def: (= left right) + (\= (..value left) + (..value right)))) + +(implementation: .public functor + (Functor Lazy) + + (def: (map f fa) + (lazy (f (value fa))))) + +(implementation: .public apply + (Apply Lazy) + + (def: &functor ..functor) + (def: (apply ff fa) + (lazy ((value ff) (value fa))))) + +(implementation: .public monad + (Monad Lazy) + + (def: &functor ..functor) + (def: in (|>> lazy)) + (def: join value)) diff --git a/stdlib/source/library/lux/control/maybe.lux b/stdlib/source/library/lux/control/maybe.lux new file mode 100644 index 000000000..2d9b56039 --- /dev/null +++ b/stdlib/source/library/lux/control/maybe.lux @@ -0,0 +1,171 @@ +(.module: + [library + [lux (#- list) + [abstract + [monoid (#+ Monoid)] + [equivalence (#+ Equivalence)] + [hash (#+ Hash)] + [apply (#+ Apply)] + ["." functor (#+ Functor)] + ["." monad (#+ Monad do)]] + [meta + ["." location]]]]) + +... (type: (Maybe a) +... #.None +... (#.Some a)) + +(implementation: .public monoid + (All [a] (Monoid (Maybe a))) + + (def: identity #.None) + + (def: (compose mx my) + (case mx + #.None + my + + (#.Some x) + (#.Some x)))) + +(implementation: .public functor + (Functor Maybe) + + (def: (map f ma) + (case ma + #.None #.None + (#.Some a) (#.Some (f a))))) + +(implementation: .public apply + (Apply Maybe) + + (def: &functor ..functor) + + (def: (apply ff fa) + (case [ff fa] + [(#.Some f) (#.Some a)] + (#.Some (f a)) + + _ + #.None))) + +(implementation: .public monad + (Monad Maybe) + + (def: &functor ..functor) + + (def: (in x) + (#.Some x)) + + (def: (join mma) + (case mma + #.None + #.None + + (#.Some mx) + mx))) + +(implementation: .public (equivalence super) + (All [a] (-> (Equivalence a) (Equivalence (Maybe a)))) + + (def: (= mx my) + (case [mx my] + [#.None #.None] + #1 + + [(#.Some x) (#.Some y)] + (\ super = x y) + + _ + #0))) + +(implementation: .public (hash super) + (All [a] (-> (Hash a) (Hash (Maybe a)))) + + (def: &equivalence + (..equivalence (\ super &equivalence))) + + (def: (hash value) + (case value + #.None + 0 + + (#.Some value) + (\ super hash value)))) + +(implementation: .public (with monad) + (All [M] (-> (Monad M) (Monad (All [a] (M (Maybe a)))))) + + (def: &functor (functor.compose (get@ #monad.&functor monad) ..functor)) + + (def: in (|>> (\ ..monad in) (\ monad in))) + + (def: (join MmMma) + (do monad + [mMma MmMma] + (case mMma + #.None + (in #.None) + + (#.Some Mma) + Mma)))) + +(def: .public (lift monad) + {#.doc (example "Wraps a monadic value with Maybe machinery.")} + (All [M a] (-> (Monad M) (-> (M a) (M (Maybe a))))) + (\ monad map (\ ..monad in))) + +(macro: .public (else tokens state) + {#.doc (example "Allows you to provide a default value that will be used" + "if a (Maybe x) value turns out to be #.None." + "Note: the expression for the default value will not be computed if the base computation succeeds." + (else +20 (#.Some +10)) + "=>" + +10 + -------------------------- + (else +20 #.None) + "=>" + +20)} + (case tokens + (^ (.list else maybe)) + (let [g!temp (: Code [location.dummy (#.Identifier ["" ""])])] + (#.Right [state (.list (` (case (~ maybe) + (#.Some (~ g!temp)) + (~ g!temp) + + #.None + (~ else))))])) + + _ + (#.Left "Wrong syntax for else"))) + +(def: .public assume + {#.doc (example "Assumes that a Maybe value is a #.Some and yields its value." + "Raises/throws a runtime error otherwise." + "WARNING: Use with caution.")} + (All [a] (-> (Maybe a) a)) + (|>> (..else (undefined)))) + +(def: .public (list value) + (All [a] (-> (Maybe a) (List a))) + (case value + #.None + #.End + + (#.Some value) + (#.Item value #.End))) + +(macro: .public (when tokens state) + {#.doc (example "Can be used as a guard in (co)monadic be/do expressions." + (do monad + [value (do_something 1 2 3) + ..when (passes_test? value)] + (do_something_else 4 5 6)))} + (case tokens + (^ (.list test then)) + (#.Right [state (.list (` (.if (~ test) + (~ then) + #.None)))]) + + _ + (#.Left "Wrong syntax for when"))) diff --git a/stdlib/source/library/lux/control/parser.lux b/stdlib/source/library/lux/control/parser.lux index 8ddce370f..4c86373f5 100644 --- a/stdlib/source/library/lux/control/parser.lux +++ b/stdlib/source/library/lux/control/parser.lux @@ -89,10 +89,10 @@ (#try.Success [input' x]) (#try.Success [input' (#.Some x)])))) -(def: .public (run parser input) - {#.doc (doc "Executes the parser on the input." - "Does not verify that all of the input has been consumed by the parser." - "Returns both the parser's output, and a value that represents the remaining input.")} +(def: .public (result parser input) + {#.doc (example "Executes the parser on the input." + "Does not verify that all of the input has been consumed by the parser." + "Returns both the parser's output, and a value that represents the remaining input.")} (All [s a] (-> (Parser s a) s (Try [s a]))) (parser input)) @@ -144,9 +144,9 @@ (#try.Success [input (list)]) (#try.Success [input' head]) - (..run (\ ..monad map (|>> (list& head)) - (some parser)) - input')))) + (..result (\ ..monad map (|>> (list& head)) + (some parser)) + input')))) (def: .public (many parser) {#.doc "1-or-more combinator."} @@ -185,9 +185,9 @@ (#try.Success [input (list)]) (#try.Success [input' x]) - (..run (\ ..monad map (|>> (#.Item x)) - (at_most (dec amount) parser)) - input'))))) + (..result (\ ..monad map (|>> (#.Item x)) + (at_most (dec amount) parser)) + input'))))) (def: .public (between minimum additional parser) (All [s a] (-> Nat Nat (Parser s a) (Parser s (List a)))) @@ -214,7 +214,7 @@ (\ ! map (|>> (list\map product.right) (#.Item x))))))) (def: .public (not parser) - {#.doc (doc "Only succeeds when the underlying parser fails.")} + {#.doc (example "Only succeeds when the underlying parser fails.")} (All [s a] (-> (Parser s a) (Parser s Any))) (function (_ input) (case (parser input) @@ -225,13 +225,13 @@ (#try.Failure "Expected to fail; yet succeeded.")))) (def: .public (failure message) - {#.doc (doc "Always fail with this 'message'.")} + {#.doc (example "Always fail with this 'message'.")} (All [s a] (-> Text (Parser s a))) (function (_ input) (#try.Failure message))) (def: .public (lift operation) - {#.doc (doc "Lift a potentially failed computation into a parser.")} + {#.doc (example "Lift a potentially failed computation into a parser.")} (All [s a] (-> (Try a) (Parser s a))) (function (_ input) (case operation @@ -253,7 +253,7 @@ (#try.Success [input' output])))) (def: .public remaining - {#.doc (doc "Yield the remaining input (without consuming it).")} + {#.doc (example "Yield the remaining input (without consuming it).")} (All [s] (Parser s s)) (function (_ inputs) (#try.Success [inputs inputs]))) @@ -262,17 +262,17 @@ {#.doc "Combinator for recursive parsers."} (All [s a] (-> (-> (Parser s a) (Parser s a)) (Parser s a))) (function (_ inputs) - (..run (parser (rec parser)) inputs))) + (..result (parser (rec parser)) inputs))) (def: .public (after param subject) - {#.doc (doc "Run the parser after another one (whose output is ignored).")} + {#.doc (example "Run the parser after another one (whose output is ignored).")} (All [s _ a] (-> (Parser s _) (Parser s a) (Parser s a))) (do ..monad [_ param] subject)) (def: .public (before param subject) - {#.doc (doc "Run the parser before another one (whose output is ignored).")} + {#.doc (example "Run the parser before another one (whose output is ignored).")} (All [s _ a] (-> (Parser s _) (Parser s a) (Parser s a))) (do ..monad [output subject @@ -280,7 +280,7 @@ (in output))) (def: .public (only test parser) - {#.doc (doc "Only succeed when the parser's output passes a test.")} + {#.doc (example "Only succeed when the parser's output passes a test.")} (All [s a] (-> (-> a Bit) (Parser s a) (Parser s a))) (do ..monad [output parser @@ -288,7 +288,7 @@ (in output))) (def: .public (parses? parser) - {#.doc (doc "Ignore a parser's output and just verify that it succeeds.")} + {#.doc (example "Ignore a parser's output and just verify that it succeeds.")} (All [s a] (-> (Parser s a) (Parser s Bit))) (function (_ input) (case (parser input) @@ -299,7 +299,7 @@ (#try.Success [input' true])))) (def: .public (parses parser) - {#.doc (doc "Ignore a parser's output and just execute it.")} + {#.doc (example "Ignore a parser's output and just execute it.")} (All [s a] (-> (Parser s a) (Parser s Any))) (function (_ input) (case (parser input) @@ -310,8 +310,8 @@ (#try.Success [input' []])))) (def: .public (speculative parser) - {#.doc (doc "Executes a parser, without actually consuming the input." - "That way, the same input can be consumed again by another parser.")} + {#.doc (example "Executes a parser, without actually consuming the input." + "That way, the same input can be consumed again by another parser.")} (All [s a] (-> (Parser s a) (Parser s a))) (function (_ input) (case (parser input) @@ -322,7 +322,7 @@ output))) (def: .public (codec codec parser) - {#.doc (doc "Decode the output of a parser using a codec.")} + {#.doc (example "Decode the output of a parser using a codec.")} (All [s a z] (-> (Codec a z) (Parser s a) (Parser s z))) (function (_ input) (case (parser input) diff --git a/stdlib/source/library/lux/control/parser/analysis.lux b/stdlib/source/library/lux/control/parser/analysis.lux index 7d64289bc..94e7ca9c1 100644 --- a/stdlib/source/library/lux/control/parser/analysis.lux +++ b/stdlib/source/library/lux/control/parser/analysis.lux @@ -37,7 +37,7 @@ (format text.new_line "Remaining input: " (|> asts (list\map /.%analysis) - (list.interpose " ") + (list.interposed " ") (text.join_with "")))) (exception: .public (cannot_parse {input (List Analysis)}) @@ -49,11 +49,11 @@ ["Input" (exception.listing /.%analysis input)])) (type: .public Parser - {#.doc (doc "A parser for Lux code analysis nodes.")} + {#.doc (example "A parser for Lux code analysis nodes.")} (//.Parser (List Analysis))) -(def: .public (run parser input) - {#.doc (doc "Executes a parser and makes sure no inputs go unconsumed.")} +(def: .public (result parser input) + {#.doc (example "Executes a parser and makes sure no inputs go unconsumed.")} (All [a] (-> (Parser a) (List Analysis) (Try a))) (case (parser input) (#try.Failure error) @@ -66,7 +66,7 @@ (exception.except ..unconsumed_input unconsumed))) (def: .public any - {#.doc (doc "Matches any value, without discrimination.")} + {#.doc (example "Matches any value, without discrimination.")} (Parser Analysis) (function (_ input) (case input @@ -95,7 +95,7 @@ (template [ ] [(`` (as_is (def: .public - {#.doc (doc (~~ (template.text ["Queries for a " " value."])))} + {#.doc (example (~~ (template.text ["Queries for a " " value."])))} (Parser ) (function (_ input) (case input @@ -106,7 +106,7 @@ (exception.except ..cannot_parse input)))) (def: .public ( expected) - {#.doc (doc (~~ (template.text ["Assert a specific " " value."])))} + {#.doc (example (~~ (template.text ["Assert a specific " " value."])))} (-> (Parser Any)) (function (_ input) (case input @@ -130,13 +130,13 @@ ) (def: .public (tuple parser) - {#.doc (doc "Parses only within the context of a tuple's contents.")} + {#.doc (example "Parses only within the context of a tuple's contents.")} (All [a] (-> (Parser a) (Parser a))) (function (_ input) (case input (^ (list& (/.tuple head) tail)) (do try.monad - [output (..run parser head)] + [output (..result parser head)] (#try.Success [tail output])) _ diff --git a/stdlib/source/library/lux/control/parser/binary.lux b/stdlib/source/library/lux/control/parser/binary.lux index 1018e7683..7cf526d41 100644 --- a/stdlib/source/library/lux/control/parser/binary.lux +++ b/stdlib/source/library/lux/control/parser/binary.lux @@ -27,11 +27,11 @@ ["." // ("#\." monad)]) (type: .public Offset - {#.doc (doc "An offset for reading within binary data.")} + {#.doc (example "An offset for reading within binary data.")} Nat) (type: .public Parser - {#.doc (doc "A parser for raw binary data.")} + {#.doc (example "A parser for raw binary data.")} (//.Parser [Offset Binary])) (exception: .public (binary_was_not_fully_read {binary_length Nat} {bytes_read Nat}) @@ -39,8 +39,8 @@ ["Binary length" (%.nat binary_length)] ["Bytes read" (%.nat bytes_read)])) -(def: .public (run parser input) - {#.doc (doc "Runs a parser and checks that all the binary data was read by it.")} +(def: .public (result parser input) + {#.doc (example "Runs a parser and checks that all the binary data was read by it.")} (All [a] (-> (Parser a) Binary (Try a))) (case (parser [0 input]) (#try.Failure msg) @@ -53,25 +53,25 @@ (exception.except ..binary_was_not_fully_read [length end]))))) (def: .public end? - {#.doc (doc "Checks whether there is no more data to read.")} + {#.doc (example "Checks whether there is no more data to read.")} (Parser Bit) (function (_ (^@ input [offset data])) (#try.Success [input (n.= offset (/.size data))]))) (def: .public offset - {#.doc (doc "The current offset (i.e. how much data has been read).")} + {#.doc (example "The current offset (i.e. how much data has been read).")} (Parser Offset) (function (_ (^@ input [offset data])) (#try.Success [input offset]))) (def: .public remaining - {#.doc (doc "How much of the data remains to be read.")} + {#.doc (example "How much of the data remains to be read.")} (Parser Nat) (function (_ (^@ input [offset data])) (#try.Success [input (n.- offset (/.size data))]))) (type: .public Size - {#.doc (doc "The size of a chunk of data within a binary array.")} + {#.doc (example "The size of a chunk of data within a binary array.")} Nat) (def: .public size/8 Size 1) @@ -129,14 +129,14 @@ [1 #.Right right]])) (def: .public (rec body) - {#.doc (doc "Tie the knot for a recursive parser.")} + {#.doc (example "Tie the knot for a recursive parser.")} (All [a] (-> (-> (Parser a) (Parser a)) (Parser a))) (function (_ input) (let [parser (body (rec body))] (parser input)))) (def: .public any - {#.doc (doc "Does no parsing, and just returns a dummy value.")} + {#.doc (example "Does no parsing, and just returns a dummy value.")} (Parser Any) (//\in [])) @@ -156,18 +156,18 @@ _ (//.lift (exception.except ..not_a_bit [value]))))) (def: .public (segment size) - {#.doc (doc "Parses a chunk of data of a given size.")} + {#.doc (example "Parses a chunk of data of a given size.")} (-> Nat (Parser Binary)) (function (_ [offset binary]) (case size - 0 (#try.Success [[offset binary] (/.create 0)]) + 0 (#try.Success [[offset binary] (/.empty 0)]) _ (|> binary (/.slice offset size) (\ try.monad map (|>> [[(n.+ size offset) binary]])))))) (template [ ] [(`` (def: .public - {#.doc (doc (~~ (template.text ["Parses a block of data prefixed with a size that is " " bytes long."])))} + {#.doc (example (~~ (template.text ["Parses a block of data prefixed with a size that is " " bytes long."])))} (Parser Binary) (do //.monad [size (//\map .nat )] @@ -181,7 +181,7 @@ (template [ ] [(`` (def: .public - {#.doc (doc (~~ (template.text ["Parses a block of (UTF-8 encoded) text prefixed with a size that is " " bytes long."])))} + {#.doc (example (~~ (template.text ["Parses a block of (UTF-8 encoded) text prefixed with a size that is " " bytes long."])))} (Parser Text) (do //.monad [utf8 ] @@ -197,7 +197,7 @@ (template [ ] [(def: .public ( valueP) - {#.doc (doc (~~ (template.text ["Parses a row of values prefixed with a size that is " " bytes long."])))} + {#.doc (example (~~ (template.text ["Parses a row of values prefixed with a size that is " " bytes long."])))} (All [v] (-> (Parser v) (Parser (Row v)))) (do //.monad [amount (: (Parser Nat) @@ -227,7 +227,7 @@ (..or ..any)) (def: .public (list value) - {#.doc (doc "Parses an arbitrarily long list of values.")} + {#.doc (example "Parses an arbitrarily long list of values.")} (All [a] (-> (Parser a) (Parser (List a)))) (..rec (|>> (//.and value) diff --git a/stdlib/source/library/lux/control/parser/cli.lux b/stdlib/source/library/lux/control/parser/cli.lux index b4051eb43..cc9bf19ab 100644 --- a/stdlib/source/library/lux/control/parser/cli.lux +++ b/stdlib/source/library/lux/control/parser/cli.lux @@ -14,10 +14,10 @@ {#.doc "A command-line interface parser."} (//.Parser (List Text) a)) -(def: .public (run parser inputs) - {#.doc (doc "Executes the parser and verifies that all inputs are processed.")} +(def: .public (result parser inputs) + {#.doc (example "Executes the parser and verifies that all inputs are processed.")} (All [a] (-> (Parser a) (List Text) (Try a))) - (case (//.run parser inputs) + (case (//.result parser inputs) (#try.Success [remaining output]) (case remaining #.End @@ -64,7 +64,7 @@ (All [a] (-> (Parser a) (Parser a))) (function (_ inputs) (loop [immediate inputs] - (case (//.run cli immediate) + (case (//.result cli immediate) (#try.Success [remaining output]) (#try.Success [remaining output]) @@ -88,14 +88,14 @@ _ (#try.Failure (format "Unknown parameters: " (text.join_with " " inputs)))))) (def: .public (named name value) - {#.doc (doc "Parses a named parameter and yields its value.")} + {#.doc (example "Parses a named parameter and yields its value.")} (All [a] (-> Text (Parser a) (Parser a))) (|> value (//.after (..this name)) ..somewhere)) (def: .public (parameter [short long] value) - {#.doc (doc "Parses a parameter that can have either a short or a long name.")} + {#.doc (example "Parses a parameter that can have either a short or a long name.")} (All [a] (-> [Text Text] (Parser a) (Parser a))) (|> value (//.after (//.either (..this short) (..this long))) diff --git a/stdlib/source/library/lux/control/parser/code.lux b/stdlib/source/library/lux/control/parser/code.lux index c3ac5dca0..d22039f4a 100644 --- a/stdlib/source/library/lux/control/parser/code.lux +++ b/stdlib/source/library/lux/control/parser/code.lux @@ -34,7 +34,7 @@ (def: (remaining_inputs codes) (-> (List Code) Text) ($_ text\compose text.new_line "Remaining input: " - (|> codes (list\map code.format) (list.interpose " ") (text.join_with "")))) + (|> codes (list\map code.format) (list.interposed " ") (text.join_with "")))) (def: .public any {#.doc "Yields the next input without applying any logic."} @@ -176,8 +176,8 @@ #.End true _ false)]))) -(def: .public (run parser inputs) - {#.doc (doc "Executes a parser against a stream of code, and verifies all the inputs are consumed.")} +(def: .public (result parser inputs) + {#.doc (example "Executes a parser against a stream of code, and verifies all the inputs are consumed.")} (All [a] (-> (Parser a) (List Code) (Try a))) (case (parser inputs) (#try.Failure error) @@ -198,5 +198,5 @@ (All [a] (-> (List Code) (Parser a) (Parser a))) (function (_ real) (do try.monad - [value (..run parser inputs)] + [value (..result parser inputs)] (in [real value])))) diff --git a/stdlib/source/library/lux/control/parser/environment.lux b/stdlib/source/library/lux/control/parser/environment.lux index b83ef9165..5358da9ca 100644 --- a/stdlib/source/library/lux/control/parser/environment.lux +++ b/stdlib/source/library/lux/control/parser/environment.lux @@ -13,11 +13,11 @@ ["." //]) (type: .public Property - {#.doc (doc "A property in the environment.")} + {#.doc (example "A property in the environment.")} Text) (type: .public Environment - {#.doc (doc "An abstraction for environment variables of a program.")} + {#.doc (example "An abstraction for environment variables of a program.")} (Dictionary Property Text)) (exception: .public (unknown_property {property Property}) @@ -25,11 +25,11 @@ ["Property" (%.text property)])) (type: .public (Parser a) - {#.doc (doc "A parser of environment variables of a program.")} + {#.doc (example "A parser of environment variables of a program.")} (//.Parser Environment a)) (def: .public empty - {#.doc (doc "An empty environment.")} + {#.doc (example "An empty environment.")} Environment (dictionary.empty text.hash)) @@ -43,8 +43,8 @@ #.None (exception.except ..unknown_property [name])))) -(def: .public (run parser environment) - {#.doc (doc "Executes a parser against the given environment variables." - "Does not check whether all environment variables were parsed, since they're usually an open set.")} +(def: .public (result parser environment) + {#.doc (example "Executes a parser against the given environment variables." + "Does not check whether all environment variables were parsed, since they're usually an open set.")} (All [a] (-> (Parser a) Environment (Try a))) (\ try.monad map product.right (parser environment))) diff --git a/stdlib/source/library/lux/control/parser/json.lux b/stdlib/source/library/lux/control/parser/json.lux index f1112ffbe..133f78332 100644 --- a/stdlib/source/library/lux/control/parser/json.lux +++ b/stdlib/source/library/lux/control/parser/json.lux @@ -32,11 +32,11 @@ (exception: .public empty_input) -(def: .public (run parser json) - {#.doc (doc "Executes the parser against a JSON object." - "Verifies that all of the JSON was consumed by the parser.")} +(def: .public (result parser json) + {#.doc (example "Executes the parser against a JSON object." + "Verifies that all of the JSON was consumed by the parser.")} (All [a] (-> (Parser a) JSON (Try a))) - (case (//.run parser (list json)) + (case (//.result parser (list json)) (#try.Success [remainder output]) (case remainder #.End @@ -120,7 +120,7 @@ ) (def: .public (nullable parser) - {#.doc (doc "Enhances parser by adding NULL-handling.")} + {#.doc (example "Enhances parser by adding NULL-handling.")} (All [a] (-> (Parser a) (Parser (Maybe a)))) (//.or ..null parser)) @@ -132,7 +132,7 @@ [head ..any] (case head (#/.Array values) - (case (//.run parser (row.list values)) + (case (//.result parser (row.list values)) (#try.Failure error) (//.failure error) @@ -148,8 +148,8 @@ (//.failure (exception.error ..unexpected_value [head]))))) (def: .public (object parser) - {#.doc (doc "Parses the contents of a JSON object." - "Use this with the 'field' combinator.")} + {#.doc (example "Parses the contents of a JSON object." + "Use this with the 'field' combinator.")} (All [a] (-> (Parser a) (Parser a))) (do //.monad [head ..any] @@ -160,7 +160,7 @@ (list\map (function (_ [key value]) (list (#/.String key) value))) list.concat - (//.run parser)) + (//.result parser)) (#try.Failure error) (//.failure error) @@ -176,14 +176,14 @@ (//.failure (exception.error ..unexpected_value [head]))))) (def: .public (field field_name parser) - {#.doc (doc "Parses a field inside a JSON object." - "Use this inside the 'object' combinator.")} + {#.doc (example "Parses a field inside a JSON object." + "Use this inside the 'object' combinator.")} (All [a] (-> Text (Parser a) (Parser a))) (function (recur inputs) (case inputs (^ (list& (#/.String key) value inputs')) (if (text\= key field_name) - (case (//.run parser (list value)) + (case (//.result parser (list value)) (#try.Success [#.End output]) (#try.Success [inputs' output]) diff --git a/stdlib/source/library/lux/control/parser/synthesis.lux b/stdlib/source/library/lux/control/parser/synthesis.lux index cde50518e..dadf00655 100644 --- a/stdlib/source/library/lux/control/parser/synthesis.lux +++ b/stdlib/source/library/lux/control/parser/synthesis.lux @@ -49,12 +49,12 @@ (exception: .public empty_input) (type: .public Parser - {#.doc (doc "A parser for the Lux compiler's synthesis nodes using during optimization.")} + {#.doc (example "A parser for the Lux compiler's synthesis nodes using during optimization.")} (//.Parser (List Synthesis))) -(def: .public (run parser input) - {#.doc (doc "Executes the parser against the inputs." - "Ensures all inputs are consumed by the parser.")} +(def: .public (result parser input) + {#.doc (example "Executes the parser against the inputs." + "Ensures all inputs are consumed by the parser.")} (All [a] (-> (Parser a) (List Synthesis) (Try a))) (case (parser input) (#try.Failure error) @@ -67,7 +67,7 @@ (exception.except ..unconsumed_input unconsumed))) (def: .public any - {#.doc (doc "Yields a synthesis node without subjecting it to any analysis.")} + {#.doc (example "Yields a synthesis node without subjecting it to any analysis.")} (Parser Synthesis) (.function (_ input) (case input @@ -95,7 +95,7 @@ (template [ ] [(`` (def: .public - {#.doc (doc (~~ (template.text ["Queries for a " " synthesis node."])))} + {#.doc (example (~~ (template.text ["Queries for a " " synthesis node."])))} (Parser ) (.function (_ input) (case input @@ -106,7 +106,7 @@ (exception.except ..cannot_parse input))))) (`` (def: .public ( expected) - {#.doc (doc (~~ (template.text ["Checks for a specific " " synthesis node."])))} + {#.doc (example (~~ (template.text ["Checks for a specific " " synthesis node."])))} (-> (Parser Any)) (.function (_ input) (case input @@ -128,27 +128,27 @@ ) (def: .public (tuple parser) - {#.doc (doc "Parses the contents of a tuple.")} + {#.doc (example "Parses the contents of a tuple.")} (All [a] (-> (Parser a) (Parser a))) (.function (_ input) (case input (^ (list& (/.tuple head) tail)) (do try.monad - [output (..run parser head)] + [output (..result parser head)] (#try.Success [tail output])) _ (exception.except ..cannot_parse input)))) (def: .public (function expected parser) - {#.doc (doc "Parses the body of a function with the 'expected' arity.")} + {#.doc (example "Parses the body of a function with the 'expected' arity.")} (All [a] (-> Arity (Parser a) (Parser [(Environment Synthesis) a]))) (.function (_ input) (case input (^ (list& (/.function/abstraction [environment actual body]) tail)) (if (n.= expected actual) (do try.monad - [output (..run parser (list body))] + [output (..result parser (list body))] (#try.Success [tail [environment output]])) (exception.except ..wrong_arity [expected actual])) @@ -156,14 +156,14 @@ (exception.except ..cannot_parse input)))) (def: .public (loop init_parsers iteration_parser) - {#.doc (doc "Parses the initial values and the body of a loop.")} + {#.doc (example "Parses the initial values and the body of a loop.")} (All [a b] (-> (Parser a) (Parser b) (Parser [Register a b]))) (.function (_ input) (case input (^ (list& (/.loop/scope [start inits iteration]) tail)) (do try.monad - [inits (..run init_parsers inits) - iteration (..run iteration_parser (list iteration))] + [inits (..result init_parsers inits) + iteration (..result iteration_parser (list iteration))] (#try.Success [tail [start inits iteration]])) _ diff --git a/stdlib/source/library/lux/control/parser/text.lux b/stdlib/source/library/lux/control/parser/text.lux index f593f311f..8d314634c 100644 --- a/stdlib/source/library/lux/control/parser/text.lux +++ b/stdlib/source/library/lux/control/parser/text.lux @@ -4,12 +4,12 @@ [abstract [monad (#+ Monad do)]] [control + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)]] [data ["/" text (#+ Char) ("#\." monoid)] ["." product] - ["." maybe] [collection ["." list ("#\." fold)]]] [macro @@ -21,7 +21,7 @@ ["." //]) (type: .public Offset - {#.doc (doc "An offset into a block of text.")} + {#.doc (example "An offset into a block of text.")} Nat) (def: start_offset @@ -29,11 +29,11 @@ 0) (type: .public Parser - {#.doc (doc "A parser for text.")} + {#.doc (example "A parser for text.")} (//.Parser [Offset Text])) (type: .public Slice - {#.doc (doc "A slice of a block of text.")} + {#.doc (example "A slice of a block of text.")} {#basis Offset #distance Offset}) @@ -55,9 +55,9 @@ (exception: .public cannot_parse) (exception: .public cannot_slice) -(def: .public (run parser input) - {#.doc (doc "Executes a parser against a block of text." - "Verifies that the entire input has been processed.")} +(def: .public (result parser input) + {#.doc (example "Executes a parser against a block of text." + "Verifies that the entire input has been processed.")} (All [a] (-> (Parser a) Text (Try a))) (case (parser [start_offset input]) (#try.Failure msg) @@ -69,7 +69,7 @@ (exception.except ..unconsumed_input [end_offset input])))) (def: .public offset - {#.doc (doc "Yields the current offset into the input.")} + {#.doc (example "Yields the current offset into the input.")} (Parser Offset) (function (_ (^@ input [offset tape])) (#try.Success [input offset]))) @@ -112,7 +112,7 @@ (template [ ] [(`` (def: .public ( parser) - {#.doc (doc (~~ (template.text ["Produce a character" " if the parser fails."])))} + {#.doc (example (~~ (template.text ["Produce a character" " if the parser fails."])))} (All [a] (-> (Parser a) (Parser ))) (function (_ input) (case (parser input) @@ -131,7 +131,7 @@ ["Reference" (/.format reference)])) (def: .public (this reference) - {#.doc (doc "Checks that a specific text shows up in the input.")} + {#.doc (example "Checks that a specific text shows up in the input.")} (-> Text (Parser Any)) (function (_ [offset tape]) (case (/.index_of' offset reference tape) @@ -283,7 +283,7 @@ (..satisfies /.space?)) (def: .public (and left right) - {#.doc (doc "Yields the outputs of both parsers composed together.")} + {#.doc (example "Yields the outputs of both parsers composed together.")} (-> (Parser Text) (Parser Text) (Parser Text)) (do //.monad [=left left @@ -291,7 +291,7 @@ (in ($_ /\compose =left =right)))) (def: .public (and! left right) - {#.doc (doc "Yields the outputs of both parsers composed together (as a slice).")} + {#.doc (example "Yields the outputs of both parsers composed together (as a slice).")} (-> (Parser Slice) (Parser Slice) (Parser Slice)) (do //.monad [[left::basis left::distance] left @@ -364,7 +364,7 @@ {#.doc "Applies a parser against the given input."} (All [a] (-> Text (Parser a) (Parser a))) (function (_ real_input) - (case (..run parser local_input) + (case (..result parser local_input) (#try.Failure error) (#try.Failure error) @@ -372,7 +372,7 @@ (#try.Success [real_input value])))) (def: .public (slice parser) - {#.doc (doc "Converts a slice to a block of text.")} + {#.doc (example "Converts a slice to a block of text.")} (-> (Parser Slice) (Parser Text)) (do //.monad [[basis distance] parser] @@ -385,11 +385,11 @@ (exception.except ..cannot_slice []))))) (def: .public (then structured text) - {#.doc (doc "Embeds a text parser into an arbitrary parser that yields text.")} + {#.doc (example "Embeds a text parser into an arbitrary parser that yields text.")} (All [s a] (-> (Parser a) (//.Parser s Text) (//.Parser s a))) (do //.monad [raw text] - (//.lift (..run structured raw)))) + (//.lift (..result structured raw)))) diff --git a/stdlib/source/library/lux/control/parser/tree.lux b/stdlib/source/library/lux/control/parser/tree.lux index 6daf1129e..cba23cf82 100644 --- a/stdlib/source/library/lux/control/parser/tree.lux +++ b/stdlib/source/library/lux/control/parser/tree.lux @@ -13,23 +13,23 @@ ["." //]) (type: .public (Parser t a) - {#.doc (doc "A parser of arbitrary trees.")} + {#.doc (example "A parser of arbitrary trees.")} (//.Parser (Zipper t) a)) -(def: .public (run' parser zipper) - {#.doc (doc "Applies the parser against a tree zipper.")} +(def: .public (result' parser zipper) + {#.doc (example "Applies the parser against a tree zipper.")} (All [t a] (-> (Parser t a) (Zipper t) (Try a))) (do try.monad - [[zipper output] (//.run parser zipper)] + [[zipper output] (//.result parser zipper)] (in output))) -(def: .public (run parser tree) - {#.doc (doc "Applies the parser against a tree.")} +(def: .public (result parser tree) + {#.doc (example "Applies the parser against a tree.")} (All [t a] (-> (Parser t a) (Tree t) (Try a))) - (run' parser (zipper.zipper tree))) + (result' parser (zipper.zipper tree))) (def: .public value - {#.doc (doc "Yields the value inside the current tree node.")} + {#.doc (example "Yields the value inside the current tree node.")} (All [t] (Parser t t)) (function (_ zipper) (#try.Success [zipper (zipper.value zipper)]))) @@ -38,7 +38,7 @@ (template [ ] [(def: .public - {#.doc (doc )} + {#.doc (example )} (All [t] (Parser t [])) (function (_ zipper) (case ( zipper) diff --git a/stdlib/source/library/lux/control/parser/type.lux b/stdlib/source/library/lux/control/parser/type.lux index 6e5c0f005..aaebfb594 100644 --- a/stdlib/source/library/lux/control/parser/type.lux +++ b/stdlib/source/library/lux/control/parser/type.lux @@ -1,6 +1,6 @@ (.module: - {#.doc (.doc "Parsing of Lux types." - "Used mostly for polytypic programming.")} + {#.doc (.example "Parsing of Lux types." + "Used mostly for polytypic programming.")} [library [lux (#- function local) [abstract @@ -61,21 +61,21 @@ (text.join_with ""))])) (type: .public Env - {#.doc (doc "An environment for type parsing.")} + {#.doc (example "An environment for type parsing.")} (Dictionary Nat [Type Code])) (type: .public (Parser a) - {#.doc (doc "A parser of Lux types.")} + {#.doc (example "A parser of Lux types.")} (//.Parser [Env (List Type)] a)) (def: .public fresh - {#.doc (doc "An empty parsing environment.")} + {#.doc (example "An empty parsing environment.")} Env (dictionary.empty n.hash)) -(def: (run' env poly types) +(def: (result' env poly types) (All [a] (-> Env (Parser a) (List Type) (Try a))) - (case (//.run poly [env types]) + (case (//.result poly [env types]) (#try.Failure error) (#try.Failure error) @@ -87,14 +87,14 @@ _ (exception.except ..unconsumed_input remaining)))) -(def: .public (run poly type) - {#.doc (doc "Applies a parser against a type." - "Verifies that the parser fully consumes the type's information.")} +(def: .public (result poly type) + {#.doc (example "Applies a parser against a type." + "Verifies that the parser fully consumes the type's information.")} (All [a] (-> (Parser a) Type (Try a))) - (run' ..fresh poly (list type))) + (result' ..fresh poly (list type))) (def: .public env - {#.doc (doc "Yields the current parsing environment.")} + {#.doc (example "Yields the current parsing environment.")} (Parser Env) (.function (_ [env inputs]) (#try.Success [[env inputs] env]))) @@ -102,7 +102,7 @@ (def: (with_env temp poly) (All [a] (-> Env (Parser a) (Parser a))) (.function (_ [env inputs]) - (case (//.run poly [temp inputs]) + (case (//.result poly [temp inputs]) (#try.Failure error) (#try.Failure error) @@ -110,7 +110,7 @@ (#try.Success [[env remaining] output])))) (def: .public peek - {#.doc (doc "Inspect a type in the input stream without consuming it.")} + {#.doc (example "Inspect a type in the input stream without consuming it.")} (Parser Type) (.function (_ [env inputs]) (case inputs @@ -121,7 +121,7 @@ (#try.Success [[env inputs] headT])))) (def: .public any - {#.doc (doc "Yields a type, without examination.")} + {#.doc (example "Yields a type, without examination.")} (Parser Type) (.function (_ [env inputs]) (case inputs @@ -132,10 +132,10 @@ (#try.Success [[env tail] headT])))) (def: .public (local types poly) - {#.doc (doc "Apply a parser to the given inputs.")} + {#.doc (example "Apply a parser to the given inputs.")} (All [a] (-> (List Type) (Parser a) (Parser a))) (.function (_ [env pass_through]) - (case (run' env poly types) + (case (result' env poly types) (#try.Failure error) (#try.Failure error) @@ -151,9 +151,9 @@ (.function (_ [env inputs]) (let [current_id (dictionary.size env) g!var (label current_id)] - (case (//.run poly - [(dictionary.put current_id [type g!var] env) - inputs]) + (case (//.result poly + [(dictionary.put current_id [type g!var] env) + inputs]) (#try.Failure error) (#try.Failure error) @@ -162,7 +162,7 @@ (template [ ] [(`` (def: .public ( poly) - {#.doc (doc (~~ (template.text ["Parses the contents of a " " type."])))} + {#.doc (example (~~ (template.text ["Parses the contents of a " " type."])))} (All [a] (-> (Parser a) (Parser a))) (do //.monad [headT ..any] @@ -222,7 +222,7 @@ (in [funcL all_varsL output]))))) (def: .public (function in_poly out_poly) - {#.doc (doc "Parses a function's inputs and output.")} + {#.doc (example "Parses a function's inputs and output.")} (All [i o] (-> (Parser i) (Parser o) (Parser [i o]))) (do //.monad [headT any @@ -233,7 +233,7 @@ (//.failure (exception.error ..not_function headT))))) (def: .public (applied poly) - {#.doc (doc "Parses a type application.")} + {#.doc (example "Parses a type application.")} (All [a] (-> (Parser a) (Parser a))) (do //.monad [headT any @@ -244,7 +244,7 @@ (template [ ] [(def: .public ( expected) - {#.doc (doc )} + {#.doc (example )} (-> Type (Parser Any)) (do //.monad [actual any] @@ -254,9 +254,9 @@ [exactly type\= "Parses a type exactly."] - [sub check.checks? + [sub check.subsumes? "Parses a sub type."] - [super (function.flip check.checks?) + [super (function.flip check.subsumes?) "Parses a super type."] ) @@ -299,7 +299,7 @@ (//.failure (exception.error ..not_parameter headT))))) (def: .public existential - {#.doc (doc "Yields an existential type.")} + {#.doc (example "Yields an existential type.")} (Parser Nat) (do //.monad [headT any] @@ -311,7 +311,7 @@ (//.failure (exception.error ..not_existential headT))))) (def: .public named - {#.doc (doc "Yields a named type.")} + {#.doc (example "Yields a named type.")} (Parser [Name Type]) (do //.monad [inputT any] diff --git a/stdlib/source/library/lux/control/parser/xml.lux b/stdlib/source/library/lux/control/parser/xml.lux index 14072c73c..6e7dfe3e1 100644 --- a/stdlib/source/library/lux/control/parser/xml.lux +++ b/stdlib/source/library/lux/control/parser/xml.lux @@ -18,7 +18,7 @@ ["." //]) (type: .public (Parser a) - {#.doc (doc "A parser of XML-encoded data.")} + {#.doc (example "A parser of XML-encoded data.")} (//.Parser [Attrs (List XML)] a)) (exception: .public empty_input) @@ -38,9 +38,9 @@ (exception.report ["Inputs" (exception.listing (\ /.codec encode) inputs)])) -(def: (run' parser attrs documents) +(def: (result' parser attrs documents) (All [a] (-> (Parser a) Attrs (List XML) (Try a))) - (case (//.run parser [attrs documents]) + (case (//.result parser [attrs documents]) (#try.Success [[attrs' remaining] output]) (if (list.empty? remaining) (#try.Success output) @@ -49,14 +49,14 @@ (#try.Failure error) (#try.Failure error))) -(def: .public (run parser documents) - {#.doc (doc "Applies a parser against a stream of XML documents." - "Verifies that all of the inputs are consumed by the parser.")} +(def: .public (result parser documents) + {#.doc (example "Applies a parser against a stream of XML documents." + "Verifies that all of the inputs are consumed by the parser.")} (All [a] (-> (Parser a) (List XML) (Try a))) - (..run' parser /.attributes documents)) + (..result' parser /.attributes documents)) (def: .public text - {#.doc (doc "Yields text from a text node.")} + {#.doc (example "Yields text from a text node.")} (Parser Text) (function (_ [attrs documents]) (case documents @@ -72,7 +72,7 @@ (exception.except ..unexpected_input []))))) (def: .public tag - {#.doc (doc "Yields the tag from the next node.")} + {#.doc (example "Yields the tag from the next node.")} (Parser Tag) (function (_ [attrs documents]) (case documents @@ -88,7 +88,7 @@ (#try.Success [[attrs documents] tag]))))) (def: .public (attribute name) - {#.doc (doc "Yields the value of an attribute in the current node.")} + {#.doc (example "Yields the value of an attribute in the current node.")} (-> Attribute (Parser Text)) (function (_ [attrs documents]) (case (dictionary.get name attrs) @@ -99,7 +99,7 @@ (#try.Success [[attrs documents] value])))) (def: .public (node expected parser) - {#.doc (doc "Parses the contents of the next node if the tag matches.")} + {#.doc (example "Parses the contents of the next node if the tag matches.")} (All [a] (-> Tag (Parser a) (Parser a))) (function (_ [attrs documents]) (case documents @@ -114,28 +114,28 @@ (#/.Node actual attrs' children) (if (name\= expected actual) (|> children - (..run' parser attrs') + (..result' parser attrs') (try\map (|>> [[attrs tail]]))) (exception.except ..wrong_tag [expected actual])))))) -(def: .public ignore - {#.doc (doc "Skips the next node.")} - (Parser Any) +(def: .public any + {#.doc (example "Yields the next node.")} + (Parser XML) (function (_ [attrs documents]) (case documents #.End (exception.except ..empty_input []) (#.Item head tail) - (#try.Success [[attrs tail] []])))) + (#try.Success [[attrs tail] head])))) (exception: .public nowhere) (def: .public (somewhere parser) - {#.doc (doc "Applies the parser somewhere among the remaining inputs; instead of demanding that the parser succeeds against the immediate inputs.")} + {#.doc (example "Applies the parser somewhere among the remaining inputs; instead of demanding that the parser succeeds against the immediate inputs.")} (All [a] (-> (Parser a) (Parser a))) (function (recur [attrs input]) - (case (//.run parser [attrs input]) + (case (//.result parser [attrs input]) (#try.Success [[attrs remaining] output]) (#try.Success [[attrs remaining] output]) diff --git a/stdlib/source/library/lux/control/pipe.lux b/stdlib/source/library/lux/control/pipe.lux index 7e551f43c..07f38e15e 100644 --- a/stdlib/source/library/lux/control/pipe.lux +++ b/stdlib/source/library/lux/control/pipe.lux @@ -12,7 +12,7 @@ ["." identity] [collection ["." list ("#\." fold monad)]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code]] [math @@ -27,19 +27,19 @@ (syntax: .public (new> start {body body^} prev) - {#.doc (doc "Ignores the piped argument, and begins a new pipe." - (n.= 1 - (|> 20 - (n.* 3) - (n.+ 4) - (new> 0 [inc]))))} + {#.doc (example "Ignores the piped argument, and begins a new pipe." + (n.= 1 + (|> 20 + (n.* 3) + (n.+ 4) + (new> 0 [inc]))))} (in (list (` (|> (~ start) (~+ body)))))) (syntax: .public (let> binding body prev) - {#.doc (doc "Gives a name to the piped-argument, within the given expression." - (n.= 10 - (|> 5 - (let> x (n.+ x x)))))} + {#.doc (example "Gives a name to the piped-argument, within the given expression." + (n.= 10 + (|> 5 + (let> x (n.+ x x)))))} (in (list (` (let [(~ binding) (~ prev)] (~ body)))))) @@ -53,13 +53,13 @@ {else body^} {_ _reversed_} {branches (p.some (p.and body^ body^))}) - {#.doc (doc "Branching for pipes." - "Both the tests and the bodies are piped-code, and must be given inside a tuple." - (|> +5 - (cond> [i.even?] [(i.* +2)] - [i.odd?] [(i.* +3)] - [(new> -1 [])])))} - (with_gensyms [g!temp] + {#.doc (example "Branching for pipes." + "Both the tests and the bodies are piped-code, and must be given inside a tuple." + (|> +5 + (cond> [i.even?] [(i.* +2)] + [i.odd?] [(i.* +3)] + [(new> -1 [])])))} + (with_identifiers [g!temp] (in (list (` (let [(~ g!temp) (~ prev)] (cond (~+ (do list.monad [[test then] branches] @@ -68,26 +68,26 @@ (|> (~ g!temp) (~+ else))))))))) (syntax: .public (if> {test body^} {then body^} {else body^} prev) - {#.doc (doc "If-branching." - (is? (if (n.even? sample) - "even" - "odd") - (|> sample - (if> [n.even?] - [(new> "even" [])] - [(new> "odd" [])]))))} + {#.doc (example "If-branching." + (is? (if (n.even? sample) + "even" + "odd") + (|> sample + (if> [n.even?] + [(new> "even" [])] + [(new> "odd" [])]))))} (in (list (` (cond> [(~+ test)] [(~+ then)] [(~+ else)] (~ prev)))))) (syntax: .public (when> {test body^} {then body^} prev) - {#.doc (doc "Only execute the body when the test passes." - (is? (if (n.even? sample) - (n.* 2 sample) - sample) - (|> sample - (when> [n.even?] - [(n.* 2)]))))} + {#.doc (example "Only execute the body when the test passes." + (is? (if (n.even? sample) + (n.* 2 sample) + sample) + (|> sample + (when> [n.even?] + [(n.* 2)]))))} (in (list (` (cond> [(~+ test)] [(~+ then)] [] (~ prev)))))) @@ -95,12 +95,12 @@ (syntax: .public (loop> {test body^} {then body^} prev) - {#.doc (doc "Loops for pipes." - "Both the testing and calculating steps are pipes and must be given inside tuples." - (|> +1 - (loop> [(i.< +10)] - [inc])))} - (with_gensyms [g!temp] + {#.doc (example "Loops for pipes." + "Both the testing and calculating steps are pipes and must be given inside tuples." + (|> +1 + (loop> [(i.< +10)] + [inc])))} + (with_identifiers [g!temp] (in (list (` (loop [(~ g!temp) (~ prev)] (if (|> (~ g!temp) (~+ test)) ((~' recur) (|> (~ g!temp) (~+ then))) @@ -109,14 +109,14 @@ (syntax: .public (do> monad {steps (p.some body^)} prev) - {#.doc (doc "Monadic pipes." - "Each steps in the monadic computation is a pipe and must be given inside a tuple." - (|> +5 - (do> identity.monad - [(i.* +3)] - [(i.+ +4)] - [inc])))} - (with_gensyms [g!temp] + {#.doc (example "Monadic pipes." + "Each steps in the monadic computation is a pipe and must be given inside a tuple." + (|> +5 + (do> identity.monad + [(i.* +3)] + [(i.+ +4)] + [inc])))} + (with_identifiers [g!temp] (case (list.reversed steps) (^ (list& last_step prev_steps)) (let [step_bindings (do list.monad @@ -132,46 +132,46 @@ (syntax: .public (exec> {body body^} prev) - {#.doc (doc "Non-updating pipes." - "Will generate piped computations, but their results will not be used in the larger scope." - (|> +5 - (exec> [.nat %n log!]) - (i.* +10)))} - (with_gensyms [g!temp] + {#.doc (example "Non-updating pipes." + "Will generate piped computations, but their results will not be used in the larger scope." + (|> +5 + (exec> [.nat %n log!]) + (i.* +10)))} + (with_identifiers [g!temp] (in (list (` (let [(~ g!temp) (~ prev)] (exec (|> (~ g!temp) (~+ body)) (~ g!temp)))))))) (syntax: .public (tuple> {paths (p.many body^)} prev) - {#.doc (doc "Parallel branching for pipes." - "Allows to run multiple pipelines for a value and gives you a tuple of the outputs." - (|> +5 - (tuple> [(i.* +10)] - [dec (i./ +2)] - [Int/encode])) - "Will become: [+50 +2 '+5']")} - (with_gensyms [g!temp] + {#.doc (example "Parallel branching for pipes." + "Allows to run multiple pipelines for a value and gives you a tuple of the outputs." + (|> +5 + (tuple> [(i.* +10)] + [dec (i./ +2)] + [Int/encode])) + "Will become: [+50 +2 '+5']")} + (with_identifiers [g!temp] (in (list (` (let [(~ g!temp) (~ prev)] [(~+ (list\map (function (_ body) (` (|> (~ g!temp) (~+ body)))) paths))])))))) (syntax: .public (case> {branches (p.many (p.and s.any s.any))} prev) - {#.doc (doc "Pattern-matching for pipes." - "The bodies of each branch are NOT pipes; just regular values." - (|> +5 - (case> +0 "zero" - +1 "one" - +2 "two" - +3 "three" - +4 "four" - +5 "five" - +6 "six" - +7 "seven" - +8 "eight" - +9 "nine" - _ "???")))} + {#.doc (example "Pattern-matching for pipes." + "The bodies of each branch are NOT pipes; just regular values." + (|> +5 + (case> +0 "zero" + +1 "one" + +2 "two" + +3 "three" + +4 "four" + +5 "five" + +6 "six" + +7 "seven" + +8 "eight" + +9 "nine" + _ "???")))} (in (list (` (case (~ prev) (~+ (list\join (list\map (function (_ [pattern body]) (list pattern body)) branches)))))))) diff --git a/stdlib/source/library/lux/control/reader.lux b/stdlib/source/library/lux/control/reader.lux index 947c18b21..b2e5b9399 100644 --- a/stdlib/source/library/lux/control/reader.lux +++ b/stdlib/source/library/lux/control/reader.lux @@ -20,8 +20,8 @@ (All [r a] (-> (-> r r) (Reader r a) (Reader r a))) (|>> change proc)) -(def: .public (run env proc) - {#.doc (doc "Executes the reader against the given environment.")} +(def: .public (result env proc) + {#.doc "Executes the reader against the given environment."} (All [r a] (-> r (Reader r a) a)) (proc env)) @@ -64,8 +64,8 @@ (def: (join eMeMa) (function (_ env) (do monad - [eMa (run env eMeMa)] - (run env eMa))))) + [eMa (result env eMeMa)] + (result env eMa))))) (def: .public lift {#.doc "Lift monadic values to the Reader wrapper."} diff --git a/stdlib/source/library/lux/control/region.lux b/stdlib/source/library/lux/control/region.lux index daf4b33d3..d84f0e027 100644 --- a/stdlib/source/library/lux/control/region.lux +++ b/stdlib/source/library/lux/control/region.lux @@ -19,8 +19,8 @@ (-> r (! (Try Any)))) (type: .public (Region r ! a) - {#.doc (doc "A region where resources may be be claimed and where a side-effecting computation may be performed." - "Every resource is paired with a function that knows how to clean/reclaim it, to make sure there are no leaks.")} + {#.doc (example "A region where resources may be be claimed and where a side-effecting computation may be performed." + "Every resource is paired with a function that knows how to clean/reclaim it, to make sure there are no leaks.")} (-> [r (List (Cleaner r !))] (! [(List (Cleaner r !)) (Try a)]))) @@ -53,8 +53,8 @@ (#try.Failure error) (exception.except ..clean_up_error [error output]))) -(def: .public (run monad computation) - {#.doc (doc "Executes a region-based computation, with a side-effect determined by the monad.")} +(def: .public (run! monad computation) + {#.doc (example "Executes a region-based computation, with a side-effect determined by the monad.")} (All [! a] (-> (Monad !) (All [r] (Region r ! a)) (! (Try a)))) @@ -65,7 +65,7 @@ (\ ! map (list\fold clean output))))) (def: .public (acquire monad cleaner value) - {#.doc (doc "Acquire a resource while pairing it a function that knows how to reclaim it.")} + {#.doc (example "Acquire a resource while pairing it a function that knows how to reclaim it.")} (All [! a] (-> (Monad !) (-> a (! (Try Any))) a (All [r] (Region r ! a)))) (function (_ [region cleaners]) @@ -140,7 +140,7 @@ (in [cleaners (#try.Failure error)])))))) (def: .public (failure monad error) - {#.doc (doc "Immediately fail with this 'message'.")} + {#.doc (example "Immediately fail with this 'message'.")} (All [! a] (-> (Monad !) Text (All [r] (Region r ! a)))) @@ -148,14 +148,14 @@ (\ monad in [cleaners (#try.Failure error)]))) (def: .public (except monad exception message) - {#.doc (doc "Fail by throwing/raising an exception.")} + {#.doc (example "Fail by throwing/raising an exception.")} (All [! e a] (-> (Monad !) (Exception e) e (All [r] (Region r ! a)))) (failure monad (exception.error exception message))) (def: .public (lift monad operation) - {#.doc (doc "Lift an effectful computation into a region-based computation.")} + {#.doc (example "Lift an effectful computation into a region-based computation.")} (All [! a] (-> (Monad !) (! a) (All [r] (Region r ! a)))) diff --git a/stdlib/source/library/lux/control/remember.lux b/stdlib/source/library/lux/control/remember.lux index 44289b3cb..f4f9c4213 100644 --- a/stdlib/source/library/lux/control/remember.lux +++ b/stdlib/source/library/lux/control/remember.lux @@ -48,14 +48,14 @@ (<>.failure message))))) (syntax: .public (remember {deadline ..deadline} {message .text} {focus (<>.maybe .any)}) - {#.doc (doc "A message with an expiration date." - "Can have an optional piece of code to focus on." - (remember "2022-04-01" - "Do this, that and the other.") - (remember "2022-04-01" - "Improve the performace." - (some (complicated (computation 123)))))} - (let [now (io.run instant.now) + {#.doc (example "A message with an expiration date." + "Can have an optional piece of code to focus on." + (remember "2022-04-01" + "Do this, that and the other.") + (remember "2022-04-01" + "Improve the performace." + (some (complicated (computation 123)))))} + (let [now (io.run! instant.now) today (instant.date now)] (if (date\< deadline today) (in (case focus @@ -68,13 +68,13 @@ (template [ ] [(`` (syntax: .public ( {deadline ..deadline} {message .text} {focus (<>.maybe .any)}) - {#.doc (doc (~~ (template.text ["A " " message with an expiration date."])) - "Can have an optional piece of code to focus on." - ( "2022-04-01" - "Do this, that and the other.") - ( "2022-04-01" - "Improve the performace." - (some (complicated (computation 123)))))} + {#.doc (example (~~ (template.text ["A " " message with an expiration date."])) + "Can have an optional piece of code to focus on." + ( "2022-04-01" + "Do this, that and the other.") + ( "2022-04-01" + "Improve the performace." + (some (complicated (computation 123)))))} (in (list (` (..remember (~ (code.text (%.date deadline))) (~ (code.text (format " " message))) (~+ (case focus diff --git a/stdlib/source/library/lux/control/security/capability.lux b/stdlib/source/library/lux/control/security/capability.lux index b0123dc68..bf689a80c 100644 --- a/stdlib/source/library/lux/control/security/capability.lux +++ b/stdlib/source/library/lux/control/security/capability.lux @@ -25,8 +25,8 @@ ["|.|" annotations]]]]]) (abstract: .public (Capability brand input output) - {#.doc (doc "Represents the capability to perform an operation." - "This operation is assumed to have security implications.")} + {#.doc (example "Represents the capability to perform an operation." + "This operation is assumed to have security implications.")} (-> input output) @@ -37,7 +37,7 @@ (|>> :abstraction)) (def: .public (use capability input) - {#.doc (doc "Applies a capability against its required input.")} + {#.doc (example "Applies a capability against its required input.")} (All [brand input output] (-> (Capability brand input output) input @@ -50,21 +50,21 @@ |declaration|.parser (<>.maybe |annotations|.parser) (.form ($_ <>.and .local_identifier .any .any))))}) - {#.doc (doc "Defines a capability as a unique type, and a constructor for instances." + {#.doc (example "Defines a capability as a unique type, and a constructor for instances." - (capability: (Can_Duplicate a) - (can_duplicate a [a a])) - - (let [capability (can_duplicate - (function (_ value) - [value value])) - [left right] (..use capability 123)] - (is? left right)))} + (capability: (Can_Duplicate a) + (can_duplicate a [a a])) + + (let [capability (can_duplicate + (function (_ value) + [value value])) + [left right] (..use capability 123)] + (is? left right)))} (do {! meta.monad} [this_module meta.current_module_name .let [[name vars] declaration] g!brand (\ ! map (|>> %.code code.text) - (macro.gensym (format (%.name [this_module name])))) + (macro.identifier (format (%.name [this_module name])))) .let [capability (` (..Capability (.primitive (~ g!brand)) (~ input) (~ output)))]] (in (list (` (type: (~ export_policy) (~ (|declaration|.format declaration)) @@ -77,7 +77,7 @@ )))) (def: .public (async capability) - {#.doc (doc "Converts a synchronous I/O-based capability into an asynchronous capability.")} + {#.doc (example "Converts a synchronous I/O-based capability into an asynchronous capability.")} (All [brand input output] (-> (Capability brand input (IO output)) (Capability brand input (Async output)))) diff --git a/stdlib/source/library/lux/control/security/policy.lux b/stdlib/source/library/lux/control/security/policy.lux index 32bf06c38..ea47056bd 100644 --- a/stdlib/source/library/lux/control/security/policy.lux +++ b/stdlib/source/library/lux/control/security/policy.lux @@ -9,38 +9,38 @@ abstract]]]) (abstract: .public (Policy brand value label) - {#.doc (doc "A security policy encoded as the means to 'upgrade' or 'downgrade' in a secure context.")} + {#.doc (example "A security policy encoded as the means to 'upgrade' or 'downgrade' in a secure context.")} value (type: .public (Can_Upgrade brand label value) - {#.doc (doc "Represents the capacity to 'upgrade' a value.")} + {#.doc (example "Represents the capacity to 'upgrade' a value.")} (-> value (Policy brand value label))) (type: .public (Can_Downgrade brand label value) - {#.doc (doc "Represents the capacity to 'downgrade' a value.")} + {#.doc (example "Represents the capacity to 'downgrade' a value.")} (-> (Policy brand value label) value)) (type: .public (Privilege brand label) - {#.doc (doc "Represents the privilege to both 'upgrade' and 'downgrade' a value.")} + {#.doc (example "Represents the privilege to both 'upgrade' and 'downgrade' a value.")} {#can_upgrade (Can_Upgrade brand label) #can_downgrade (Can_Downgrade brand label)}) (type: .public (Delegation brand from to) - {#.doc (doc "Represents the act of delegating policy capacities.")} + {#.doc (example "Represents the act of delegating policy capacities.")} (All [value] (-> (Policy brand value from) (Policy brand value to)))) (def: .public (delegation downgrade upgrade) - {#.doc (doc "Delegating policy capacities.")} + {#.doc (example "Delegating policy capacities.")} (All [brand from to] (-> (Can_Downgrade brand from) (Can_Upgrade brand to) (Delegation brand from to))) (|>> downgrade upgrade)) (type: .public (Context brand scope label) - {#.doc (doc "A computational context with an associated policy privilege.")} + {#.doc (example "A computational context with an associated policy privilege.")} (-> (Privilege brand label) (scope label))) @@ -50,27 +50,27 @@ #can_downgrade (|>> :representation)}) (def: .public (with_policy context) - {#.doc (doc "Activates a security context with the priviledge to enforce it's policy." - - (type: Password - (Private Text)) - - (interface: (Policy %) - (: (-> Text (Password %)) - password) - (: (-> (Password %) Text) - unsafe)) - - (def: (policy _) - (Ex [%] (-> Any (Policy %))) - (with_policy - (: (Context Privacy Policy) - (function (_ (^open "%::.")) - (implementation - (def: (password value) - (%::can_upgrade value)) - (def: (unsafe password) - (%::can_downgrade password))))))))} + {#.doc (example "Activates a security context with the priviledge to enforce it's policy." + + (type: Password + (Private Text)) + + (interface: (Policy %) + (: (-> Text (Password %)) + password) + (: (-> (Password %) Text) + unsafe)) + + (def: (policy _) + (Ex [%] (-> Any (Policy %))) + (with_policy + (: (Context Privacy Policy) + (function (_ (^open "%::.")) + (implementation + (def: (password value) + (%::can_upgrade value)) + (def: (unsafe password) + (%::can_downgrade password))))))))} (All [brand scope] (Ex [label] (-> (Context brand scope label) @@ -121,9 +121,9 @@ )] [Privacy Private Can_Conceal Can_Reveal - (doc "A security context for privacy." - "Private data is data which cannot be allowed to leak outside of the programmed.")] + (example "A security context for privacy." + "Private data is data which cannot be allowed to leak outside of the programmed.")] [Safety Safe Can_Trust Can_Distrust - (doc "A security context for safety." - "Safe data is data coming from outside the program which can be trusted to be properly formatted and lacking injections.")] + (example "A security context for safety." + "Safe data is data coming from outside the program which can be trusted to be properly formatted and lacking injections.")] ) diff --git a/stdlib/source/library/lux/control/state.lux b/stdlib/source/library/lux/control/state.lux index 5021d293d..9cb56fb89 100644 --- a/stdlib/source/library/lux/control/state.lux +++ b/stdlib/source/library/lux/control/state.lux @@ -41,7 +41,7 @@ (let [[state' output] (action (change state))] [state output]))) -(def: .public (run state action) +(def: .public (result state action) {#.doc "Run a stateful computation."} (All [s a] (-> s (State s a) [s a])) (action state)) @@ -80,7 +80,7 @@ (ma state'))))) (def: .public (while condition body) - {#.doc (doc "A stateful while loop.")} + {#.doc (example "A stateful while loop.")} (All [s] (-> (State s Bit) (State s Any) (State s Any))) (do {! ..monad} [execute? condition] @@ -91,7 +91,7 @@ (in [])))) (def: .public (do_while condition body) - {#.doc (doc "A stateful do-while loop.")} + {#.doc (example "A stateful do-while loop.")} (All [s] (-> (State s Bit) (State s Any) (State s Any))) (do ..monad [_ body] @@ -121,7 +121,7 @@ {#.doc "Stateful computations decorated by a monad."} (-> s (M [s a]))) -(def: .public (run' state action) +(def: .public (result' state action) {#.doc "Execute a stateful computation decorated by a monad."} (All [M s a] (-> s (+State M s a) (M [s a]))) (action state)) diff --git a/stdlib/source/library/lux/control/thread.lux b/stdlib/source/library/lux/control/thread.lux index 8b6323863..c0a8c5955 100644 --- a/stdlib/source/library/lux/control/thread.lux +++ b/stdlib/source/library/lux/control/thread.lux @@ -15,7 +15,7 @@ abstract]]]) (type: .public (Thread ! a) - {#.doc (doc "An imperative process with access to mutable values.")} + {#.doc (example "An imperative process with access to mutable values.")} (-> ! a)) (abstract: .public (Box t v) @@ -24,7 +24,7 @@ (Array v) (def: .public (box init) - {#.doc (doc "A brand-new box initialized to the given value.")} + {#.doc (example "A brand-new box initialized to the given value.")} (All [a] (-> a (All [!] (Thread ! (Box ! a))))) (function (_ !) (|> (array.empty 1) @@ -32,7 +32,7 @@ :abstraction))) (def: .public (read box) - {#.doc (doc "Reads the current value in the box.")} + {#.doc (example "Reads the current value in the box.")} (All [! a] (-> (Box ! a) (Thread ! a))) (function (_ !) (for {@.old @@ -54,25 +54,25 @@ @.scheme ("scheme array read" 0 (:representation box))}))) (def: .public (write value box) - {#.doc (doc "Mutates the value in the box.")} + {#.doc (example "Mutates the value in the box.")} (All [a] (-> a (All [!] (-> (Box ! a) (Thread ! Any))))) (function (_ !) (|> box :representation (array.write! 0 value) :abstraction))) ) -(def: .public (run thread) - {#.doc (doc "Executes the imperative thread in a self-contained way.")} +(def: .public (result thread) + {#.doc (example "Executes the imperative thread in a self-contained way.")} (All [a] (-> (All [!] (Thread ! a)) a)) (thread [])) (def: .public io - {#.doc (doc "Transforms the imperative thread into an I/O computation.")} + {#.doc (example "Transforms the imperative thread into an I/O computation.")} (All [a] (-> (All [!] (Thread ! a)) (IO a))) - (|>> ..run io.io)) + (|>> ..result io.io)) (implementation: .public functor (All [!] (Functor (Thread !))) @@ -105,7 +105,7 @@ ((ffa !) !)))) (def: .public (update f box) - {#.doc (doc "Update a box's value by applying a function to it.")} + {#.doc (example "Update a box's value by applying a function to it.")} (All [a !] (-> (-> a a) (Box ! a) (Thread ! a))) (do ..monad [old (read box) diff --git a/stdlib/source/library/lux/control/try.lux b/stdlib/source/library/lux/control/try.lux index 6d547f778..7e785b6fa 100644 --- a/stdlib/source/library/lux/control/try.lux +++ b/stdlib/source/library/lux/control/try.lux @@ -10,7 +10,7 @@ ["." location]]]]) (type: .public (Try a) - {#.doc (doc "A computation that can fail with an error message.")} + {#.doc (example "A computation that can fail with an error message.")} (#Failure Text) (#Success a)) @@ -60,7 +60,7 @@ ma))) (implementation: .public (with monad) - {#.doc (doc "Enhances a monad with error-handling functionality.")} + {#.doc (example "Enhances a monad with error-handling functionality.")} ... TODO: Replace (All [a] (! (Try a))) with (functor.Then ! Try) (All [!] (-> (Monad !) (Monad (All [a] (! (Try a)))))) @@ -82,7 +82,7 @@ Mea)))) (def: .public (lifted monad) - {#.doc (doc "Wraps a monadic value with error-handling machinery.")} + {#.doc (example "Wraps a monadic value with error-handling machinery.")} (All [! a] (-> (Monad !) (-> (! a) (! (Try a))))) (\ monad map (\ ..monad in))) @@ -102,16 +102,16 @@ ))) (def: .public (assumed try) - {#.doc (doc "Assumes a Try value succeeded, and yields its value." - "If it didn't, raises the error as a runtime error." - "WARNING: Use with caution.")} + {#.doc (example "Assumes a Try value succeeded, and yields its value." + "If it didn't, raises the error as a runtime error." + "WARNING: Use with caution.")} (All [a] (-> (Try a) a)) (case try (#Success value) value (#Failure message) - (error! message))) + (panic! message))) (def: .public (maybe try) (All [a] (-> (Try a) (Maybe a))) @@ -133,13 +133,13 @@ (name_of ..of_maybe)))))) (macro: .public (else tokens compiler) - {#.doc (doc "Allows you to provide a default value that will be used" - "if a (Try x) value turns out to be #Failure." - "Note: the expression for the default value will not be computed if the base computation succeeds." - (= "bar" - (else "foo" (#..Success "bar"))) - (= "foo" - (else "foo" (#..Failure "KABOOM!"))))} + {#.doc (example "Allows you to provide a default value that will be used" + "if a (Try x) value turns out to be #Failure." + "Note: the expression for the default value will not be computed if the base computation succeeds." + (= "bar" + (else "foo" (#..Success "bar"))) + (= "foo" + (else "foo" (#..Failure "KABOOM!"))))} (case tokens (^ (list else try)) (#Success [compiler (list (` (case (~ try) diff --git a/stdlib/source/library/lux/control/writer.lux b/stdlib/source/library/lux/control/writer.lux index c02d6f8bb..7ac976d6b 100644 --- a/stdlib/source/library/lux/control/writer.lux +++ b/stdlib/source/library/lux/control/writer.lux @@ -51,7 +51,7 @@ [(\ monoid compose log1 log2) a]))) (implementation: .public (with monoid monad) - {#.doc (doc "Enhances a monad with Writer functionality.")} + {#.doc (example "Enhances a monad with Writer functionality.")} (All [l M] (-> (Monoid l) (Monad M) (Monad (All [a] (M (Writer l a)))))) (def: &functor @@ -73,7 +73,7 @@ (in [(\ monoid compose l1 l2) a])))) (def: .public (lift monoid monad) - {#.doc (doc "Wraps a monadic value with Writer machinery.")} + {#.doc (example "Wraps a monadic value with Writer machinery.")} (All [l M a] (-> (Monoid l) (Monad M) (-> (M a) (M (Writer l a))))) diff --git a/stdlib/source/library/lux/data/binary.lux b/stdlib/source/library/lux/data/binary.lux index ef3ad5f91..b1290557f 100644 --- a/stdlib/source/library/lux/data/binary.lux +++ b/stdlib/source/library/lux/data/binary.lux @@ -8,10 +8,10 @@ [equivalence (#+ Equivalence)] [monoid (#+ Monoid)]] [control + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)]] [data - ["." maybe] [text ["%" format (#+ format)]] [collection @@ -33,7 +33,7 @@ ["Offset" (%.nat offset)] ["Length" (%.nat length)])) -(with_expansions [ (as_is {#.doc (doc "A binary BLOB of data.")}) +(with_expansions [ (as_is {#.doc (example "A binary BLOB of data.")}) (as_is (type: .public Binary (ffi.type [byte])) @@ -170,8 +170,8 @@ (-> Binary Nat) (|>> !size)) -(def: .public (create size) - {#.doc (doc "A fresh/empty binary BLOB of the specified size.")} +(def: .public (empty size) + {#.doc (example "A fresh/empty binary BLOB of the specified size.")} (-> Nat Binary) (for {@.old (ffi.array byte size) @.jvm (ffi.array byte size) @@ -200,14 +200,14 @@ output)))) (def: .public (read/8! index binary) - {#.doc (doc "Read 1 byte (8 bits) at the given index.")} + {#.doc (example "Read 1 byte (8 bits) at the given index.")} (-> Nat Binary (Try I64)) (if (n.< (..!size binary) index) (#try.Success (!read index binary)) (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (read/16! index binary) - {#.doc (doc "Read 2 bytes (16 bits) at the given index.")} + {#.doc (example "Read 2 bytes (16 bits) at the given index.")} (-> Nat Binary (Try I64)) (if (n.< (..!size binary) (n.+ 1 index)) (#try.Success ($_ i64.or @@ -216,7 +216,7 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (read/32! index binary) - {#.doc (doc "Read 4 bytes (32 bits) at the given index.")} + {#.doc (example "Read 4 bytes (32 bits) at the given index.")} (-> Nat Binary (Try I64)) (if (n.< (..!size binary) (n.+ 3 index)) (#try.Success ($_ i64.or @@ -227,7 +227,7 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (read/64! index binary) - {#.doc (doc "Read 8 bytes (64 bits) at the given index.")} + {#.doc (example "Read 8 bytes (64 bits) at the given index.")} (-> Nat Binary (Try I64)) (if (n.< (..!size binary) (n.+ 7 index)) (#try.Success ($_ i64.or @@ -242,7 +242,7 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (write/8! index value binary) - {#.doc (doc "Write 1 byte (8 bits) at the given index.")} + {#.doc (example "Write 1 byte (8 bits) at the given index.")} (-> Nat (I64 Any) Binary (Try Binary)) (if (n.< (..!size binary) index) (#try.Success (|> binary @@ -250,7 +250,7 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (write/16! index value binary) - {#.doc (doc "Write 2 bytes (16 bits) at the given index.")} + {#.doc (example "Write 2 bytes (16 bits) at the given index.")} (-> Nat (I64 Any) Binary (Try Binary)) (if (n.< (..!size binary) (n.+ 1 index)) (#try.Success (|> binary @@ -259,7 +259,7 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (write/32! index value binary) - {#.doc (doc "Write 4 bytes (32 bits) at the given index.")} + {#.doc (example "Write 4 bytes (32 bits) at the given index.")} (-> Nat (I64 Any) Binary (Try Binary)) (if (n.< (..!size binary) (n.+ 3 index)) (#try.Success (|> binary @@ -270,7 +270,7 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (write/64! index value binary) - {#.doc (doc "Write 8 bytes (64 bits) at the given index.")} + {#.doc (example "Write 8 bytes (64 bits) at the given index.")} (-> Nat (I64 Any) Binary (Try Binary)) (if (n.< (..!size binary) (n.+ 7 index)) (for {@.scheme (let [write_high (|>> (!write index (i64.right_shifted 56 value)) @@ -323,7 +323,7 @@ ["Target output space" (%.nat target_output)]))) (def: .public (copy bytes source_offset source target_offset target) - {#.doc (doc "Mutates the target binary BLOB by copying bytes from the source BLOB to it.")} + {#.doc (example "Mutates the target binary BLOB by copying bytes from the source BLOB to it.")} (-> Nat Nat Binary Nat Binary (Try Binary)) (with_expansions [ (as_is (do try.monad [_ (java/lang/System::arraycopy source (.int source_offset) target (.int target_offset) (.int bytes))] @@ -345,7 +345,7 @@ (#try.Success target)))))))) (def: .public (slice offset length binary) - {#.doc (doc "Yields a subset of the binary BLOB, so long as the specified range is valid.")} + {#.doc (example "Yields a subset of the binary BLOB, so long as the specified range is valid.")} (-> Nat Nat Binary (Try Binary)) (let [size (..!size binary) limit (n.+ length offset)] @@ -356,10 +356,10 @@ @.jvm } ... Default - (..copy length offset binary 0 (..create length))))))) + (..copy length offset binary 0 (..empty length))))))) (def: .public (drop bytes binary) - {#.doc (doc "Yields a binary BLOB with at most the specified number of bytes removed.")} + {#.doc (example "Yields a binary BLOB with at most the specified number of bytes removed.")} (-> Nat Binary Binary) (case bytes 0 binary @@ -369,18 +369,18 @@ slice (#try.Failure _) - (..create 0))))) + (..empty 0))))) (implementation: .public monoid (Monoid Binary) (def: identity - (..create 0)) + (..empty 0)) (def: (compose left right) (let [sizeL (!size left) sizeR (!size right) - output (..create (n.+ sizeL sizeR))] + output (..empty (n.+ sizeL sizeR))] (exec (..copy sizeL 0 left 0 output) (..copy sizeR 0 right sizeL output) diff --git a/stdlib/source/library/lux/data/bit.lux b/stdlib/source/library/lux/data/bit.lux index 69111ccb4..22ff7fe2f 100644 --- a/stdlib/source/library/lux/data/bit.lux +++ b/stdlib/source/library/lux/data/bit.lux @@ -61,7 +61,7 @@ _ (#.Left "Wrong syntax for Bit.")))) (def: .public complement - {#.doc (doc "Generates the complement of a predicate." - "That is a predicate that returns the oposite of the original predicate.")} + {#.doc (example "Generates the complement of a predicate." + "That is a predicate that returns the oposite of the original predicate.")} (All [a] (-> (-> a Bit) (-> a Bit))) (function.compose not)) diff --git a/stdlib/source/library/lux/data/collection/array.lux b/stdlib/source/library/lux/data/collection/array.lux index 8a3d0db92..af865d541 100644 --- a/stdlib/source/library/lux/data/collection/array.lux +++ b/stdlib/source/library/lux/data/collection/array.lux @@ -8,9 +8,10 @@ [equivalence (#+ Equivalence)] [fold (#+ Fold)] [predicate (#+ Predicate)]] + [control + ["." maybe]] [data ["." product] - ["." maybe] [collection ["." list ("#\." fold)]]] [math @@ -36,7 +37,7 @@ (as_is)) (def: .public (empty size) - {#.doc (doc "An empty array of the specified size.")} + {#.doc (example "An empty array of the specified size.")} (All [a] (-> Nat (Array a))) (for {@.old (:assume ("jvm anewarray" "(java.lang.Object )" size)) @@ -109,7 +110,7 @@ #.None)) (def: .public (write! index value array) - {#.doc (doc "Mutate the array by writing a value to the specified index.")} + {#.doc (example "Mutate the array by writing a value to the specified index.")} (All [a] (-> Nat a (Array a) (Array a))) (for {@.old @@ -129,7 +130,7 @@ @.scheme ("scheme array write" index value array)})) (def: .public (delete! index array) - {#.doc (doc "Mutate the array by deleting the value at the specified index.")} + {#.doc (example "Mutate the array by deleting the value at the specified index.")} (All [a] (-> Nat (Array a) (Array a))) (if (n.< (size array) index) @@ -159,7 +160,7 @@ false)) (def: .public (update! index transform array) - {#.doc (doc "Mutate the array by updating the value at the specified index.")} + {#.doc (example "Mutate the array by updating the value at the specified index.")} (All [a] (-> Nat (-> a a) (Array a) (Array a))) (case (read index array) @@ -170,8 +171,8 @@ (write! index (transform value) array))) (def: .public (upsert! index default transform array) - {#.doc (doc "Mutate the array by updating the value at the specified index." - "If there is no value, update and write the default value given.")} + {#.doc (example "Mutate the array by updating the value at the specified index." + "If there is no value, update and write the default value given.")} (All [a] (-> Nat a (-> a a) (Array a) (Array a))) (write! index @@ -179,7 +180,7 @@ array)) (def: .public (copy! length src_start src_array dest_start dest_array) - {#.doc (doc "Writes the contents of one array into the other.")} + {#.doc (example "Writes the contents of one array into the other.")} (All [a] (-> Nat Nat (Array a) Nat (Array a) (Array a))) @@ -214,7 +215,7 @@ (n.- (..occupancy array) (..size array))) (def: .public (filter! p xs) - {#.doc (doc "Delete every item of the array that fails to satisfy the predicate.")} + {#.doc (example "Delete every item of the array that fails to satisfy the predicate.")} (All [a] (-> (Predicate a) (Array a) (Array a))) (list\fold (function (_ idx xs') @@ -230,7 +231,7 @@ (list.indices (size xs)))) (def: .public (find p xs) - {#.doc (doc "Yields the first item in the array that satisfies the predicate.")} + {#.doc (example "Yields the first item in the array that satisfies the predicate.")} (All [a] (-> (Predicate a) (Array a) (Maybe a))) (let [arr_size (size xs)] @@ -264,7 +265,7 @@ #.None)))) (def: .public (clone xs) - {#.doc (doc "Yields a shallow clone of the array.")} + {#.doc (example "Yields a shallow clone of the array.")} (All [a] (-> (Array a) (Array a))) (let [arr_size (size xs)] (list\fold (function (_ idx ys) @@ -289,7 +290,7 @@ (dec 0)) (def: .public (list array) - {#.doc (doc "Yields a list with every non-empty item in the array.")} + {#.doc (example "Yields a list with every non-empty item in the array.")} (All [a] (-> (Array a) (List a))) (loop [idx (dec (size array)) output #.End] @@ -307,7 +308,7 @@ output))))) (def: .public (list' default array) - {#.doc (doc "Like 'list', but uses the 'default' value when encountering an empty cell in the array.")} + {#.doc (example "Like 'list', but uses the 'default' value when encountering an empty cell in the array.")} (All [a] (-> a (Array a) (List a))) (loop [idx (dec (size array)) output #.End] diff --git a/stdlib/source/library/lux/data/collection/bits.lux b/stdlib/source/library/lux/data/collection/bits.lux index d88827cf1..d7063ac08 100644 --- a/stdlib/source/library/lux/data/collection/bits.lux +++ b/stdlib/source/library/lux/data/collection/bits.lux @@ -4,9 +4,9 @@ [abstract [equivalence (#+ Equivalence)]] [control - pipe] + pipe + ["." maybe]] [data - ["." maybe] [collection ["." array (#+ Array) ("#\." fold)]]] [math @@ -21,7 +21,7 @@ i64.width) (type: .public Bits - {#.doc (doc "A bit-map.")} + {#.doc (example "A bit-map.")} (Array Chunk)) (def: empty_chunk @@ -33,10 +33,10 @@ (array.empty 0)) (def: .public (size bits) - {#.doc (doc "Measures the size of a bit-map by counting all the 1s in the bit-map.")} + {#.doc (example "Measures the size of a bit-map by counting all the 1s in the bit-map.")} (-> Bits Nat) (array\fold (function (_ chunk total) - (|> chunk i64.count (n.+ total))) + (|> chunk i64.ones (n.+ total))) 0 bits)) diff --git a/stdlib/source/library/lux/data/collection/dictionary.lux b/stdlib/source/library/lux/data/collection/dictionary.lux index 49c684929..e86eb437b 100644 --- a/stdlib/source/library/lux/data/collection/dictionary.lux +++ b/stdlib/source/library/lux/data/collection/dictionary.lux @@ -6,10 +6,10 @@ [equivalence (#+ Equivalence)] [functor (#+ Functor)]] [control + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)]] [data - ["." maybe] ["." product] [collection ["." list ("#\." fold functor monoid)] @@ -207,7 +207,7 @@ ... 1s within the bitmap. (def: bitmap_size (-> Bit_Map Nat) - i64.count) + i64.ones) ... A mask that, for a given bit position, only allows all the 1s prior ... to it, which would indicate the bitmap-size (and, thus, index) @@ -565,7 +565,7 @@ (get@ #..hash)) (def: .public (empty key_hash) - {#.doc (doc "An empty dictionary.")} + {#.doc (example "An empty dictionary.")} (All [k v] (-> (Hash k) (Dictionary k v))) {#hash key_hash #root empty_node}) @@ -611,8 +611,8 @@ (put key (f val) dict))) (def: .public (upsert key default f dict) - {#.doc (doc "Updates the value at the key; if it exists." - "Otherwise, puts a value by applying the function to a default.")} + {#.doc (example "Updates the value at the key; if it exists." + "Otherwise, puts a value by applying the function to a default.")} (All [k v] (-> k v (-> v v) (Dictionary k v) (Dictionary k v))) (..put key (f (maybe.else default @@ -651,16 +651,16 @@ ) (def: .public (merged dict2 dict1) - {#.doc (doc "Merges 2 dictionaries." - "If any collisions with keys occur, the values of dict2 will overwrite those of dict1.")} + {#.doc (example "Merges 2 dictionaries." + "If any collisions with keys occur, the values of dict2 will overwrite those of dict1.")} (All [k v] (-> (Dictionary k v) (Dictionary k v) (Dictionary k v))) (list\fold (function (_ [key val] dict) (put key val dict)) dict1 (entries dict2))) (def: .public (merged_with f dict2 dict1) - {#.doc (doc "Merges 2 dictionaries." - "If any collisions with keys occur, a new value will be computed by applying 'f' to the values of dict2 and dict1.")} + {#.doc (example "Merges 2 dictionaries." + "If any collisions with keys occur, a new value will be computed by applying 'f' to the values of dict2 and dict1.")} (All [k v] (-> (-> v v v) (Dictionary k v) (Dictionary k v) (Dictionary k v))) (list\fold (function (_ [key val2] dict) (case (get key dict) @@ -673,7 +673,7 @@ (entries dict2))) (def: .public (re_bind from_key to_key dict) - {#.doc (doc "If there is a value under 'from_key', remove 'from_key' and store the value under 'to_key'.")} + {#.doc (example "If there is a value under 'from_key', remove 'from_key' and store the value under 'to_key'.")} (All [k v] (-> k k (Dictionary k v) (Dictionary k v))) (case (get from_key dict) #.None diff --git a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux index b64cf7067..6d343f573 100644 --- a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux +++ b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux @@ -5,9 +5,10 @@ equivalence [monad (#+ Monad do)] ["." order (#+ Order)]] + [control + ["." maybe]] [data ["p" product] - ["." maybe] [collection ["." list ("#\." monoid fold)]]] [macro @@ -45,12 +46,12 @@ ) (type: .public (Dictionary k v) - {#.doc (doc "A dictionary data-structure with ordered entries.")} + {#.doc (example "A dictionary data-structure with ordered entries.")} {#&order (Order k) #root (Maybe (Node k v))}) (def: .public (empty order) - {#.doc (doc "An empty dictionary, employing the given order.")} + {#.doc (example "An empty dictionary, employing the given order.")} (All [k v] (-> (Order k) (Dictionary k v))) {#&order order #root #.None}) @@ -102,7 +103,7 @@ (template [ ] [(def: .public ( dict) - {#.doc (doc (~~ (template.text ["Yields value under the " "imum key."])))} + {#.doc (example (~~ (template.text ["Yields value under the " "imum key."])))} (All [k v] (-> (Dictionary k v) (Maybe v))) (case (get@ #root dict) #.None @@ -148,7 +149,7 @@ ))] [blackened #Red #Black self] - [reddened #Black #Red (error! error_message)] + [reddened #Black #Red (panic! error_message)] ) (def: (with_left addition center) @@ -360,7 +361,7 @@ (\ maybe.functor map reddened (get@ #right right))))) _ - (error! error_message)) + (panic! error_message)) )) (def: (without_right key value ?left ?right) @@ -389,7 +390,7 @@ (#.Some (black key value (get@ #right left>>right) ?right))) _ - (error! error_message) + (panic! error_message) ))) (def: (prepended ?left ?right) diff --git a/stdlib/source/library/lux/data/collection/dictionary/plist.lux b/stdlib/source/library/lux/data/collection/dictionary/plist.lux index a834e3036..a251109f4 100644 --- a/stdlib/source/library/lux/data/collection/dictionary/plist.lux +++ b/stdlib/source/library/lux/data/collection/dictionary/plist.lux @@ -14,8 +14,8 @@ ... https://en.wikipedia.org/wiki/Property_list (type: .public (PList a) - {#.doc (doc "A property list." - "It's a simple dictionary-like structure with Text keys.")} + {#.doc (example "A property list." + "It's a simple dictionary-like structure with Text keys.")} (List [Text a])) (def: .public empty diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index 1056c034b..fc57c691a 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -51,7 +51,7 @@ xs)) (def: .public (only keep? xs) - {#.doc (doc "A list with only values that satisfy the predicate.")} + {#.doc (example "A list with only values that satisfy the predicate.")} (All [a] (-> (Predicate a) (List a) (List a))) (case xs @@ -77,8 +77,8 @@ [in (#.Item head out)])))) (def: .public (pairs xs) - {#.doc (doc "Cut the list into pairs of 2." - "Caveat emptor: If the list has an un-even number of elements, the last one will be skipped.")} + {#.doc (example "Cut the list into pairs of 2." + "Caveat emptor: If the list has an un-even number of elements, the last one will be skipped.")} (All [a] (-> (List a) (List [a a]))) (case xs (^ (list& x1 x2 xs')) @@ -153,8 +153,8 @@ (let [[ys' xs'] (split_with' predicate #.End xs)] [(reversed ys') xs'])) -(def: .public (chunk size list) - {#.doc "Segment the list in chunks of the given size."} +(def: .public (sub size list) + {#.doc "Segment the list into sub-lists of (at most) the given size."} (All [a] (-> Nat (List a) (List (List a)))) (case list #.End @@ -162,7 +162,7 @@ _ (let [[pre post] (split size list)] - (#.Item pre (chunk size post))))) + (#.Item pre (sub size post))))) (def: .public (repeated n x) {#.doc "A list of the value x, repeated n times."} @@ -244,7 +244,7 @@ #.None)) xs)) -(def: .public (interpose sep xs) +(def: .public (interposed sep xs) {#.doc "Puts a value between every two elements in the list."} (All [a] (-> a (List a) (List a))) @@ -256,7 +256,7 @@ xs (#.Item x xs') - (list& x sep (interpose sep xs')))) + (list& x sep (interposed sep xs')))) (def: .public (size list) (All [a] (-> (List a) Nat)) @@ -375,8 +375,8 @@ (def: join (|>> reversed (fold compose identity)))) -(def: .public (sort < xs) - {#.doc (doc "A list ordered by a comparison function.")} +(def: .public (sorted < xs) + {#.doc (example "A list ordered by a comparison function.")} (All [a] (-> (-> a a Bit) (List a) (List a))) (case xs #.End @@ -389,7 +389,7 @@ [pre (#.Item x' post)])) [(list) (list)] xs')] - ($_ compose (sort < pre) (list x) (sort < post))))) + ($_ compose (sorted < pre) (list x) (sorted < post))))) (def: .public (empty? xs) (All [a] (Predicate (List a))) @@ -459,11 +459,11 @@ (recur input' output'))))) (macro: .public (zipped tokens state) - {#.doc (doc "Create list zippers with the specified number of input lists." - (def: .public zipped/2 (zipped 2)) - (def: .public zipped/3 (zipped 3)) - (zipped/3 xs ys zs) - ((zipped 3) xs ys zs))} + {#.doc (example "Create list zippers with the specified number of input lists." + (def: .public zipped/2 (zipped 2)) + (def: .public zipped/3 (zipped 3)) + (zipped/3 xs ys zs) + ((zipped 3) xs ys zs))} (case tokens (^ (list [_ (#.Nat num_lists)])) (if (n.> 0 num_lists) @@ -504,11 +504,11 @@ (def: .public zipped/3 (zipped 3)) (macro: .public (zipped_with tokens state) - {#.doc (doc "Create list zippers with the specified number of input lists." - (def: .public zipped_with/2 (zipped_with 2)) - (def: .public zipped_with/3 (zipped_with 3)) - (zipped_with/2 + xs ys) - ((zipped_with 2) + xs ys))} + {#.doc (example "Create list zippers with the specified number of input lists." + (def: .public zipped_with/2 (zipped_with 2)) + (def: .public zipped_with/3 (zipped_with 3)) + (zipped_with/2 + xs ys) + ((zipped_with 2) + xs ys))} (case tokens (^ (list [_ (#.Nat num_lists)])) (if (n.> 0 num_lists) @@ -564,8 +564,8 @@ (last xs'))) (def: .public (inits xs) - {#.doc (doc "For a list of size N, yields the first N-1 elements." - "Will yield a #.None for empty lists.")} + {#.doc (example "For a list of size N, yields the first N-1 elements." + "Will yield a #.None for empty lists.")} (All [a] (-> (List a) (Maybe (List a)))) (case xs #.End @@ -584,12 +584,12 @@ )) (def: .public concat - {#.doc (doc "The sequential combination of all the lists.")} + {#.doc (example "The sequential combination of all the lists.")} (All [a] (-> (List (List a)) (List a))) (\ ..monad join)) (implementation: .public (with monad) - {#.doc (doc "Enhances a monad with List functionality.")} + {#.doc (example "Enhances a monad with List functionality.")} (All [M] (-> (Monad M) (Monad (All [a] (M (List a)))))) (def: &functor (functor.compose (get@ #monad.&functor monad) ..functor)) @@ -607,7 +607,7 @@ (in (concat lla))))) (def: .public (lift monad) - {#.doc (doc "Wraps a monadic value with List machinery.")} + {#.doc (example "Wraps a monadic value with List machinery.")} (All [M a] (-> (Monad M) (-> (M a) (M (List a))))) (\ monad map (\ ..monad in))) @@ -624,11 +624,11 @@ (#.Item [idx x] (recur (inc idx) xs'))))) (macro: .public (when tokens state) - {#.doc (doc "Can be used as a guard in (co)monadic be/do expressions." - (do monad - [value (do_something 1 2 3) - ..when (passes_test? value)] - (do_something_else 4 5 6)))} + {#.doc (example "Can be used as a guard in (co)monadic be/do expressions." + (do monad + [value (do_something 1 2 3) + ..when (passes_test? value)] + (do_something_else 4 5 6)))} (case tokens (^ (.list test then)) (#.Right [state (.list (` (.if (~ test) diff --git a/stdlib/source/library/lux/data/collection/queue.lux b/stdlib/source/library/lux/data/collection/queue.lux index 80b454c58..04fd1c6b5 100644 --- a/stdlib/source/library/lux/data/collection/queue.lux +++ b/stdlib/source/library/lux/data/collection/queue.lux @@ -12,7 +12,7 @@ ["n" nat]]]]]) (type: .public (Queue a) - {#.doc (doc "A first-in, first-out sequential data-structure.")} + {#.doc (example "A first-in, first-out sequential data-structure.")} {#front (List a) #rear (List a)}) @@ -32,7 +32,7 @@ (list\compose front (list.reversed rear)))) (def: .public peek - {#.doc (doc "Yields the first value in the queue, if any.")} + {#.doc (example "Yields the first value in the queue, if any.")} (All [a] (-> (Queue a) (Maybe a))) (|>> (get@ #front) list.head)) diff --git a/stdlib/source/library/lux/data/collection/queue/priority.lux b/stdlib/source/library/lux/data/collection/queue/priority.lux index 763f1836d..138b86876 100644 --- a/stdlib/source/library/lux/data/collection/queue/priority.lux +++ b/stdlib/source/library/lux/data/collection/queue/priority.lux @@ -4,8 +4,9 @@ [abstract [equivalence (#+ Equivalence)] [monad (#+ do)]] + [control + ["." maybe]] [data - ["." maybe] [collection ["." tree #_ ["#" finger (#+ Tree)]]]] diff --git a/stdlib/source/library/lux/data/collection/row.lux b/stdlib/source/library/lux/data/collection/row.lux index b81cb2534..2a6a1020d 100644 --- a/stdlib/source/library/lux/data/collection/row.lux +++ b/stdlib/source/library/lux/data/collection/row.lux @@ -14,17 +14,17 @@ [fold (#+ Fold)] [predicate (#+ Predicate)]] [control + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)] ["p" parser ["s" code (#+ Parser)]]] [data - ["." maybe] ["." product] [collection ["." list ("#\." fold functor monoid)] ["." array (#+ Array) ("#\." functor fold)]]] - [macro (#+ with_gensyms) + [macro [syntax (#+ syntax:)] ["." code]] [math @@ -183,7 +183,7 @@ #.End)))) (type: .public (Row a) - {#.doc (doc "A sequential data-structure with fast random access.")} + {#.doc (example "A sequential data-structure with fast random access.")} {#level Level #size Nat #root (Hierarchy a) @@ -242,7 +242,7 @@ (exception: base_was_not_found) (def: .public (within_bounds? row idx) - {#.doc (doc "Determines whether the index is within the bounds of the row.")} + {#.doc (example "Determines whether the index is within the bounds of the row.")} (All [a] (-> (Row a) Nat Bit)) (n.< (get@ #size row) idx)) @@ -359,8 +359,8 @@ (|>> (get@ #size) (n.= 0))) (syntax: .public (row {elems (p.some s.any)}) - {#.doc (doc "Row literals." - (row 12 34 56 78 90))} + {#.doc (example "Row literals." + (row 12 34 56 78 90))} (in (.list (` (..of_list (.list (~+ elems))))))) (implementation: (node_equivalence Equivalence) diff --git a/stdlib/source/library/lux/data/collection/sequence.lux b/stdlib/source/library/lux/data/collection/sequence.lux index 5decabfde..f26f57d97 100644 --- a/stdlib/source/library/lux/data/collection/sequence.lux +++ b/stdlib/source/library/lux/data/collection/sequence.lux @@ -8,7 +8,7 @@ ["//" continuation (#+ Cont)] ["<>" parser ["<.>" code (#+ Parser)]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code]] [data @@ -36,8 +36,8 @@ (//.pending [x (repeated x)])) (def: .public (cycle [start next]) - {#.doc (doc "Go over the elements of a list forever." - "The list should not be empty.")} + {#.doc (example "Go over the elements of a list forever." + "The list should not be empty.")} (All [a] (-> [a (List a)] (Sequence a))) (loop [head start @@ -52,7 +52,7 @@ (template [ ] [(def: .public ( sequence) (All [a] (-> (Sequence a) )) - (let [[head tail] (//.run sequence)] + (let [[head tail] (//.result sequence)] ))] [head a] @@ -61,7 +61,7 @@ (def: .public (item idx sequence) (All [a] (-> Nat (Sequence a) a)) - (let [[head tail] (//.run sequence)] + (let [[head tail] (//.result sequence)] (case idx 0 head _ (item (dec idx) tail)))) @@ -70,7 +70,7 @@ [(def: .public ( pred xs) (All [a] (-> (Sequence a) (List a))) - (let [[x xs'] (//.run xs)] + (let [[x xs'] (//.result xs)] (if (list& x ( xs')) (list)))) @@ -78,7 +78,7 @@ (def: .public ( pred xs) (All [a] (-> (Sequence a) (Sequence a))) - (let [[x xs'] (//.run xs)] + (let [[x xs'] (//.result xs)] (if ( xs') xs))) @@ -86,7 +86,7 @@ (def: .public ( pred xs) (All [a] (-> (Sequence a) [(List a) (Sequence a)])) - (let [[x xs'] (//.run xs)] + (let [[x xs'] (//.result xs)] (if (let [[tail next] ( xs')] [(#.Item [x tail]) next]) @@ -104,17 +104,17 @@ (//.pending [x (unfold step next)]))) (def: .public (only predicate sequence) - {#.doc (doc "A new sequence only with items that satisfy the predicate.")} + {#.doc (example "A new sequence only with items that satisfy the predicate.")} (All [a] (-> (-> a Bit) (Sequence a) (Sequence a))) - (let [[head tail] (//.run sequence)] + (let [[head tail] (//.result sequence)] (if (predicate head) (//.pending [head (only predicate tail)]) (only predicate tail)))) (def: .public (partition left? xs) - {#.doc (doc "Split a sequence in two based on a predicate." - "The left side contains all entries for which the predicate is #1." - "The right side contains all entries for which the predicate is #0.")} + {#.doc (example "Split a sequence in two based on a predicate." + "The left side contains all entries for which the predicate is #1." + "The right side contains all entries for which the predicate is #0.")} (All [a] (-> (-> a Bit) (Sequence a) [(Sequence a) (Sequence a)])) [(..only left? xs) (..only (bit.complement left?) xs)]) @@ -123,7 +123,7 @@ (Functor Sequence) (def: (map f fa) - (let [[head tail] (//.run fa)] + (let [[head tail] (//.result fa)] (//.pending [(f head) (map f tail)])))) (implementation: .public comonad @@ -134,20 +134,20 @@ (def: out head) (def: (split wa) - (let [[head tail] (//.run wa)] + (let [[head tail] (//.result wa)] (//.pending [wa (split tail)])))) (syntax: .public (^sequence& {patterns (.form (<>.many .any))} body {branches (<>.some .any)}) - {#.doc (doc "Allows destructuring of sequences in pattern-matching expressions." - "Caveat emptor: Only use it for destructuring, and not for testing values within the sequences." - (let [(^sequence& x y z _tail) (some_sequence_func +1 +2 +3)] - (func x y z)))} - (with_gensyms [g!sequence] + {#.doc (example "Allows destructuring of sequences in pattern-matching expressions." + "Caveat emptor: Only use it for destructuring, and not for testing values within the sequences." + (let [(^sequence& x y z _tail) (some_sequence_func +1 +2 +3)] + (func x y z)))} + (with_identifiers [g!sequence] (let [body+ (` (let [(~+ (list\join (list\map (function (_ pattern) (list (` [(~ pattern) (~ g!sequence)]) - (` ((~! //.run) (~ g!sequence))))) + (` ((~! //.result) (~ g!sequence))))) patterns)))] (~ body)))] (in (list& g!sequence body+ branches))))) diff --git a/stdlib/source/library/lux/data/collection/set.lux b/stdlib/source/library/lux/data/collection/set.lux index 2269117ca..f3ccdc7fb 100644 --- a/stdlib/source/library/lux/data/collection/set.lux +++ b/stdlib/source/library/lux/data/collection/set.lux @@ -16,8 +16,8 @@ ["#" dictionary (#+ Dictionary)]]) (type: .public (Set a) - {#.doc (doc "An un-ordered data-structure with unique items." - "This means there is no repetition/duplication among the items.")} + {#.doc (example "An un-ordered data-structure with unique items." + "This means there is no repetition/duplication among the items.")} (Dictionary a Any)) (def: .public member_hash diff --git a/stdlib/source/library/lux/data/collection/set/multi.lux b/stdlib/source/library/lux/data/collection/set/multi.lux index 9d7d956de..4131578c1 100644 --- a/stdlib/source/library/lux/data/collection/set/multi.lux +++ b/stdlib/source/library/lux/data/collection/set/multi.lux @@ -6,7 +6,8 @@ [equivalence (#+ Equivalence)] [hash (#+ Hash)]] [control - ["." function]] + ["." function] + ["." maybe]] [math [number ["n" nat]]] @@ -15,12 +16,10 @@ ["." // [// ["." list ("#\." fold monoid)] - ["." dictionary (#+ Dictionary)] - [// - ["." maybe]]]]) + ["." dictionary (#+ Dictionary)]]]) (abstract: .public (Set a) - {#.doc (doc "A set that keeps track of repetition in its entries.")} + {#.doc (example "A set that keeps track of repetition in its entries.")} (Dictionary a Nat) @@ -96,7 +95,7 @@ subject))) (def: .public (sub? reference subject) - {#.doc (doc "Is 'subject' a sub-set of 'reference'?")} + {#.doc (example "Is 'subject' a sub-set of 'reference'?")} (All [a] (-> (Set a) (Set a) Bit)) (|> subject :representation @@ -107,7 +106,7 @@ (n.>= multiplicity)))))) (def: .public (support set) - {#.doc (doc "A set of the unique (non repeated) members.")} + {#.doc (example "A set of the unique (non repeated) members.")} (All [a] (-> (Set a) (//.Set a))) (let [(^@ set [hash _]) (:representation set)] (|> set @@ -158,6 +157,6 @@ (//.list subject))) (def: .public super? - {#.doc (doc "Is 'subject' a super-set of 'reference'?")} + {#.doc (example "Is 'subject' a super-set of 'reference'?")} (All [a] (-> (Set a) (Set a) Bit)) (function.flip sub?)) diff --git a/stdlib/source/library/lux/data/collection/set/ordered.lux b/stdlib/source/library/lux/data/collection/set/ordered.lux index 8f2992ebc..e69dba5fe 100644 --- a/stdlib/source/library/lux/data/collection/set/ordered.lux +++ b/stdlib/source/library/lux/data/collection/set/ordered.lux @@ -13,7 +13,7 @@ abstract]]]) (abstract: .public (Set a) - {#.doc (doc "A set with ordered entries.")} + {#.doc (example "A set with ordered entries.")} (/.Dictionary a a) @@ -77,13 +77,13 @@ ) (def: .public (sub? super sub) - {#.doc (doc "Is 'sub' a sub-set of 'super'?")} + {#.doc (example "Is 'sub' a sub-set of 'super'?")} (All [a] (-> (Set a) (Set a) Bit)) (|> sub ..list (list.every? (..member? super)))) (def: .public (super? sub super) - {#.doc (doc "Is 'super' a super-set of 'sub'?")} + {#.doc (example "Is 'super' a super-set of 'sub'?")} (All [a] (-> (Set a) (Set a) Bit)) (sub? super sub)) diff --git a/stdlib/source/library/lux/data/collection/stack.lux b/stdlib/source/library/lux/data/collection/stack.lux index d34fe97ac..af2b3c3ea 100644 --- a/stdlib/source/library/lux/data/collection/stack.lux +++ b/stdlib/source/library/lux/data/collection/stack.lux @@ -11,7 +11,7 @@ abstract]]]) (abstract: .public (Stack a) - {#.doc (doc "A first-in, last-out sequential data-structure.")} + {#.doc (example "A first-in, last-out sequential data-structure.")} (List a) @@ -28,7 +28,7 @@ (|>> :representation //.empty?)) (def: .public (peek stack) - {#.doc (doc "Yields the top value in the stack, if any.")} + {#.doc (example "Yields the top value in the stack, if any.")} (All [a] (-> (Stack a) (Maybe a))) (case (:representation stack) #.End diff --git a/stdlib/source/library/lux/data/collection/tree.lux b/stdlib/source/library/lux/data/collection/tree.lux index 7d12bad74..69043cb63 100644 --- a/stdlib/source/library/lux/data/collection/tree.lux +++ b/stdlib/source/library/lux/data/collection/tree.lux @@ -17,12 +17,12 @@ ["." code]]]]) (type: .public (Tree a) - {#.doc (doc "A generic tree data-structure.")} + {#.doc (example "A generic tree data-structure.")} {#value a #children (List (Tree a))}) (def: .public (flat tree) - {#.doc (doc "All the leaf values of the tree, in order.")} + {#.doc (example "All the leaf values of the tree, in order.")} (All [a] (-> (Tree a) (List a))) (|> tree (get@ #children) @@ -55,12 +55,12 @@ (<>.and .any))) (syntax: .public (tree {root tree^}) - {#.doc (doc "Tree literals." - (: (Tree Nat) - (tree 12 - {34 {} - 56 {} - 78 {90 {}}})))} + {#.doc (example "Tree literals." + (: (Tree Nat) + (tree 12 + {34 {} + 56 {} + 78 {90 {}}})))} (in (list (` (~ (loop [[value children] root] (` {#value (~ value) #children (list (~+ (list\map recur children)))}))))))) diff --git a/stdlib/source/library/lux/data/collection/tree/finger.lux b/stdlib/source/library/lux/data/collection/tree/finger.lux index 207d3bc41..9c2844be7 100644 --- a/stdlib/source/library/lux/data/collection/tree/finger.lux +++ b/stdlib/source/library/lux/data/collection/tree/finger.lux @@ -12,7 +12,7 @@ ... https://en.wikipedia.org/wiki/Finger_tree (abstract: .public (Tree @ t v) - {#.doc (doc "A finger tree.")} + {#.doc (example "A finger tree.")} {#monoid (Monoid t) #tag t @@ -20,7 +20,7 @@ [(Tree @ t v) (Tree @ t v)])} (interface: .public (Builder @ t) - {#.doc (doc "A builder for finter tree structures.")} + {#.doc (example "A builder for finter tree structures.")} (: (All [v] (-> t v (Tree @ t v))) leaf) @@ -40,7 +40,7 @@ ) (implementation: .public (builder monoid) - {#.doc (doc "A new builder using the given monoid.")} + {#.doc (example "A new builder using the given monoid.")} (All [t] (Ex [@] (-> (Monoid t) (Builder @ t)))) (def: (leaf tag value) @@ -85,7 +85,7 @@ (values right)))) (def: .public (one predicate tree) - {#.doc (doc "Finds one value that meets the predicate.")} + {#.doc (example "Finds one value that meets the predicate.")} (All [@ t v] (-> (Predicate t) (Tree @ t v) (Maybe v))) (let [[monoid tag root] (:representation tree)] (if (predicate tag) @@ -105,7 +105,7 @@ ) (def: .public (exists? predicate tree) - {#.doc (doc "Verifies that a value exists which meets the predicate.")} + {#.doc (example "Verifies that a value exists which meets the predicate.")} (All [@ t v] (-> (Predicate t) (Tree @ t v) Bit)) (case (..one predicate tree) (#.Some _) diff --git a/stdlib/source/library/lux/data/collection/tree/zipper.lux b/stdlib/source/library/lux/data/collection/tree/zipper.lux index 874c63ee8..b6fb27355 100644 --- a/stdlib/source/library/lux/data/collection/tree/zipper.lux +++ b/stdlib/source/library/lux/data/collection/tree/zipper.lux @@ -7,9 +7,10 @@ [comonad (#+ CoMonad)] [monad (#+ do)] [equivalence (#+ Equivalence)]] + [control + ["." maybe ("#\." monad)]] [data ["." product] - ["." maybe ("#\." monad)] [text ["%" format (#+ format)]] [collection diff --git a/stdlib/source/library/lux/data/color.lux b/stdlib/source/library/lux/data/color.lux index ef2bff638..673e74e60 100644 --- a/stdlib/source/library/lux/data/color.lux +++ b/stdlib/source/library/lux/data/color.lux @@ -42,28 +42,28 @@ (|>> (f.* rgb_factor) f.int .nat)) (type: .public RGB - {#.doc (doc "Red-Green-Blue color format.")} + {#.doc (example "Red-Green-Blue color format.")} {#red Nat #green Nat #blue Nat}) (type: .public HSL - {#.doc (doc "Hue-Saturation-Lightness color format.")} + {#.doc (example "Hue-Saturation-Lightness color format.")} [Frac Frac Frac]) (type: .public CMYK - {#.doc (doc "Cyan-Magenta-Yellow-Key color format.")} + {#.doc (example "Cyan-Magenta-Yellow-Key color format.")} {#cyan Frac #magenta Frac #yellow Frac #key Frac}) (type: .public HSB - {#.doc (doc "Hue-Saturation-Brightness color format.")} + {#.doc (example "Hue-Saturation-Brightness color format.")} [Frac Frac Frac]) (abstract: .public Color - {#.doc (doc "A color value, independent of color format.")} + {#.doc (example "A color value, independent of color format.")} RGB @@ -128,7 +128,7 @@ (|> ..top (n.- value))) (def: .public (complement color) - {#.doc (doc "The opposite color.")} + {#.doc (example "The opposite color.")} (-> Color Color) (let [[red green blue] (:representation color)] (:abstraction {#red (complement' red) @@ -363,7 +363,7 @@ (syntax: (color_scheme_documentation {name .local_identifier}) (let [name (text.replaced "_" "-" name) g!documentation (code.text (format "A " name " color scheme."))] - (in (list (` {#.doc (.doc (~ g!documentation))}))))) + (in (list (` {#.doc (.example (~ g!documentation))}))))) (template [ <1> <2>] [(`` (def: .public ( color) @@ -412,7 +412,7 @@ (syntax: (palette_documentation {name .local_identifier}) (let [name (text.replaced "_" "-" name) g!documentation (code.text (format "A " name " palette."))] - (in (list (` {#.doc (.doc (~ g!documentation))}))))) + (in (list (` {#.doc (.example (~ g!documentation))}))))) (`` (def: .public (analogous spread variations color) (~~ (..palette_documentation analogous)) @@ -439,25 +439,25 @@ of_hsb)))))) (type: .public Alpha - {#.doc (doc "The degree of transparency of a pigment.")} + {#.doc (example "The degree of transparency of a pigment.")} Rev) (def: .public transparent - {#.doc (doc "The maximum degree of transparency.")} + {#.doc (example "The maximum degree of transparency.")} Alpha rev\bottom) (def: .public translucent - {#.doc (doc "The average degree of transparency.")} + {#.doc (example "The average degree of transparency.")} Alpha .5) (def: .public opaque - {#.doc (doc "The minimum degree of transparency.")} + {#.doc (example "The minimum degree of transparency.")} Alpha rev\top) (type: .public Pigment - {#.doc (doc "A color with some degree of transparency.")} + {#.doc (example "A color with some degree of transparency.")} {#color Color #alpha Alpha}) diff --git a/stdlib/source/library/lux/data/color/named.lux b/stdlib/source/library/lux/data/color/named.lux index 7637e1514..32e395bb1 100644 --- a/stdlib/source/library/lux/data/color/named.lux +++ b/stdlib/source/library/lux/data/color/named.lux @@ -27,7 +27,7 @@ (template [ ] [(`` (def: .public - {#.doc (doc (~~ (..documentation )))} + {#.doc (example (~~ (..documentation )))} Color (//.of_rgb {#//.red (hex ) #//.green (hex ) diff --git a/stdlib/source/library/lux/data/format/binary.lux b/stdlib/source/library/lux/data/format/binary.lux index aac550b8b..f3ce9f830 100644 --- a/stdlib/source/library/lux/data/format/binary.lux +++ b/stdlib/source/library/lux/data/format/binary.lux @@ -33,22 +33,22 @@ (|>> (n.* i64.bits_per_byte) i64.mask)) (type: .public Mutation - {#.doc (doc "A mutation of binary data, tracking where in the data to transform.")} + {#.doc (example "A mutation of binary data, tracking where in the data to transform.")} (-> [Offset Binary] [Offset Binary])) (type: .public Specification - {#.doc (doc "A description of how to transform binary data.")} + {#.doc (example "A description of how to transform binary data.")} [Size Mutation]) (def: .public no_op - {#.doc (doc "A specification for empty binary data.")} + {#.doc (example "A specification for empty binary data.")} Specification [0 function.identity]) (def: .public (instance [size mutation]) - {#.doc (doc "Given a specification of how to construct binary data, yields a binary blob that matches it.")} + {#.doc (example "Given a specification of how to construct binary data, yields a binary blob that matches it.")} (-> Specification Binary) - (|> size binary.create [0] mutation product.right)) + (|> size binary.empty [0] mutation product.right)) (implementation: .public monoid (Monoid Specification) @@ -61,11 +61,11 @@ (|>> mutL mutR)])) (type: .public (Writer a) - {#.doc (doc "An operation that knows how to write information into a binary blob.")} + {#.doc (example "An operation that knows how to write information into a binary blob.")} (-> a Specification)) -(def: .public (run writer value) - {#.doc (doc "Yields a binary blob with all the information written to it.")} +(def: .public (result writer value) + {#.doc (example "Yields a binary blob with all the information written to it.")} (All [a] (-> (Writer a) a Binary)) (..instance (writer value))) @@ -110,7 +110,7 @@ (\ ..monoid compose (pre preV) (post postV)))) (def: .public (rec body) - {#.doc (doc "A combinator for recursive writers.")} + {#.doc (example "A combinator for recursive writers.")} (All [a] (-> (-> (Writer a) (Writer a)) (Writer a))) (function (recur value) (body recur value))) @@ -136,7 +136,7 @@ (|>> frac.bits ..bits/64)) (def: .public (segment size) - {#.doc (doc "Writes at most 'size' bytes of an input binary blob.")} + {#.doc (example "Writes at most 'size' bytes of an input binary blob.")} (-> Nat (Writer Binary)) (function (_ value) [size diff --git a/stdlib/source/library/lux/data/format/css.lux b/stdlib/source/library/lux/data/format/css.lux index 52a44d226..e9288ecff 100644 --- a/stdlib/source/library/lux/data/format/css.lux +++ b/stdlib/source/library/lux/data/format/css.lux @@ -1,8 +1,9 @@ (.module: [library [lux (#- and) + [control + ["." maybe]] [data - ["." maybe] [number ["." nat]] ["." text diff --git a/stdlib/source/library/lux/data/format/css/value.lux b/stdlib/source/library/lux/data/format/css/value.lux index b0f7aa086..6b36f1443 100644 --- a/stdlib/source/library/lux/data/format/css/value.lux +++ b/stdlib/source/library/lux/data/format/css/value.lux @@ -2,12 +2,12 @@ [library [lux (#- All Cursor and static false true) [control + ["." maybe] [parser ["s" code]]] [data ["." color] ["." product] - ["." maybe] [number ["n" nat] ["i" int] diff --git a/stdlib/source/library/lux/data/format/html.lux b/stdlib/source/library/lux/data/format/html.lux index bcda0d2f3..34ab99976 100644 --- a/stdlib/source/library/lux/data/format/html.lux +++ b/stdlib/source/library/lux/data/format/html.lux @@ -1,10 +1,11 @@ (.module: [library [lux (#- Meta Source comment and) - ["." function] + [control + ["." function] + ["." maybe ("#\." functor)]] [data ["." product] - ["." maybe ("#\." functor)] ["." text ["%" format (#+ format)]] [collection @@ -293,7 +294,7 @@ (-> Attributes (List [Attributes Shape]) Image Image) ($_ ..and for - (case (list\map (product.uncurry ..area) areas) + (case (list\map (product.uncurried ..area) areas) #.End (..empty "map" attributes) diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux index 5dd7e9c81..5d678fb2c 100644 --- a/stdlib/source/library/lux/data/format/json.lux +++ b/stdlib/source/library/lux/data/format/json.lux @@ -1,6 +1,6 @@ (.module: - {#.doc (.doc "Functionality for reading and writing values in the JSON format." - "For more information, please see: http://www.json.org/")} + {#.doc (.example "Functionality for reading and writing values in the JSON format." + "For more information, please see: http://www.json.org/")} [library [lux #* ["." meta (#+ monad)] @@ -11,19 +11,19 @@ ["." monad (#+ do)]] [control pipe + ["." maybe] ["." try (#+ Try)] ["<>" parser ("#\." monad) ["<.>" text (#+ Parser)]]] [data ["." bit] - ["." maybe] ["." product] ["." text ("#\." equivalence monoid)] [collection ["." list ("#\." fold functor)] ["." row (#+ Row row) ("#\." monad)] ["." dictionary (#+ Dictionary)]]] - [macro (#+ with_gensyms) + [macro [syntax (#+ syntax:)] ["." code]] [math @@ -67,14 +67,14 @@ (|>> (dictionary.of_list text.hash) #..Object)) (syntax: .public (json token) - {#.doc (doc "A simple way to produce JSON literals." - (json #null) - (json #1) - (json +123.456) - (json "this is a string") - (json ["this" "is" "an" "array"]) - (json {"this" "is" - "an" "object"}))} + {#.doc (example "A simple way to produce JSON literals." + (json #null) + (json #1) + (json +123.456) + (json "this is a string") + (json ["this" "is" "an" "array"]) + (json {"this" "is" + "an" "object"}))} (let [(^open ".") ..monad wrapper (function (_ x) (` (..json (~ x))))] (case token @@ -420,4 +420,4 @@ (Codec Text JSON) (def: encode ..format) - (def: decode (.run json_parser))) + (def: decode (.result json_parser))) diff --git a/stdlib/source/library/lux/data/format/tar.lux b/stdlib/source/library/lux/data/format/tar.lux index 802b7e03d..0278235b0 100644 --- a/stdlib/source/library/lux/data/format/tar.lux +++ b/stdlib/source/library/lux/data/format/tar.lux @@ -641,11 +641,11 @@ (Writer Header) (let [checksum (|> header (set@ #checksum ..dummy_checksum) - (format.run ..header_writer') + (format.result ..header_writer') ..checksum_code)] (|> header (set@ #checksum checksum) - (format.run ..header_writer') + (format.result ..header_writer') (format.segment ..block_size)))) (def: modification_time @@ -733,7 +733,7 @@ (def: .public writer (Writer Tar) - (let [end_of_archive (binary.create ..end_of_archive_size)] + (let [end_of_archive (binary.empty ..end_of_archive_size)] (function (_ tar) (format\compose (row\fold (function (_ next total) (format\compose total (..entry_writer next))) diff --git a/stdlib/source/library/lux/data/format/xml.lux b/stdlib/source/library/lux/data/format/xml.lux index b978eb195..637ba71f7 100644 --- a/stdlib/source/library/lux/data/format/xml.lux +++ b/stdlib/source/library/lux/data/format/xml.lux @@ -31,7 +31,7 @@ (Dictionary Attribute Text)) (def: .public attributes - {#.doc (doc "An empty set of XML attributes.")} + {#.doc (example "An empty set of XML attributes.")} Attrs (dictionary.empty name.hash)) @@ -207,14 +207,14 @@ (text.replaced text.double_quote """))) (def: .public (tag [namespace name]) - {#.doc (doc "The text format of a XML tag.")} + {#.doc (example "The text format of a XML tag.")} (-> Tag Text) (case namespace "" name _ ($_ text\compose namespace ..namespace_separator name))) (def: .public attribute - {#.doc (doc "The text format of a XML attribute.")} + {#.doc (example "The text format of a XML attribute.")} (-> Attribute Text) ..tag) @@ -273,7 +273,7 @@ text.new_line prefix ""))))) )))) (def: decode - (.run ..xml^))) + (.result ..xml^))) (implementation: .public equivalence (Equivalence XML) @@ -290,7 +290,7 @@ (n.= (list.size reference/children) (list.size sample/children)) (|> (list.zipped/2 reference/children sample/children) - (list.every? (product.uncurry =)))) + (list.every? (product.uncurried =)))) _ false))) diff --git a/stdlib/source/library/lux/data/identity.lux b/stdlib/source/library/lux/data/identity.lux index be7560d60..1a7f1ec76 100644 --- a/stdlib/source/library/lux/data/identity.lux +++ b/stdlib/source/library/lux/data/identity.lux @@ -10,7 +10,7 @@ ["." function]]]]) (type: .public (Identity a) - {#.doc (doc "A value, as is, without any extra structure super-imposed on it.")} + {#.doc (example "A value, as is, without any extra structure super-imposed on it.")} a) (implementation: .public functor diff --git a/stdlib/source/library/lux/data/lazy.lux b/stdlib/source/library/lux/data/lazy.lux deleted file mode 100644 index 9b0efc9f7..000000000 --- a/stdlib/source/library/lux/data/lazy.lux +++ /dev/null @@ -1,73 +0,0 @@ -(.module: - [library - [lux #* - [abstract - [functor (#+ Functor)] - [apply (#+ Apply)] - [monad (#+ Monad do)] - [equivalence (#+ Equivalence)]] - [control - ["." io] - [parser - ["s" code]] - [concurrency - ["." atom]]] - [macro (#+ with_gensyms) - [syntax (#+ syntax:)]] - [type - abstract]]]) - -(abstract: .public (Lazy a) - {#.doc (doc "A value specified by an expression that is calculated only at the last moment possible." - "Afterwards, the value is cached for future reference.")} - - (-> [] a) - - (def: (lazy' generator) - (All [a] (-> (-> [] a) (Lazy a))) - (let [cache (atom.atom #.None)] - (:abstraction (function (_ _) - (case (io.run (atom.read! cache)) - (#.Some value) - value - - _ - (let [value (generator [])] - (exec (io.run (atom.compare_and_swap! _ (#.Some value) cache)) - value))))))) - - (def: .public (value lazy) - (All [a] (-> (Lazy a) a)) - ((:representation lazy) []))) - -(syntax: .public (lazy expression) - {#.doc (doc "Specifies a lazy value by providing the expression that computes it.")} - (with_gensyms [g!_] - (in (list (` ((~! lazy') (function ((~ g!_) (~ g!_)) (~ expression)))))))) - -(implementation: .public (equivalence (^open "\.")) - (All [a] (-> (Equivalence a) (Equivalence (Lazy a)))) - - (def: (= left right) - (\= (..value left) - (..value right)))) - -(implementation: .public functor - (Functor Lazy) - - (def: (map f fa) - (lazy (f (value fa))))) - -(implementation: .public apply - (Apply Lazy) - - (def: &functor ..functor) - (def: (apply ff fa) - (lazy ((value ff) (value fa))))) - -(implementation: .public monad - (Monad Lazy) - - (def: &functor ..functor) - (def: in (|>> lazy)) - (def: join value)) diff --git a/stdlib/source/library/lux/data/maybe.lux b/stdlib/source/library/lux/data/maybe.lux deleted file mode 100644 index a019a4c79..000000000 --- a/stdlib/source/library/lux/data/maybe.lux +++ /dev/null @@ -1,171 +0,0 @@ -(.module: - [library - [lux (#- list) - [abstract - [monoid (#+ Monoid)] - [equivalence (#+ Equivalence)] - [hash (#+ Hash)] - [apply (#+ Apply)] - ["." functor (#+ Functor)] - ["." monad (#+ Monad do)]] - [meta - ["." location]]]]) - -... (type: (Maybe a) -... #.None -... (#.Some a)) - -(implementation: .public monoid - (All [a] (Monoid (Maybe a))) - - (def: identity #.None) - - (def: (compose mx my) - (case mx - #.None - my - - (#.Some x) - (#.Some x)))) - -(implementation: .public functor - (Functor Maybe) - - (def: (map f ma) - (case ma - #.None #.None - (#.Some a) (#.Some (f a))))) - -(implementation: .public apply - (Apply Maybe) - - (def: &functor ..functor) - - (def: (apply ff fa) - (case [ff fa] - [(#.Some f) (#.Some a)] - (#.Some (f a)) - - _ - #.None))) - -(implementation: .public monad - (Monad Maybe) - - (def: &functor ..functor) - - (def: (in x) - (#.Some x)) - - (def: (join mma) - (case mma - #.None - #.None - - (#.Some mx) - mx))) - -(implementation: .public (equivalence super) - (All [a] (-> (Equivalence a) (Equivalence (Maybe a)))) - - (def: (= mx my) - (case [mx my] - [#.None #.None] - #1 - - [(#.Some x) (#.Some y)] - (\ super = x y) - - _ - #0))) - -(implementation: .public (hash super) - (All [a] (-> (Hash a) (Hash (Maybe a)))) - - (def: &equivalence - (..equivalence (\ super &equivalence))) - - (def: (hash value) - (case value - #.None - 0 - - (#.Some value) - (\ super hash value)))) - -(implementation: .public (with monad) - (All [M] (-> (Monad M) (Monad (All [a] (M (Maybe a)))))) - - (def: &functor (functor.compose (get@ #monad.&functor monad) ..functor)) - - (def: in (|>> (\ ..monad in) (\ monad in))) - - (def: (join MmMma) - (do monad - [mMma MmMma] - (case mMma - #.None - (in #.None) - - (#.Some Mma) - Mma)))) - -(def: .public (lift monad) - {#.doc (doc "Wraps a monadic value with Maybe machinery.")} - (All [M a] (-> (Monad M) (-> (M a) (M (Maybe a))))) - (\ monad map (\ ..monad in))) - -(macro: .public (else tokens state) - {#.doc (doc "Allows you to provide a default value that will be used" - "if a (Maybe x) value turns out to be #.None." - "Note: the expression for the default value will not be computed if the base computation succeeds." - (else +20 (#.Some +10)) - "=>" - +10 - -------------------------- - (else +20 #.None) - "=>" - +20)} - (case tokens - (^ (.list else maybe)) - (let [g!temp (: Code [location.dummy (#.Identifier ["" ""])])] - (#.Right [state (.list (` (case (~ maybe) - (#.Some (~ g!temp)) - (~ g!temp) - - #.None - (~ else))))])) - - _ - (#.Left "Wrong syntax for else"))) - -(def: .public assume - {#.doc (doc "Assumes that a Maybe value is a #.Some and yields its value." - "Raises/throws a runtime error otherwise." - "WARNING: Use with caution.")} - (All [a] (-> (Maybe a) a)) - (|>> (..else (undefined)))) - -(def: .public (list value) - (All [a] (-> (Maybe a) (List a))) - (case value - #.None - #.End - - (#.Some value) - (#.Item value #.End))) - -(macro: .public (when tokens state) - {#.doc (doc "Can be used as a guard in (co)monadic be/do expressions." - (do monad - [value (do_something 1 2 3) - ..when (passes_test? value)] - (do_something_else 4 5 6)))} - (case tokens - (^ (.list test then)) - (#.Right [state (.list (` (.if (~ test) - (~ then) - #.None)))]) - - _ - (#.Left "Wrong syntax for when"))) diff --git a/stdlib/source/library/lux/data/name.lux b/stdlib/source/library/lux/data/name.lux index 901de118e..531a343b7 100644 --- a/stdlib/source/library/lux/data/name.lux +++ b/stdlib/source/library/lux/data/name.lux @@ -15,7 +15,7 @@ (template [ ] [(def: .public ( name) - {#.doc (doc )} + {#.doc (example )} (-> Name Text) (let [[module short] name] ))] diff --git a/stdlib/source/library/lux/data/product.lux b/stdlib/source/library/lux/data/product.lux index 91358313b..4173f8133 100644 --- a/stdlib/source/library/lux/data/product.lux +++ b/stdlib/source/library/lux/data/product.lux @@ -8,7 +8,7 @@ (template [ ] [(def: .public ( pair) - {#.doc (doc )} + {#.doc (example )} (All [left right] (-> [left right] )) (let [[left right] pair] @@ -19,16 +19,16 @@ ) ... https://en.wikipedia.org/wiki/Currying -(def: .public (curry f) - {#.doc (doc "Converts a 2-argument function into nested single-argument functions.")} +(def: .public (curried f) + {#.doc (example "Converts a 2-argument function into nested single-argument functions.")} (All [a b c] (-> (-> [a b] c) (-> a b c))) (function (_ x y) (f [x y]))) -(def: .public (uncurry f) - {#.doc (doc "Converts nested single-argument functions into a 2-argument function.")} +(def: .public (uncurried f) + {#.doc (example "Converts nested single-argument functions into a 2-argument function.")} (All [a b c] (-> (-> a b c) (-> [a b] c))) @@ -36,13 +36,13 @@ (let [[x y] xy] (f x y)))) -(def: .public (swap xy) +(def: .public (swapped xy) (All [a b] (-> [a b] [b a])) (let [[x y] xy] [y x])) (def: .public (apply f g) - {#.doc (doc "Apply functions to both sides of a pair.")} + {#.doc (example "Apply functions to both sides of a pair.")} (All [a b c d] (-> (-> a c) (-> b d) (-> [a b] [c d]))) @@ -50,7 +50,7 @@ [(f x) (g y)])) (def: .public (fork f g) - {#.doc (doc "Yields a pair by applying both functions to a single value.")} + {#.doc (example "Yields a pair by applying both functions to a single value.")} (All [a l r] (-> (-> a l) (-> a r) (-> a [l r]))) diff --git a/stdlib/source/library/lux/data/sum.lux b/stdlib/source/library/lux/data/sum.lux index bde3fc86f..84b19ffc3 100644 --- a/stdlib/source/library/lux/data/sum.lux +++ b/stdlib/source/library/lux/data/sum.lux @@ -8,7 +8,7 @@ (template [ ] [(def: .public ( value) - {#.doc (doc )} + {#.doc (example )} (All [left right] (-> (Or left right))) (0 value))] @@ -19,7 +19,7 @@ "Lifts value to the right side of a 2-variant."]) (def: .public (either fl fr) - {#.doc (doc "Applies a function to either side of a 2-variant.")} + {#.doc (example "Applies a function to either side of a 2-variant.")} (All [a b c] (-> (-> a c) (-> b c) (-> (Or a b) c))) @@ -29,7 +29,7 @@ (0 #1 r) (fr r)))) (def: .public (apply fl fr) - {#.doc (doc "Applies functions to both sides of a 2-variant.")} + {#.doc (example "Applies functions to both sides of a 2-variant.")} (All [l l' r r'] (-> (-> l l') (-> r r') (-> (Or l r) (Or l' r')))) diff --git a/stdlib/source/library/lux/data/text.lux b/stdlib/source/library/lux/data/text.lux index c6a418bb7..a1048d638 100644 --- a/stdlib/source/library/lux/data/text.lux +++ b/stdlib/source/library/lux/data/text.lux @@ -9,8 +9,9 @@ [order (#+ Order)] [monad (#+ do)] [codec (#+ Codec)]] + [control + ["." maybe]] [data - ["." maybe] [collection ["." list ("#\." fold)]]] [math @@ -19,7 +20,7 @@ ["." i64]]]]]) (type: .public Char - {#.doc (doc "A character code number.")} + {#.doc (example "A character code number.")} Nat) ... TODO: Instead of ints, chars should be produced fron nats. @@ -44,7 +45,7 @@ ) (def: .public line_feed - {#.doc (doc "Same as 'new_line'.")} + {#.doc (example "Same as 'new_line'.")} ..new_line) (def: .public size @@ -52,7 +53,7 @@ (|>> "lux text size")) (def: .public (char index input) - {#.doc (doc "Yields the character at the specified index.")} + {#.doc (example "Yields the character at the specified index.")} (-> Nat Text (Maybe Char)) (if (n.< ("lux text size" input) index) (#.Some ("lux text char" index input)) @@ -139,14 +140,14 @@ (..enclosed' ..double_quote)) (def: .public (clip offset size input) - {#.doc (doc "Clips a chunk of text from the input at the specified offset and of the specified size.")} + {#.doc (example "Clips a chunk of text from the input at the specified offset and of the specified size.")} (-> Nat Nat Text (Maybe Text)) (if (|> size (n.+ offset) (n.<= ("lux text size" input))) (#.Some ("lux text clip" offset size input)) #.None)) (def: .public (clip' offset input) - {#.doc (doc "Clips the remaining text from the input at the specified offset.")} + {#.doc (example "Clips the remaining text from the input at the specified offset.")} (-> Nat Text (Maybe Text)) (let [size ("lux text size" input)] (if (n.<= size offset) @@ -298,7 +299,7 @@ (def: .public (join_with separator texts) (-> Text (List Text) Text) - (|> texts (list.interpose separator) concat)) + (|> texts (list.interposed separator) concat)) (def: .public (empty? text) (-> Text Bit) diff --git a/stdlib/source/library/lux/data/text/encoding.lux b/stdlib/source/library/lux/data/text/encoding.lux index 673abe522..83474b909 100644 --- a/stdlib/source/library/lux/data/text/encoding.lux +++ b/stdlib/source/library/lux/data/text/encoding.lux @@ -1,24 +1,26 @@ (.module: [library [lux #* + [macro + ["." template]] [type abstract]]]) -... https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html - +... https://en.wikipedia.org/wiki/Character_encoding#Common_character_encodings (abstract: .public Encoding - {} + {#.doc (example "Encoding formats for text.")} Text (template [ ] - [(def: .public - Encoding - (:abstraction ))] + [(`` (def: .public + {#.doc (example (~~ (template.text ["'" "' text encoding. "])))} + Encoding + (:abstraction )))] [ascii "ASCII"] - [ibm_37 "IBM037"] + [ibm_037 "IBM037"] [ibm_273 "IBM273"] [ibm_277 "IBM277"] [ibm_278 "IBM278"] diff --git a/stdlib/source/library/lux/data/text/encoding/utf8.lux b/stdlib/source/library/lux/data/text/encoding/utf8.lux index d65231922..60955ba63 100644 --- a/stdlib/source/library/lux/data/text/encoding/utf8.lux +++ b/stdlib/source/library/lux/data/text/encoding/utf8.lux @@ -158,7 +158,7 @@ #try.Success)}))) (implementation: .public codec - {#.doc (doc "A codec for binary encoding of text as UTF-8.")} + {#.doc (example "A codec for binary encoding of text as UTF-8.")} (Codec Binary Text) (def: encode ..encode) diff --git a/stdlib/source/library/lux/data/text/escape.lux b/stdlib/source/library/lux/data/text/escape.lux index f7fbaaf46..a8e2c79cc 100644 --- a/stdlib/source/library/lux/data/text/escape.lux +++ b/stdlib/source/library/lux/data/text/escape.lux @@ -5,12 +5,11 @@ [abstract [monad (#+ do)]] [control + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)] ["<>" parser ["<.>" code]]] - [data - ["." maybe]] [math [number (#+ hex) ["n" nat]]] @@ -111,7 +110,7 @@ post_limit])) (def: .public (escaped text) - {#.doc (doc "Yields a escaped version of the text.")} + {#.doc (example "Yields a escaped version of the text.")} (-> Text Text) (loop [offset 0 previous "" @@ -193,8 +192,8 @@ (exception.except ..invalid_unicode_escape [current offset]))) (def: .public (un_escaped text) - {#.doc (doc "Yields an un-escaped text." - "Fails if it was improperly escaped.")} + {#.doc (example "Yields an un-escaped text." + "Fails if it was improperly escaped.")} (-> Text (Try Text)) (loop [offset 0 previous "" @@ -240,7 +239,7 @@ _ (format previous current)))))) (syntax: .public (literal {literal .text}) - {#.doc (doc "If given a escaped text literal, expands to an un-escaped version.")} + {#.doc (example "If given a escaped text literal, expands to an un-escaped version.")} (case (..un_escaped literal) (#try.Success un_escaped) (in (list (code.text un_escaped))) diff --git a/stdlib/source/library/lux/data/text/format.lux b/stdlib/source/library/lux/data/text/format.lux index 4cfd5cb34..612928a26 100644 --- a/stdlib/source/library/lux/data/text/format.lux +++ b/stdlib/source/library/lux/data/text/format.lux @@ -50,8 +50,8 @@ (|>> f fb))) (syntax: .public (format {fragments (<>.many .any)}) - {#.doc (doc "Text interpolation." - (format "Static part " (text static) " does not match URI: " uri))} + {#.doc (example "Text interpolation." + (format "Static part " (text static) " does not match URI: " uri))} (in (.list (` ($_ "lux text concat" (~+ fragments)))))) (template [ ] diff --git a/stdlib/source/library/lux/data/text/regex.lux b/stdlib/source/library/lux/data/text/regex.lux index ff9f48eee..a81b28c5a 100644 --- a/stdlib/source/library/lux/data/text/regex.lux +++ b/stdlib/source/library/lux/data/text/regex.lux @@ -5,6 +5,7 @@ [abstract monad] [control + ["." maybe] ["." try] ["." exception (#+ exception:)] ["<>" parser ("#\." monad) @@ -12,10 +13,9 @@ ["<.>" code]]] [data ["." product] - ["." maybe] [collection ["." list ("#\." fold monad)]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code]] [math @@ -412,68 +412,68 @@ (\ <>.monad map product.right (re_alternative^ #1 re_scoped^ current_module))) (syntax: .public (regex {pattern .text}) - {#.doc (doc "Create lexers using regular-expression syntax." - "For example:" - - "Literals" - (regex "a") - - "Wildcards" - (regex ".") - - "Escaping" - (regex "\.") - - "Character classes" - (regex "\d") - (regex "\p{Lower}") - (regex "[abc]") - (regex "[a-z]") - (regex "[a-zA-Z]") - (regex "[a-z&&[def]]") - - "Negation" - (regex "[^abc]") - (regex "[^a-z]") - (regex "[^a-zA-Z]") - (regex "[a-z&&[^bc]]") - (regex "[a-z&&[^m-p]]") - - "Combinations" - (regex "aa") - (regex "a?") - (regex "a*") - (regex "a+") - - "Specific amounts" - (regex "a{2}") - - "At least" - (regex "a{1,}") - - "At most" - (regex "a{,1}") - - "Between" - (regex "a{1,2}") - - "Groups" - (regex "a(.)c") - (regex "a(b+)c") - (regex "(\d{3})-(\d{3})-(\d{4})") - (regex "(\d{3})-(?:\d{3})-(\d{4})") - (regex "(?\d{3})-\k-(\d{4})") - (regex "(?\d{3})-\k-(\d{4})-\0") - (regex "(\d{3})-((\d{3})-(\d{4}))") - - "Alternation" - (regex "a|b") - (regex "a(.)(.)|b(.)(.)") - )} + {#.doc (example "Create lexers using regular-expression syntax." + "For example:" + + "Literals" + (regex "a") + + "Wildcards" + (regex ".") + + "Escaping" + (regex "\.") + + "Character classes" + (regex "\d") + (regex "\p{Lower}") + (regex "[abc]") + (regex "[a-z]") + (regex "[a-zA-Z]") + (regex "[a-z&&[def]]") + + "Negation" + (regex "[^abc]") + (regex "[^a-z]") + (regex "[^a-zA-Z]") + (regex "[a-z&&[^bc]]") + (regex "[a-z&&[^m-p]]") + + "Combinations" + (regex "aa") + (regex "a?") + (regex "a*") + (regex "a+") + + "Specific amounts" + (regex "a{2}") + + "At least" + (regex "a{1,}") + + "At most" + (regex "a{,1}") + + "Between" + (regex "a{1,2}") + + "Groups" + (regex "a(.)c") + (regex "a(b+)c") + (regex "(\d{3})-(\d{3})-(\d{4})") + (regex "(\d{3})-(?:\d{3})-(\d{4})") + (regex "(?\d{3})-\k-(\d{4})") + (regex "(?\d{3})-\k-(\d{4})-\0") + (regex "(\d{3})-((\d{3})-(\d{4}))") + + "Alternation" + (regex "a|b") + (regex "a(.)(.)|b(.)(.)") + )} (do meta.monad [current_module meta.current_module_name] - (case (.run (regex^ current_module) - pattern) + (case (.result (regex^ current_module) + pattern) (#try.Failure error) (meta.failure (format "Error while parsing regular-expression:" //.new_line error)) @@ -485,20 +485,20 @@ (syntax: .public (^regex {[pattern bindings] (.form (<>.and .text (<>.maybe .any)))} body {branches (<>.many .any)}) - {#.doc (doc "Allows you to test text against regular expressions." - (case some_text - (^regex "(\d{3})-(\d{3})-(\d{4})" - [_ country_code area_code place_code]) - do_some_thing_when_number - - (^regex "\w+") - do_some_thing_when_word - - _ - do_something_else))} - (with_gensyms [g!temp] + {#.doc (example "Allows you to test text against regular expressions." + (case some_text + (^regex "(\d{3})-(\d{3})-(\d{4})" + [_ country_code area_code place_code]) + do_some_thing_when_number + + (^regex "\w+") + do_some_thing_when_word + + _ + do_something_else))} + (with_identifiers [g!temp] (in (list& (` (^multi (~ g!temp) - {((~! .run) (..regex (~ (code.text pattern))) (~ g!temp)) + {((~! .result) (..regex (~ (code.text pattern))) (~ g!temp)) (#try.Success (~ (maybe.else g!temp bindings)))})) body branches)))) diff --git a/stdlib/source/library/lux/data/text/unicode/block.lux b/stdlib/source/library/lux/data/text/unicode/block.lux index e9c1298fe..16f8ba47a 100644 --- a/stdlib/source/library/lux/data/text/unicode/block.lux +++ b/stdlib/source/library/lux/data/text/unicode/block.lux @@ -22,7 +22,7 @@ ["." /// (#+ Char)]) (abstract: .public Block - {#.doc (doc "A block of valid unicode characters.")} + {#.doc (example "A block of valid unicode characters.")} (Interval Char) @@ -87,7 +87,7 @@ [(with_expansions [ (..block_name ) (template.text [ "-" " | " ])] (def: .public - {#.doc (doc )} + {#.doc (example )} Block (let [start (hex ) end (hex )] diff --git a/stdlib/source/library/lux/data/trace.lux b/stdlib/source/library/lux/data/trace.lux index 5767084eb..8917fc89a 100644 --- a/stdlib/source/library/lux/data/trace.lux +++ b/stdlib/source/library/lux/data/trace.lux @@ -31,6 +31,6 @@ ((get@ #trace wa) (\ monoid compose t1 t2)))})}))) -(def: .public (run context tracer) +(def: .public (result context tracer) (All [t a] (-> t (Trace t a) a)) (\ tracer trace context)) diff --git a/stdlib/source/library/lux/debug.lux b/stdlib/source/library/lux/debug.lux index 235528c6b..45fdba0d2 100644 --- a/stdlib/source/library/lux/debug.lux +++ b/stdlib/source/library/lux/debug.lux @@ -513,7 +513,7 @@ (def: .public (representation type value) (-> Type Any (Try Text)) - (case (.run ..representation_parser type) + (case (.result ..representation_parser type) (#try.Success representation) (#try.Success (representation value)) diff --git a/stdlib/source/library/lux/extension.lux b/stdlib/source/library/lux/extension.lux index ae9745baa..4a97254e9 100644 --- a/stdlib/source/library/lux/extension.lux +++ b/stdlib/source/library/lux/extension.lux @@ -12,7 +12,7 @@ ["." product] [collection ["." list ("#\." functor)]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) ["." code] [syntax (#+ syntax:)]] [tool @@ -56,7 +56,7 @@ .local_identifier (<>.some (..input default))))) -(template [ ] +(template [ ] [(syntax: .public ( {[name extension phase archive inputs] (..declaration (` ))} body) @@ -69,10 +69,10 @@ g!name (code.local_identifier extension) g!phase (code.local_identifier phase) g!archive (code.local_identifier archive)] - (with_gensyms [g!handler g!inputs g!error] + (with_identifiers [g!handler g!inputs g!error] (in (list (` ( (~ name) (.function ((~ g!handler) (~ g!name) (~ g!phase) (~ g!archive) (~ g!inputs)) - (.case ((~! ) (~ g!parser) (~ g!inputs)) + (.case ((~! ) (~ g!parser) (~ g!inputs)) (#.Right [(~+ (list\map (|>> product.left code.local_identifier) inputs))]) @@ -82,8 +82,8 @@ ((~! phase.failure) (~ g!error))) ))))))))] - [.any .end! .and .run "lux def analysis" analysis:] - [.any .end! .and .run "lux def synthesis" synthesis:] - [.any .end! .and .run "lux def generation" generation:] - [.any .end! .and .run "lux def directive" directive:] + [.any .end! .and .result "lux def analysis" analysis:] + [.any .end! .and .result "lux def synthesis" synthesis:] + [.any .end! .and .result "lux def generation" generation:] + [.any .end! .and .result "lux def directive" directive:] ) diff --git a/stdlib/source/library/lux/ffi.js.lux b/stdlib/source/library/lux/ffi.js.lux index 9cd8c739c..ef3837e6c 100644 --- a/stdlib/source/library/lux/ffi.js.lux +++ b/stdlib/source/library/lux/ffi.js.lux @@ -6,18 +6,18 @@ [monad (#+ do)]] [control ["." io] + ["." maybe] ["<>" parser ("#\." monad) ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ["%" format]] [collection ["." list ("#\." functor fold)]]] [type abstract] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code] ["." template]]]]) @@ -167,7 +167,7 @@ (` (let [(~ g!temp) (~ output)] (if (not ("js object null?" (~ g!temp))) (~ g!temp) - (.error! "Null is an invalid value.")))))) + (.panic! "Null is an invalid value.")))))) (type: Class_Declaration [Text (List Text)]) @@ -233,10 +233,10 @@ (~+ (list\map (with_null g!temp) g!inputs))))))))))) (syntax: .public (import: {import ..import}) - (with_gensyms [g!temp] + (with_identifiers [g!temp] (case import (#Class [[class_name class_parameters] format members]) - (with_gensyms [g!object] + (with_identifiers [g!object] (let [qualify (: (-> Text Code) (function (_ member_name) (|> format @@ -324,7 +324,7 @@ (syntax: .public (constant type {[head tail] (.tuple (<>.and .local_identifier (<>.some .local_identifier)))}) - (with_gensyms [g!_] + (with_identifiers [g!_] (let [constant (` ("js constant" (~ (code.text head))))] (case tail #.End diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index 70eafbd8d..1b0133aa8 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -8,12 +8,12 @@ [control ["." function] ["." io] + ["." maybe] ["." try (#+ Try)] ["." exception (#+ Exception exception:)] ["<>" parser ("#\." monad) ["<.>" code (#+ Parser)]]] [data - ["." maybe] ["." product] ["." text ("#\." equivalence) ["%" format (#+ format)]] @@ -21,7 +21,7 @@ ["." array] ["." list ("#\." monad fold monoid)] ["." dictionary (#+ Dictionary)]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code] ["." template]] @@ -125,9 +125,9 @@ (template [ ] [(template: .public ( value) - {#.doc (doc "Type converter." - (: - ( (: foo))))} + {#.doc (example "Type converter." + (: + ( (: foo))))} [(|> value (: ) "jvm object cast" @@ -168,9 +168,9 @@ (template [ <0> <1>] [(template: .public ( value) - {#.doc (doc "Type converter." - (: - ( (: foo))))} + {#.doc (example "Type converter." + (: + ( (: foo))))} [(|> value <0> <1>)])] [long_to_char ..Long ..Character ..long_to_int ..int_to_char] @@ -436,7 +436,7 @@ (def: (parser->replacer p ast) (-> (Parser Code) (-> Code Code)) - (case (<>.run p (list ast)) + (case (<>.result p (list ast)) (#.Right [#.End ast']) ast' @@ -1210,37 +1210,37 @@ {annotations ..annotations^} {fields (<>.some (..field_decl^ class_vars))} {methods (<>.some (..method_def^ class_vars))}) - {#.doc (doc "Allows defining JVM classes in Lux code." - "For example:" - (class: #final (TestClass A) [Runnable] - ... Fields - (#private foo boolean) - (#private bar A) - (#private baz java/lang/Object) - ... Methods - (#public [] (new [value A]) [] - (exec - (:= ::foo #1) - (:= ::bar value) - (:= ::baz "") - [])) - (#public (virtual) java/lang/Object - "") - (#public #static (static) java/lang/Object - "") - (Runnable [] (run) void - []) - ) - - "The tuple corresponds to parent interfaces." - "An optional super-class can be specified before the tuple. If not specified, java.lang.Object will be assumed." - "Fields and methods defined in the class can be used with special syntax." - "For example:" - "::resolved, for accessing the 'resolved' field." - "(:= ::resolved #1) for modifying it." - "(::new! []) for calling the class's constructor." - "(::resolve! container [value]) for calling the 'resolve' method." - )} + {#.doc (example "Allows defining JVM classes in Lux code." + "For example:" + (class: #final (TestClass A) [Runnable] + ... Fields + (#private foo boolean) + (#private bar A) + (#private baz java/lang/Object) + ... Methods + (#public [] (new [value A]) [] + (exec + (:= ::foo #1) + (:= ::bar value) + (:= ::baz "") + [])) + (#public (virtual) java/lang/Object + "") + (#public #static (static) java/lang/Object + "") + (Runnable [] (run) void + []) + ) + + "The tuple corresponds to parent interfaces." + "An optional super-class can be specified before the tuple. If not specified, java.lang.Object will be assumed." + "Fields and methods defined in the class can be used with special syntax." + "For example:" + "::resolved, for accessing the 'resolved' field." + "(:= ::resolved #1) for modifying it." + "(::new! []) for calling the class's constructor." + "(::resolve! container [value]) for calling the 'resolve' method." + )} (do meta.monad [.let [fully_qualified_class_name full_class_name method_parser (: (Parser Code) @@ -1263,9 +1263,9 @@ (.tuple (<>.some (class^ class_vars))))} {annotations ..annotations^} {members (<>.some (..method_decl^ class_vars))}) - {#.doc (doc "Allows defining JVM interfaces." - (interface: TestInterface - ([] foo [boolean String] void #throws [Exception])))} + {#.doc (example "Allows defining JVM interfaces." + (interface: TestInterface + ([] foo [boolean String] void #throws [Exception])))} (in (list (` ("jvm class interface" (~ (declaration$ (type.declaration full_class_name class_vars))) [(~+ (list\map class$ supers))] @@ -1280,17 +1280,17 @@ (.tuple (<>.some (class^ class_vars))))} {constructor_args (..constructor_args^ class_vars)} {methods (<>.some ..overriden_method_def^)}) - {#.doc (doc "Allows defining anonymous classes." - "The 1st tuple corresponds to class-level type-variables." - "The 2nd tuple corresponds to parent interfaces." - "The 3rd tuple corresponds to arguments to the super class constructor." - "An optional super-class can be specified before the 1st tuple. If not specified, java.lang.Object will be assumed." - (object [] [Runnable] - [] - (Runnable [] (run self) void - (exec (do_something some_value) - []))) - )} + {#.doc (example "Allows defining anonymous classes." + "The 1st tuple corresponds to class-level type-variables." + "The 2nd tuple corresponds to parent interfaces." + "The 3rd tuple corresponds to arguments to the super class constructor." + "An optional super-class can be specified before the 1st tuple. If not specified, java.lang.Object will be assumed." + (object [] [Runnable] + [] + (Runnable [] (run self) void + (exec (do_something some_value) + []))) + )} (in (list (` ("jvm class anonymous" [(~+ (list\map var$ class_vars))] (~ (class$ super)) @@ -1299,39 +1299,39 @@ [(~+ (list\map (method_def$ "" (<>.failure "") super (list)) methods))]))))) (syntax: .public (null) - {#.doc (doc "Null object reference." - (null))} + {#.doc (example "Null object reference." + (null))} (in (list (` ("jvm object null"))))) (def: .public (null? obj) - {#.doc (doc "Test for null object reference." - (= (null? (null)) - true) - (= (null? "YOLO") - false))} + {#.doc (example "Test for null object reference." + (= (null? (null)) + true) + (= (null? "YOLO") + false))} (-> (primitive "java.lang.Object") Bit) ("jvm object null?" obj)) (syntax: .public (??? expr) - {#.doc (doc "Takes a (potentially null) ObjectType reference and creates a (Maybe ObjectType) for it." - (= (??? (: java/lang/String (null))) - #.None) - (= (??? "YOLO") - (#.Some "YOLO")))} - (with_gensyms [g!temp] + {#.doc (example "Takes a (potentially null) ObjectType reference and creates a (Maybe ObjectType) for it." + (= (??? (: java/lang/String (null))) + #.None) + (= (??? "YOLO") + (#.Some "YOLO")))} + (with_identifiers [g!temp] (in (list (` (let [(~ g!temp) (~ expr)] (if ("jvm object null?" (~ g!temp)) #.None (#.Some (~ g!temp))))))))) (syntax: .public (!!! expr) - {#.doc (doc "Takes a (Maybe ObjectType) and returns a ObjectType." - "A #.None would get translated into a (null)." - (= (null) - (!!! (??? (: java/lang/Thread (null))))) - (= "foo" - (!!! (??? "foo"))))} - (with_gensyms [g!value] + {#.doc (example "Takes a (Maybe ObjectType) and returns a ObjectType." + "A #.None would get translated into a (null)." + (= (null) + (!!! (??? (: java/lang/Thread (null))))) + (= "foo" + (!!! (??? "foo"))))} + (with_identifiers [g!value] (in (list (` ({(#.Some (~ g!value)) (~ g!value) @@ -1341,12 +1341,12 @@ (syntax: .public (check {class (..type^ (list))} {unchecked (<>.maybe .any)}) - {#.doc (doc "Checks whether an object is an instance of a particular class." - "Caveat emptor: Cannot check for polymorphism, so avoid using parameterized classes." - (case (check String "YOLO") - (#.Some value_as_string) - #.None))} - (with_gensyms [g!_ g!unchecked] + {#.doc (example "Checks whether an object is an instance of a particular class." + "Caveat emptor: Cannot check for polymorphism, so avoid using parameterized classes." + (case (check String "YOLO") + (#.Some value_as_string) + #.None))} + (with_identifiers [g!_ g!unchecked] (let [class_name (..reflection class) class_type (` (.primitive (~ (code.text class_name)))) check_type (` (.Maybe (~ class_type))) @@ -1367,19 +1367,19 @@ )))) (syntax: .public (synchronized lock body) - {#.doc (doc "Evaluates body, while holding a lock on a given object." - (synchronized object_to_be_locked - (exec (do_something ___) - (do_something_else ___) - (finish_the_computation ___))))} + {#.doc (example "Evaluates body, while holding a lock on a given object." + (synchronized object_to_be_locked + (exec (do_something ___) + (do_something_else ___) + (finish_the_computation ___))))} (in (list (` ("jvm object synchronized" (~ lock) (~ body)))))) (syntax: .public (do_to obj {methods (<>.some partial_call^)}) - {#.doc (doc "Call a variety of methods on an object. Then, return the object." - (do_to object - (ClassName::method1 arg0 arg1 arg2) - (ClassName::method2 arg3 arg4 arg5)))} - (with_gensyms [g!obj] + {#.doc (example "Call a variety of methods on an object. Then, return the object." + (do_to object + (ClassName::method1 arg0 arg1 arg2) + (ClassName::method2 arg3 arg4 arg5)))} + (with_identifiers [g!obj] (in (list (` (let [(~ g!obj) (~ obj)] (exec (~+ (list\map (complete_call$ g!obj) methods)) (~ g!obj)))))))) @@ -1422,7 +1422,7 @@ [arg_inputs (monad.map ! (: (-> [Bit (Type Value)] (Meta [Bit Code])) (function (_ [maybe? _]) - (with_gensyms [arg_name] + (with_identifiers [arg_name] (in [maybe? arg_name])))) import_member_args) .let [input_jvm_types (list\map product.right import_member_args) @@ -1455,7 +1455,7 @@ (if (not (..null? (:as (primitive "java.lang.Object") (~ g!temp)))) (~ g!temp) - (error! "Cannot produce null references from method calls.")))))) + (panic! "Cannot produce null references from method calls.")))))) _ return_term)) @@ -1607,7 +1607,7 @@ ((~' in) (.list (.` (~ jvm_interop))))))))) (#MethodDecl [commons method]) - (with_gensyms [g!obj] + (with_identifiers [g!obj] (do meta.monad [.let [def_name (code.identifier ["" (..import_name import_format method_prefix (get@ #import_member_alias commons))]) (^slots [#import_member_kind]) commons @@ -1665,7 +1665,7 @@ [.let [(^open ".") fad getter_name (code.identifier ["" (..import_name import_format method_prefix import_field_name)]) setter_name (code.identifier ["" (..import_name import_format method_prefix (format import_field_name "!"))])] - getter_interop (with_gensyms [g!obj] + getter_interop (with_identifiers [g!obj] (let [getter_call (if import_field_static? (` ((~ getter_name))) (` ((~ getter_name) (~ g!obj)))) @@ -1684,7 +1684,7 @@ ((~' in) (.list (.` (~ getter_body))))))))) setter_interop (: (Meta (List Code)) (if import_field_setter? - (with_gensyms [g!obj g!value] + (with_identifiers [g!obj g!value] (let [setter_call (if import_field_static? (` ((~ setter_name) (~ g!value))) (` ((~ setter_name) (~ g!value) (~ g!obj)))) @@ -1743,57 +1743,57 @@ {declaration ..declaration^} {.let [[class_name class_type_vars] (parser.declaration declaration)]} {bundles (<>.some (..bundle class_type_vars))}) - {#.doc (doc "Allows importing JVM classes, and using them as types." - "Their methods, fields and enum options can also be imported." - (import: java/lang/Object - ["#::." - (new []) - (equals [java/lang/Object] boolean) - (wait [int] #io #try void)]) - - "Special options can also be given for the return values." - "#? means that the values will be returned inside a Maybe type. That way, null becomes #.None." - "#try means that the computation might throw an exception, and the return value will be wrapped by the Try type." - "#io means the computation has side effects, and will be wrapped by the IO type." - "These options must show up in the following order [#io #try #?] (although, each option can be used independently)." - (import: java/lang/String - ["#::." - (new [[byte]]) - (#static valueOf [char] java/lang/String) - (#static valueOf #as int_valueOf [int] java/lang/String)]) - - (import: (java/util/List e) - ["#::." - (size [] int) - (get [int] e)]) - - (import: (java/util/ArrayList a) - ["#::." - ([T] toArray [[T]] [T])]) - - "The class-type that is generated is of the fully-qualified name." - "This avoids a clash between the java.util.List type, and Lux's own List type." - "All enum options to be imported must be specified." - (import: java/lang/Character$UnicodeScript - ["#::." - (#enum ARABIC CYRILLIC LATIN)]) - - "It should also be noted, the only types that may show up in method arguments or return values may be Java classes, arrays, primitives, void or type-vars." - "Lux types, such as Maybe cannot be named (otherwise, they'd be confused for Java classes)." - (import: (lux/concurrency/async/JvmAsync A) - ["#::." - (resolve [A] boolean) - (poll [] A) - (wasResolved [] boolean) - (waitOn [lux/Function] void) - (#static [A] make [A] (lux/concurrency/async/JvmAsync A))]) - - "Also, the names of the imported members will look like Class::member" - (java/lang/Object::new []) - (java/lang/Object::equals [other_object] my_object) - (java/util/List::size [] my_list) - java/lang/Character$UnicodeScript::LATIN - )} + {#.doc (example "Allows importing JVM classes, and using them as types." + "Their methods, fields and enum options can also be imported." + (import: java/lang/Object + ["#::." + (new []) + (equals [java/lang/Object] boolean) + (wait [int] #io #try void)]) + + "Special options can also be given for the return values." + "#? means that the values will be returned inside a Maybe type. That way, null becomes #.None." + "#try means that the computation might throw an exception, and the return value will be wrapped by the Try type." + "#io means the computation has side effects, and will be wrapped by the IO type." + "These options must show up in the following order [#io #try #?] (although, each option can be used independently)." + (import: java/lang/String + ["#::." + (new [[byte]]) + (#static valueOf [char] java/lang/String) + (#static valueOf #as int_valueOf [int] java/lang/String)]) + + (import: (java/util/List e) + ["#::." + (size [] int) + (get [int] e)]) + + (import: (java/util/ArrayList a) + ["#::." + ([T] toArray [[T]] [T])]) + + "The class-type that is generated is of the fully-qualified name." + "This avoids a clash between the java.util.List type, and Lux's own List type." + "All enum options to be imported must be specified." + (import: java/lang/Character$UnicodeScript + ["#::." + (#enum ARABIC CYRILLIC LATIN)]) + + "It should also be noted, the only types that may show up in method arguments or return values may be Java classes, arrays, primitives, void or type-vars." + "Lux types, such as Maybe cannot be named (otherwise, they'd be confused for Java classes)." + (import: (lux/concurrency/async/JvmAsync A) + ["#::." + (resolve [A] boolean) + (poll [] A) + (wasResolved [] boolean) + (waitOn [lux/Function] void) + (#static [A] make [A] (lux/concurrency/async/JvmAsync A))]) + + "Also, the names of the imported members will look like Class::member" + (java/lang/Object::new []) + (java/lang/Object::equals [other_object] my_object) + (java/util/List::size [] my_list) + java/lang/Character$UnicodeScript::LATIN + )} (do {! meta.monad} [kind (class_kind declaration) =members (|> bundles @@ -1805,8 +1805,8 @@ (syntax: .public (array {type (..type^ (list))} size) - {#.doc (doc "Create an array of the given type, with the given size." - (array java/lang/Object 10))} + {#.doc (example "Create an array of the given type, with the given size." + (array java/lang/Object 10))} (let [g!size (` (|> (~ size) (.: .Nat) (.:as (.primitive (~ (code.text box.long)))) @@ -1924,8 +1924,8 @@ )))) (syntax: .public (array_length array) - {#.doc (doc "Gives the length of an array." - (array_length my_array))} + {#.doc (example "Gives the length of an array." + (array_length my_array))} (case array [_ (#.Identifier array_name)] (do meta.monad @@ -1955,13 +1955,13 @@ (.:as .Nat)))))) _ - (with_gensyms [g!array] + (with_identifiers [g!array] (in (list (` (let [(~ g!array) (~ array)] (..array_length (~ g!array))))))))) (syntax: .public (array_read idx array) - {#.doc (doc "Loads an element from an array." - (array_read 10 my_array))} + {#.doc (example "Loads an element from an array." + (array_read 10 my_array))} (case array [_ (#.Identifier array_name)] (do meta.monad @@ -1993,13 +1993,13 @@ (in (list (` ("jvm array read object" (~ g!idx) (~ array)))))))) _ - (with_gensyms [g!array] + (with_identifiers [g!array] (in (list (` (let [(~ g!array) (~ array)] (..array_read (~ idx) (~ g!array))))))))) (syntax: .public (array_write idx value array) - {#.doc (doc "Stores an element into an array." - (array_write 10 my_object my_array))} + {#.doc (example "Stores an element into an array." + (array_write 10 my_object my_array))} (case array [_ (#.Identifier array_name)] (do meta.monad @@ -2032,13 +2032,13 @@ (in (list (` ("jvm array write object" (~ g!idx) (~ value) (~ array)))))))) _ - (with_gensyms [g!array] + (with_identifiers [g!array] (in (list (` (let [(~ g!array) (~ array)] (..array_write (~ idx) (~ value) (~ g!array))))))))) (syntax: .public (class_for {type (..type^ (list))}) - {#.doc (doc "Loads the class as a java.lang.Class object." - (class_for java/lang/String))} + {#.doc (example "Loads the class as a java.lang.Class object." + (class_for java/lang/String))} (in (list (` ("jvm object class" (~ (code.text (..reflection type)))))))) (syntax: .public (type {type (..type^ (list))}) diff --git a/stdlib/source/library/lux/ffi.lua.lux b/stdlib/source/library/lux/ffi.lua.lux index a0ee4ab01..8370a58d4 100644 --- a/stdlib/source/library/lux/ffi.lua.lux +++ b/stdlib/source/library/lux/ffi.lua.lux @@ -7,18 +7,18 @@ [monad (#+ do)]] [control ["." io] + ["." maybe] ["<>" parser ("#\." monad) ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ["%" format]] [collection ["." list ("#\." functor fold)]]] [type abstract] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code] ["." template]]]]) @@ -154,7 +154,7 @@ (` (let [(~ g!temp) (~ output)] (if (not ("lua object nil?" (~ g!temp))) (~ g!temp) - (.error! "Nil is an invalid value!")))))) + (.panic! "Nil is an invalid value!")))))) (type: Import (#Class [Text Text (List Member)]) @@ -213,10 +213,10 @@ (~+ (list\map (with_nil g!temp) g!inputs))))))))))) (syntax: .public (import: {import ..import}) - (with_gensyms [g!temp] + (with_identifiers [g!temp] (case import (#Class [class format members]) - (with_gensyms [g!object] + (with_identifiers [g!object] (let [qualify (: (-> Text Code) (function (_ member_name) (|> format diff --git a/stdlib/source/library/lux/ffi.old.lux b/stdlib/source/library/lux/ffi.old.lux index 8c20e8ae2..3413ee442 100644 --- a/stdlib/source/library/lux/ffi.old.lux +++ b/stdlib/source/library/lux/ffi.old.lux @@ -8,11 +8,11 @@ [control ["." function] ["." io] + ["." maybe] ["." try (#+ Try)] ["<>" parser ["<.>" code (#+ Parser)]]] [data - ["." maybe] ["." product] ["." bit ("#\." codec)] ["." text ("#\." equivalence monoid) @@ -20,7 +20,7 @@ [collection ["." array (#+ Array)] ["." list ("#\." monad fold monoid)]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code]] ["." meta @@ -28,9 +28,9 @@ (template [ ] [(def: .public ( value) - {#.doc (doc "Type converter." - (: - ( (: foo))))} + {#.doc (example "Type converter." + (: + ( (: foo))))} (-> (primitive ) (primitive )) ( value))] @@ -426,7 +426,7 @@ (def: (parser_replacer p ast) (-> (Parser Code) (-> Code Code)) - (case (<>.run p (list ast)) + (case (<>.result p (list ast)) (#.Right [#.End ast']) ast' @@ -1177,36 +1177,36 @@ {annotations ..annotations^} {fields (<>.some (..field_decl^ class_vars))} {methods (<>.some (..method_def^ class_vars))}) - {#.doc (doc "Allows defining JVM classes in Lux code." - "For example:" - (class: #final (TestClass A) [Runnable] - ... Fields - (#private foo boolean) - (#private bar A) - (#private baz java/lang/Object) - ... Methods - (#public [] (new [value A]) [] - (exec (:= ::foo #1) - (:= ::bar value) - (:= ::baz "") - [])) - (#public (virtual) java/lang/Object - "") - (#public #static (static) java/lang/Object - "") - (Runnable [] (run) void - []) - ) - - "The tuple corresponds to parent interfaces." - "An optional super-class can be specified before the tuple. If not specified, java.lang.Object will be assumed." - "Fields and methods defined in the class can be used with special syntax." - "For example:" - "::resolved, for accessing the 'resolved' field." - "(:= ::resolved #1) for modifying it." - "(::new! []) for calling the class's constructor." - "(::resolve! container [value]) for calling the 'resolve' method." - )} + {#.doc (example "Allows defining JVM classes in Lux code." + "For example:" + (class: #final (TestClass A) [Runnable] + ... Fields + (#private foo boolean) + (#private bar A) + (#private baz java/lang/Object) + ... Methods + (#public [] (new [value A]) [] + (exec (:= ::foo #1) + (:= ::bar value) + (:= ::baz "") + [])) + (#public (virtual) java/lang/Object + "") + (#public #static (static) java/lang/Object + "") + (Runnable [] (run) void + []) + ) + + "The tuple corresponds to parent interfaces." + "An optional super-class can be specified before the tuple. If not specified, java.lang.Object will be assumed." + "Fields and methods defined in the class can be used with special syntax." + "For example:" + "::resolved, for accessing the 'resolved' field." + "(:= ::resolved #1) for modifying it." + "(::new! []) for calling the class's constructor." + "(::resolve! container [value]) for calling the 'resolve' method." + )} (do meta.monad [current_module meta.current_module_name .let [fully_qualified_class_name (format (safe current_module) "." full_class_name) @@ -1232,9 +1232,9 @@ (.tuple (<>.some (..super_class_decl^ class_vars))))} {annotations ..annotations^} {members (<>.some (..method_decl^ class_vars))}) - {#.doc (doc "Allows defining JVM interfaces." - (interface: TestInterface - ([] foo [boolean String] void #throws [Exception])))} + {#.doc (example "Allows defining JVM interfaces." + (interface: TestInterface + ([] foo [boolean String] void #throws [Exception])))} (let [def_code (format "jvm interface:" (spaced (list (class_decl$ class_decl) (with_brackets (spaced (list\map super_class_decl$ supers))) @@ -1251,17 +1251,17 @@ (.tuple (<>.some (..super_class_decl^ class_vars))))} {constructor_args (..constructor_args^ class_vars)} {methods (<>.some ..overriden_method_def^)}) - {#.doc (doc "Allows defining anonymous classes." - "The 1st tuple corresponds to class-level type-variables." - "The 2nd tuple corresponds to parent interfaces." - "The 3rd tuple corresponds to arguments to the super class constructor." - "An optional super-class can be specified before the 1st tuple. If not specified, java.lang.Object will be assumed." - (object [] [Runnable] - [] - (Runnable [] (run self) void - (exec (do_something some_value) - []))) - )} + {#.doc (example "Allows defining anonymous classes." + "The 1st tuple corresponds to class-level type-variables." + "The 2nd tuple corresponds to parent interfaces." + "The 3rd tuple corresponds to arguments to the super class constructor." + "An optional super-class can be specified before the 1st tuple. If not specified, java.lang.Object will be assumed." + (object [] [Runnable] + [] + (Runnable [] (run self) void + (exec (do_something some_value) + []))) + )} (let [def_code (format "jvm anon-class:" (spaced (list (super_class_decl$ super) (with_brackets (spaced (list\map super_class_decl$ interfaces))) @@ -1270,39 +1270,39 @@ (in (list (` ((~ (code.text def_code)))))))) (syntax: .public (null) - {#.doc (doc "Null object reference." - (null))} + {#.doc (example "Null object reference." + (null))} (in (list (` ("jvm object null"))))) (def: .public (null? obj) - {#.doc (doc "Test for null object reference." - (= (null? (null)) - true) - (= (null? "YOLO") - false))} + {#.doc (example "Test for null object reference." + (= (null? (null)) + true) + (= (null? "YOLO") + false))} (-> (primitive "java.lang.Object") Bit) ("jvm object null?" obj)) (syntax: .public (??? expr) - {#.doc (doc "Takes a (potentially null) ObjectType reference and creates a (Maybe ObjectType) for it." - (= (??? (: java/lang/String (null))) - #.None) - (= (??? "YOLO") - (#.Some "YOLO")))} - (with_gensyms [g!temp] + {#.doc (example "Takes a (potentially null) ObjectType reference and creates a (Maybe ObjectType) for it." + (= (??? (: java/lang/String (null))) + #.None) + (= (??? "YOLO") + (#.Some "YOLO")))} + (with_identifiers [g!temp] (in (list (` (let [(~ g!temp) (~ expr)] (if ("jvm object null?" (~ g!temp)) #.None (#.Some (~ g!temp))))))))) (syntax: .public (!!! expr) - {#.doc (doc "Takes a (Maybe ObjectType) and returns a ObjectType." - "A #.None would get translated into a (null)." - (= (null) - (!!! (??? (: java/lang/Thread (null))))) - (= "foo" - (!!! (??? "foo"))))} - (with_gensyms [g!value] + {#.doc (example "Takes a (Maybe ObjectType) and returns a ObjectType." + "A #.None would get translated into a (null)." + (= (null) + (!!! (??? (: java/lang/Thread (null))))) + (= "foo" + (!!! (??? "foo"))))} + (with_identifiers [g!value] (in (list (` ({(#.Some (~ g!value)) (~ g!value) @@ -1312,12 +1312,12 @@ (syntax: .public (check {class (..generic_type^ (list))} {unchecked (<>.maybe .any)}) - {#.doc (doc "Checks whether an object is an instance of a particular class." - "Caveat emptor: Cannot check for polymorphism, so avoid using parameterized classes." - (case (check java/lang/String "YOLO") - (#.Some value_as_string) - #.None))} - (with_gensyms [g!_ g!unchecked] + {#.doc (example "Checks whether an object is an instance of a particular class." + "Caveat emptor: Cannot check for polymorphism, so avoid using parameterized classes." + (case (check java/lang/String "YOLO") + (#.Some value_as_string) + #.None))} + (with_identifiers [g!_ g!unchecked] (let [class_name (simple_class$ (list) class) class_type (` (.primitive (~ (code.text class_name)))) check_type (` (.Maybe (~ class_type))) @@ -1338,19 +1338,19 @@ )))) (syntax: .public (synchronized lock body) - {#.doc (doc "Evaluates body, while holding a lock on a given object." - (synchronized object_to_be_locked - (exec (do_something ___) - (do_something_else ___) - (finish_the_computation ___))))} + {#.doc (example "Evaluates body, while holding a lock on a given object." + (synchronized object_to_be_locked + (exec (do_something ___) + (do_something_else ___) + (finish_the_computation ___))))} (in (list (` ("jvm object synchronized" (~ lock) (~ body)))))) (syntax: .public (do_to obj {methods (<>.some partial_call^)}) - {#.doc (doc "Call a variety of methods on an object. Then, return the object." - (do_to object - (ClassName::method1 arg0 arg1 arg2) - (ClassName::method2 arg3 arg4 arg5)))} - (with_gensyms [g!obj] + {#.doc (example "Call a variety of methods on an object. Then, return the object." + (do_to object + (ClassName::method1 arg0 arg1 arg2) + (ClassName::method2 arg3 arg4 arg5)))} + (with_identifiers [g!obj] (in (list (` (let [(~ g!obj) (~ obj)] (exec (~+ (list\map (complete_call$ g!obj) methods)) (~ g!obj)))))))) @@ -1391,7 +1391,7 @@ [arg_inputs (monad.map ! (: (-> [Bit GenericType] (Meta [Bit Code])) (function (_ [maybe? _]) - (with_gensyms [arg_name] + (with_identifiers [arg_name] (in [maybe? arg_name])))) import_member_args) .let [arg_classes (: (List Text) @@ -1420,7 +1420,7 @@ (if (not (..null? (:as (primitive "java.lang.Object") (~ g!temp)))) (~ g!temp) - (error! (~ (code.text (format "Cannot produce null references from method calls @ " + (panic! (~ (code.text (format "Cannot produce null references from method calls @ " (get@ #class_name class) "." (get@ #import_member_alias commons)))))))))) @@ -1533,7 +1533,7 @@ ((~' in) (.list (.` (~ jvm_interop))))))))) (#MethodDecl [commons method]) - (with_gensyms [g!obj] + (with_identifiers [g!obj] (do meta.monad [.let [def_name (code.identifier ["" (..import_name import_format method_prefix (get@ #import_member_alias commons))]) (^slots [#import_member_kind]) commons @@ -1579,7 +1579,7 @@ (list\map lux_type_parameter))) getter_name (code.identifier ["" (..import_name import_format method_prefix import_field_name)]) setter_name (code.identifier ["" (..import_name import_format method_prefix (format import_field_name "!"))])] - getter_interop (with_gensyms [g!obj] + getter_interop (with_identifiers [g!obj] (let [getter_call (if import_field_static? (` ((~ getter_name))) (` ((~ getter_name) (~ g!obj)))) @@ -1600,7 +1600,7 @@ ((~' in) (.list (.` (~ getter_body))))))))) setter_interop (: (Meta (List Code)) (if import_field_setter? - (with_gensyms [g!obj g!value] + (with_identifiers [g!obj g!value] (let [setter_call (if import_field_static? (` ((~ setter_name) (~ g!value))) (` ((~ setter_name) (~ g!value) (~ g!obj)))) @@ -1655,57 +1655,57 @@ (syntax: .public (import: {class_decl ..class_decl^} {bundles (<>.some (..bundle (product.right class_decl)))}) - {#.doc (doc "Allows importing JVM classes, and using them as types." - "Their methods, fields and enum options can also be imported." - (import: java/lang/Object - ["#::." - (new []) - (equals [java/lang/Object] boolean) - (wait [int] #io #try void)]) - - "Special options can also be given for the return values." - "#? means that the values will be returned inside a Maybe type. That way, null becomes #.None." - "#try means that the computation might throw an exception, and the return value will be wrapped by the Try type." - "#io means the computation has side effects, and will be wrapped by the IO type." - "These options must show up in the following order [#io #try #?] (although, each option can be used independently)." - (import: java/lang/String - ["#::." - (new [[byte]]) - (#static valueOf [char] java/lang/String) - (#static valueOf #as int_valueOf [int] java/lang/String)]) - - (import: (java/util/List e) - ["#::." - (size [] int) - (get [int] e)]) - - (import: (java/util/ArrayList a) - ["#::." - ([T] toArray [[T]] [T])]) - - "The class-type that is generated is of the fully-qualified name." - "This avoids a clash between the java.util.List type, and Lux's own List type." - "All enum options to be imported must be specified." - (import: java/lang/Character$UnicodeScript - ["#::." - (#enum ARABIC CYRILLIC LATIN)]) - - "It should also be noted, the only types that may show up in method arguments or return values may be Java classes, arrays, primitives, void or type-parameters." - "Lux types, such as Maybe cannot be named (otherwise, they'd be confused for Java classes)." - (import: (lux/concurrency/async/JvmAsync A) - ["#::." - (resolve [A] boolean) - (poll [] A) - (wasResolved [] boolean) - (waitOn [lux/Function] void) - (#static [A] make [A] (lux/concurrency/async/JvmAsync A))]) - - "Also, the names of the imported members will look like Class::member" - (java/lang/Object::new []) - (java/lang/Object::equals [other_object] my_object) - (java/util/List::size [] my_list) - java/lang/Character$UnicodeScript::LATIN - )} + {#.doc (example "Allows importing JVM classes, and using them as types." + "Their methods, fields and enum options can also be imported." + (import: java/lang/Object + ["#::." + (new []) + (equals [java/lang/Object] boolean) + (wait [int] #io #try void)]) + + "Special options can also be given for the return values." + "#? means that the values will be returned inside a Maybe type. That way, null becomes #.None." + "#try means that the computation might throw an exception, and the return value will be wrapped by the Try type." + "#io means the computation has side effects, and will be wrapped by the IO type." + "These options must show up in the following order [#io #try #?] (although, each option can be used independently)." + (import: java/lang/String + ["#::." + (new [[byte]]) + (#static valueOf [char] java/lang/String) + (#static valueOf #as int_valueOf [int] java/lang/String)]) + + (import: (java/util/List e) + ["#::." + (size [] int) + (get [int] e)]) + + (import: (java/util/ArrayList a) + ["#::." + ([T] toArray [[T]] [T])]) + + "The class-type that is generated is of the fully-qualified name." + "This avoids a clash between the java.util.List type, and Lux's own List type." + "All enum options to be imported must be specified." + (import: java/lang/Character$UnicodeScript + ["#::." + (#enum ARABIC CYRILLIC LATIN)]) + + "It should also be noted, the only types that may show up in method arguments or return values may be Java classes, arrays, primitives, void or type-parameters." + "Lux types, such as Maybe cannot be named (otherwise, they'd be confused for Java classes)." + (import: (lux/concurrency/async/JvmAsync A) + ["#::." + (resolve [A] boolean) + (poll [] A) + (wasResolved [] boolean) + (waitOn [lux/Function] void) + (#static [A] make [A] (lux/concurrency/async/JvmAsync A))]) + + "Also, the names of the imported members will look like Class::member" + (java/lang/Object::new []) + (java/lang/Object::equals [other_object] my_object) + (java/util/List::size [] my_list) + java/lang/Character$UnicodeScript::LATIN + )} (do {! meta.monad} [kind (class_kind class_decl) =members (|> bundles @@ -1717,8 +1717,8 @@ (syntax: .public (array {type (..generic_type^ (list))} size) - {#.doc (doc "Create an array of the given type, with the given size." - (array java/lang/Object 10))} + {#.doc (example "Create an array of the given type, with the given size." + (array java/lang/Object 10))} (case type (^template [ ] [(^ (#GenericClass (list))) @@ -1736,8 +1736,8 @@ (in (list (` ("jvm anewarray" (~ (code.text (generic_type$ type))) (~ size))))))) (syntax: .public (array_length array) - {#.doc (doc "Gives the length of an array." - (array_length my_array))} + {#.doc (example "Gives the length of an array." + (array_length my_array))} (in (list (` ("jvm arraylength" (~ array)))))) (def: (type_class_name type) @@ -1763,8 +1763,8 @@ (meta.failure (format "Cannot convert to JvmType: " (type.format type)))))) (syntax: .public (array_read idx array) - {#.doc (doc "Loads an element from an array." - (array_read 10 my_array))} + {#.doc (example "Loads an element from an array." + (array_read 10 my_array))} (case array [_ (#.Identifier array_name)] (do meta.monad @@ -1787,13 +1787,13 @@ (in (list (` ("jvm aaload" (~ array) (~ idx))))))) _ - (with_gensyms [g!array] + (with_identifiers [g!array] (in (list (` (let [(~ g!array) (~ array)] (..array_read (~ idx) (~ g!array))))))))) (syntax: .public (array_write idx value array) - {#.doc (doc "Stores an element into an array." - (array_write 10 my_object my_array))} + {#.doc (example "Stores an element into an array." + (array_write 10 my_object my_array))} (case array [_ (#.Identifier array_name)] (do meta.monad @@ -1816,13 +1816,13 @@ (in (list (` ("jvm aastore" (~ array) (~ idx) (~ value))))))) _ - (with_gensyms [g!array] + (with_identifiers [g!array] (in (list (` (let [(~ g!array) (~ array)] (..array_write (~ idx) (~ value) (~ g!array))))))))) (syntax: .public (class_for {type (..generic_type^ (list))}) - {#.doc (doc "Loads the class as a java.lang.Class object." - (class_for java/lang/String))} + {#.doc (example "Loads the class as a java.lang.Class object." + (class_for java/lang/String))} (in (list (` ("jvm object class" (~ (code.text (simple_class$ (list) type)))))))) (syntax: .public (type {type (..generic_type^ (list))}) diff --git a/stdlib/source/library/lux/ffi.php.lux b/stdlib/source/library/lux/ffi.php.lux index 1097cacf5..6b4ffc631 100644 --- a/stdlib/source/library/lux/ffi.php.lux +++ b/stdlib/source/library/lux/ffi.php.lux @@ -7,18 +7,18 @@ [monad (#+ do)]] [control ["." io] + ["." maybe] ["<>" parser ("#\." monad) ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ["%" format]] [collection ["." list ("#\." functor fold)]]] [type abstract] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code] ["." template]]]]) @@ -162,7 +162,7 @@ (` (let [(~ g!temp) (~ output)] (if (not ("php object null?" (~ g!temp))) (~ g!temp) - (.error! "Null is an invalid value!")))))) + (.panic! "Null is an invalid value!")))))) (type: Import (#Class Text (Maybe Alias) Text (List Member)) @@ -183,12 +183,12 @@ )) (syntax: .public (try expression) - {#.doc (doc (case (try (risky_computation input)) - (#.Right success) - (do_something success) + {#.doc (example (case (try (risky_computation input)) + (#.Right success) + (do_something success) - (#.Left error) - (recover_from_failure error)))} + (#.Left error) + (recover_from_failure error)))} (in (list (` ("lux try" ((~! io.io) (~ expression))))))) (def: (with_io with? without) @@ -233,10 +233,10 @@ (~+ (list\map (with_null g!temp) g!inputs))))))))))) (syntax: .public (import: {import ..import}) - (with_gensyms [g!temp] + (with_identifiers [g!temp] (case import (#Class [class alias format members]) - (with_gensyms [g!object] + (with_identifiers [g!object] (let [qualify (: (-> Text Code) (function (_ member_name) (|> format diff --git a/stdlib/source/library/lux/ffi.py.lux b/stdlib/source/library/lux/ffi.py.lux index 8878c85a2..93eaf6ccc 100644 --- a/stdlib/source/library/lux/ffi.py.lux +++ b/stdlib/source/library/lux/ffi.py.lux @@ -7,18 +7,18 @@ [monad (#+ do)]] [control ["." io] + ["." maybe] ["<>" parser ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ["%" format]] [collection ["." list ("#\." functor fold)]]] [type abstract] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code] ["." template]]]]) @@ -157,7 +157,7 @@ (` (let [(~ g!temp) (~ output)] (if (not ("python object none?" (~ g!temp))) (~ g!temp) - (.error! "None is an invalid value!")))))) + (.panic! "None is an invalid value!")))))) (type: Import (#Class [Text Text (List Member)]) @@ -213,10 +213,10 @@ (~+ (list\map (with_none g!temp) g!inputs))))))))))) (syntax: .public (import: {import ..import}) - (with_gensyms [g!temp] + (with_identifiers [g!temp] (case import (#Class [class format members]) - (with_gensyms [g!object] + (with_identifiers [g!object] (let [qualify (: (-> Text Code) (function (_ member_name) (|> format diff --git a/stdlib/source/library/lux/ffi.rb.lux b/stdlib/source/library/lux/ffi.rb.lux index 26fea6c27..8bffde0d6 100644 --- a/stdlib/source/library/lux/ffi.rb.lux +++ b/stdlib/source/library/lux/ffi.rb.lux @@ -7,18 +7,18 @@ [monad (#+ do)]] [control ["." io] + ["." maybe] ["<>" parser ("#\." monad) ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ["%" format]] [collection ["." list ("#\." functor fold)]]] [type abstract] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code] ["." template]]]]) @@ -162,7 +162,7 @@ (` (let [(~ g!temp) (~ output)] (if (not ("ruby object nil?" (~ g!temp))) (~ g!temp) - (.error! "Nil is an invalid value!")))))) + (.panic! "Nil is an invalid value!")))))) (type: Import (#Class Text (Maybe Alias) Text (List Member)) @@ -226,10 +226,10 @@ (~+ (list\map (with_nil g!temp) g!inputs))))))))))) (syntax: .public (import: {[?module import] ..import}) - (with_gensyms [g!temp] + (with_identifiers [g!temp] (case import (#Class [class alias format members]) - (with_gensyms [g!object] + (with_identifiers [g!object] (let [qualify (: (-> Text Code) (function (_ member_name) (|> format diff --git a/stdlib/source/library/lux/ffi.scm.lux b/stdlib/source/library/lux/ffi.scm.lux index 85f3f560a..6a1e79cec 100644 --- a/stdlib/source/library/lux/ffi.scm.lux +++ b/stdlib/source/library/lux/ffi.scm.lux @@ -7,18 +7,18 @@ [monad (#+ do)]] [control ["." io] + ["." maybe] ["<>" parser ("#\." monad) ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ["%" format (#+ format)]] [collection ["." list ("#\." functor fold)]]] [type abstract] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code] ["." template]]]]) @@ -136,7 +136,7 @@ (` (let [(~ g!temp) (~ output)] (if (not ("scheme object nil?" (~ g!temp))) (~ g!temp) - (.error! "Nil is an invalid value!")))))) + (.panic! "Nil is an invalid value!")))))) (type: Import (#Function Common_Method) @@ -150,12 +150,12 @@ )) (syntax: .public (try expression) - {#.doc (doc (case (try (risky_computation input)) - (#.Right success) - (do_something success) + {#.doc (example (case (try (risky_computation input)) + (#.Right success) + (do_something success) - (#.Left error) - (recover_from_failure error)))} + (#.Left error) + (recover_from_failure error)))} (in (list (` ("lux try" ((~! io.io) (~ expression))))))) (def: (with_io with? without) @@ -200,7 +200,7 @@ (~+ (list\map (with_nil g!temp) g!inputs))))))))))) (syntax: .public (import: {import ..import}) - (with_gensyms [g!temp] + (with_identifiers [g!temp] (case import (#Function [name alias inputsT io? try? outputT]) (let [imported (` ("scheme constant" (~ (code.text name))))] diff --git a/stdlib/source/library/lux/locale.lux b/stdlib/source/library/lux/locale.lux index 512d214c6..39befd846 100644 --- a/stdlib/source/library/lux/locale.lux +++ b/stdlib/source/library/lux/locale.lux @@ -4,8 +4,9 @@ [abstract [equivalence (#+ Equivalence)] ["." hash (#+ Hash)]] + [control + ["." maybe ("#\." functor)]] [data - ["." maybe ("#\." functor)] ["." text ["%" format (#+ format)] ["." encoding (#+ Encoding)]]] diff --git a/stdlib/source/library/lux/locale/language.lux b/stdlib/source/library/lux/locale/language.lux index 7204c4823..4bff5041e 100644 --- a/stdlib/source/library/lux/locale/language.lux +++ b/stdlib/source/library/lux/locale/language.lux @@ -13,7 +13,7 @@ ... https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes (abstract: .public Language - {#.doc (doc "An ISO 639 language.")} + {#.doc (example "An ISO 639 language.")} {#name Text #code Text} diff --git a/stdlib/source/library/lux/locale/territory.lux b/stdlib/source/library/lux/locale/territory.lux index 279cb1148..48526b897 100644 --- a/stdlib/source/library/lux/locale/territory.lux +++ b/stdlib/source/library/lux/locale/territory.lux @@ -13,7 +13,7 @@ ... https://en.wikipedia.org/wiki/ISO_3166-1 (abstract: .public Territory - {#.doc (doc "An ISO 3166 territory.")} + {#.doc (example "An ISO 3166 territory.")} {#name Text #short Text diff --git a/stdlib/source/library/lux/macro.lux b/stdlib/source/library/lux/macro.lux index 193b5a25e..c05d45cde 100644 --- a/stdlib/source/library/lux/macro.lux +++ b/stdlib/source/library/lux/macro.lux @@ -19,8 +19,8 @@ ["." location]]]) (def: .public (single_expansion syntax) - {#.doc (doc "Given code that requires applying a macro, does it once and returns the result." - "Otherwise, returns the code as-is.")} + {#.doc (example "Given code that requires applying a macro, does it once and returns the result." + "Otherwise, returns the code as-is.")} (-> Code (Meta (List Code))) (case syntax [_ (#.Form (#.Item [[_ (#.Identifier name)] args]))] @@ -37,8 +37,8 @@ (\ //.monad in (list syntax)))) (def: .public (expansion syntax) - {#.doc (doc "Given code that requires applying a macro, expands repeatedly until no more direct macro-calls are left." - "Otherwise, returns the code as-is.")} + {#.doc (example "Given code that requires applying a macro, expands repeatedly until no more direct macro-calls are left." + "Otherwise, returns the code as-is.")} (-> Code (Meta (List Code))) (case syntax [_ (#.Form (#.Item [[_ (#.Identifier name)] args]))] @@ -106,9 +106,9 @@ _ (\ //.monad in (list syntax)))) -(def: .public (gensym prefix) - {#.doc (doc "Generates a unique name as an Code node (ready to be used in code templates)." - "A prefix can be given (or just be empty text) to better identify the code for debugging purposes.")} +(def: .public (identifier prefix) + {#.doc (example "Generates a unique name as an Code node (ready to be used in code templates)." + "A prefix can be given (or just be empty text) to better identify the code for debugging purposes.")} (-> Text (Meta Code)) (do //.monad [id //.seed] @@ -131,29 +131,29 @@ (|>> name\encode (text\compose "Wrong syntax for "))) -(macro: .public (with_gensyms tokens) - {#.doc (doc "Creates new identifiers and offers them to the body expression." - (syntax: .public (synchronized lock body) - (with_gensyms [g!lock g!body g!_] - (in (list (` (let [(~ g!lock) (~ lock) - (~ g!_) ("jvm monitorenter" (~ g!lock)) - (~ g!body) (~ body) - (~ g!_) ("jvm monitorexit" (~ g!lock))] - (~ g!body))))) - )))} +(macro: .public (with_identifiers tokens) + {#.doc (example "Creates new identifiers and offers them to the body expression." + (syntax: .public (synchronized lock body) + (with_identifiers [g!lock g!body g!_] + (in (list (` (let [(~ g!lock) (~ lock) + (~ g!_) ("jvm monitorenter" (~ g!lock)) + (~ g!body) (~ body) + (~ g!_) ("jvm monitorexit" (~ g!lock))] + (~ g!body))))) + )))} (case tokens (^ (list [_ (#.Tuple identifiers)] body)) (do {! //.monad} [identifier_names (monad.map ! ..get_local_identifier identifiers) .let [identifier_defs (list\join (list\map (: (-> Text (List Code)) - (function (_ name) (list (code.identifier ["" name]) (` (gensym (~ (code.text name))))))) + (function (_ name) (list (code.identifier ["" name]) (` (..identifier (~ (code.text name))))))) identifier_names))]] (in (list (` ((~! do) (~! //.monad) [(~+ identifier_defs)] (~ body)))))) _ - (//.failure (..wrong_syntax_error (name_of ..with_gensyms))))) + (//.failure (..wrong_syntax_error (name_of ..with_identifiers))))) (def: .public (one_expansion token) {#.doc "Works just like expand, except that it ensures that the output is a single Code token."} @@ -169,13 +169,13 @@ (template [ ] [(macro: .public ( tokens) - {#.doc (doc "Performs a macro-expansion and logs the resulting code." - "You can either use the resulting code, or omit them." - "By omitting them, this macro produces nothing (just like the lux.comment macro)." - ( #omit - (def: (foo bar baz) - (-> Int Int Int) - (int.+ bar baz))))} + {#.doc (example "Performs a macro-expansion and logs the resulting code." + "You can either use the resulting code, or omit them." + "By omitting them, this macro produces nothing (just like the lux.comment macro)." + ( #omit + (def: (foo bar baz) + (-> Int Int Int) + (int.+ bar baz))))} (let [[module _] (name_of .._) [_ short] (name_of ) macro_name [module short]] diff --git a/stdlib/source/library/lux/macro/local.lux b/stdlib/source/library/lux/macro/local.lux index 8a4360ac7..67434aa09 100644 --- a/stdlib/source/library/lux/macro/local.lux +++ b/stdlib/source/library/lux/macro/local.lux @@ -100,7 +100,7 @@ (do meta.monad [_ (monad.map meta.monad ..push_one macros) seed meta.seed - g!pop (//.gensym "pop") + g!pop (//.identifier "pop") _ (let [g!pop (: Name ["" (//code.format g!pop)])] (..push_one [g!pop (..pop_all (list\map product.left macros) g!pop)]))] (in (` ((~ g!pop)))))) diff --git a/stdlib/source/library/lux/macro/poly.lux b/stdlib/source/library/lux/macro/poly.lux index 535c8236f..7c79dd3d7 100644 --- a/stdlib/source/library/lux/macro/poly.lux +++ b/stdlib/source/library/lux/macro/poly.lux @@ -6,17 +6,17 @@ [abstract ["." monad (#+ do)]] [control + ["." maybe] ["<>" parser ("#\." monad) ["<.>" type (#+ Env)] ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text] [collection ["." list ("#\." fold functor)] ["." dictionary]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) ["." code] [syntax (#+ syntax:)]] [math @@ -32,15 +32,15 @@ (<>.and (<>\in (` .private)) private)))) (syntax: .public (poly: {[export_policy name body] ..polyP}) - (with_gensyms [g!_ g!type g!output] + (with_identifiers [g!_ g!type g!output] (let [g!name (code.identifier ["" name])] (in (.list (` ((~! syntax:) (~ export_policy) ((~ g!name) {(~ g!type) (~! .identifier)}) ((~! do) (~! meta.monad) [(~ g!type) ((~! meta.type_definition) (~ g!type))] (case (: (.Either .Text .Code) - ((~! .run) ((~! <>.rec) - (function ((~ g!_) (~ g!name)) - (~ body))) + ((~! .result) ((~! <>.rec) + (function ((~ g!_) (~ g!name)) + (~ body))) (~ g!type))) (#.Left (~ g!output)) ((~! meta.failure) (~ g!output)) diff --git a/stdlib/source/library/lux/macro/syntax.lux b/stdlib/source/library/lux/macro/syntax.lux index 2689d68f3..0a3e28707 100644 --- a/stdlib/source/library/lux/macro/syntax.lux +++ b/stdlib/source/library/lux/macro/syntax.lux @@ -1,16 +1,16 @@ (.module: [library [lux #* - ["." macro (#+ with_gensyms)] + ["." macro (#+ with_identifiers)] ["." meta] [abstract ["." monad (#+ do)]] [control + ["." maybe] ["." try] ["<>" parser ["" code (#+ Parser)]]] [data - ["." maybe] ["." text ("#\." monoid)] [collection ["." list ("#\." functor)]]] @@ -42,22 +42,22 @@ (#.Item [[x y] pairs']) (list& x y (un_paired pairs')))) (macro: .public (syntax: tokens) - {#.doc (doc "A more advanced way to define macros than 'macro:'." - "The inputs to the macro can be parsed in complex ways through the use of syntax parsers." - "The macro body is also (implicitly) run in the Meta monad, to save some typing." - "Also, the compiler state can be accessed through the *compiler* binding." - (syntax: .public (object {.let [imports (class_imports *compiler*)]} - {.let [class_vars (list)]} - {super (opt (super_class_decl^ imports class_vars))} - {interfaces (tuple (some (super_class_decl^ imports class_vars)))} - {constructor_args (constructor_args^ imports class_vars)} - {methods (some (overriden_method_def^ imports))}) - (let [def_code ($_ text\compose "anon-class:" - (spaced (list (super_class_decl$ (maybe.else object_super_class super)) - (with_brackets (spaced (list\map super_class_decl$ interfaces))) - (with_brackets (spaced (list\map constructor_arg$ constructor_args))) - (with_brackets (spaced (list\map (method_def$ id) methods))))))] - (in (list (` ((~ (code.text def_code)))))))))} + {#.doc (example "A more advanced way to define macros than 'macro:'." + "The inputs to the macro can be parsed in complex ways through the use of syntax parsers." + "The macro body is also (implicitly) run in the Meta monad, to save some typing." + "Also, the compiler state can be accessed through the *lux* binding." + (syntax: .public (object {.let [imports (class_imports *lux*)]} + {.let [class_vars (list)]} + {super (opt (super_class_decl^ imports class_vars))} + {interfaces (tuple (some (super_class_decl^ imports class_vars)))} + {constructor_args (constructor_args^ imports class_vars)} + {methods (some (overriden_method_def^ imports))}) + (let [def_code ($_ text\compose "anon-class:" + (spaced (list (super_class_decl$ (maybe.else object_super_class super)) + (with_brackets (spaced (list\map super_class_decl$ interfaces))) + (with_brackets (spaced (list\map constructor_arg$ constructor_args))) + (with_brackets (spaced (list\map (method_def$ id) methods))))))] + (in (list (` ((~ (code.text def_code)))))))))} (let [?parts (: (Maybe [Code Text (List Code) Code Code]) (case tokens (^ (list export_policy @@ -84,7 +84,7 @@ #.None))] (case ?parts (#.Some [export_policy name args meta body]) - (with_gensyms [g!tokens g!body g!error] + (with_identifiers [g!tokens g!body g!error] (do {! meta.monad} [vars+parsers (monad.map ! (: (-> Code (Meta [Code Code])) @@ -113,7 +113,7 @@ (meta.failure "Syntax pattern expects records or identifiers.")))) args) this_module meta.current_module_name - .let [g!state (code.identifier ["" "*compiler*"]) + .let [g!state (code.identifier ["" "*lux*"]) error_msg (code.text (macro.wrong_syntax_error [this_module name]))]] (in (list (` (macro: (~ export_policy) ((~ (code.identifier ["" name])) (~ g!tokens) (~ g!state)) (~ meta) @@ -122,7 +122,7 @@ (#.Left (~ g!error)) (#.Left ((~! text.join_with) (~! text.new_line) (list (~ error_msg) (~ g!error))))} - ((~! .run) + ((~! .result) (: ((~! .Parser) (Meta (List Code))) ((~! do) (~! <>.monad) [(~+ (..un_paired vars+parsers))] diff --git a/stdlib/source/library/lux/macro/syntax/annotations.lux b/stdlib/source/library/lux/macro/syntax/annotations.lux index 88d43f03d..1db17d9b5 100644 --- a/stdlib/source/library/lux/macro/syntax/annotations.lux +++ b/stdlib/source/library/lux/macro/syntax/annotations.lux @@ -16,7 +16,7 @@ ["." code]]]]) (type: .public Annotations - {#.doc (doc "Definition/module annotations.")} + {#.doc (example "Definition/module annotations.")} (List [Name Code])) (def: .public equivalence diff --git a/stdlib/source/library/lux/macro/syntax/check.lux b/stdlib/source/library/lux/macro/syntax/check.lux index c55f6f233..26450894a 100644 --- a/stdlib/source/library/lux/macro/syntax/check.lux +++ b/stdlib/source/library/lux/macro/syntax/check.lux @@ -18,7 +18,7 @@ "lux check") (type: .public Check - {#.doc (doc "A type annotation for an expression.")} + {#.doc (example "A type annotation for an expression.")} {#type Code #value Code}) diff --git a/stdlib/source/library/lux/macro/syntax/declaration.lux b/stdlib/source/library/lux/macro/syntax/declaration.lux index 158bb618f..c85e74822 100644 --- a/stdlib/source/library/lux/macro/syntax/declaration.lux +++ b/stdlib/source/library/lux/macro/syntax/declaration.lux @@ -15,7 +15,7 @@ ["." code]]]]) (type: .public Declaration - {#.doc (doc "A declaration for either a constant or a function.")} + {#.doc (example "A declaration for either a constant or a function.")} {#name Text #arguments (List Text)}) @@ -27,10 +27,10 @@ )) (def: .public parser - {#.doc (doc "A parser for declaration syntax." - "Such as:" - quux - (foo bar baz))} + {#.doc (example "A parser for declaration syntax." + "Such as:" + quux + (foo bar baz))} (Parser Declaration) (<>.either (<>.and .local_identifier (<>\in (list))) diff --git a/stdlib/source/library/lux/macro/syntax/definition.lux b/stdlib/source/library/lux/macro/syntax/definition.lux index eeefc3074..b0322f507 100644 --- a/stdlib/source/library/lux/macro/syntax/definition.lux +++ b/stdlib/source/library/lux/macro/syntax/definition.lux @@ -26,7 +26,7 @@ ["#." check (#+ Check)]]) (type: .public Definition - {#.doc (doc "Syntax for a constant definition.")} + {#.doc (example "Syntax for a constant definition.")} {#name Text #value (Either Check Code) @@ -107,7 +107,7 @@ [raw .any me_raw (|> raw macro.full_expansion - (meta.run compiler) + (meta.result compiler) <>.lift)] (<| (.local me_raw) .form diff --git a/stdlib/source/library/lux/macro/syntax/export.lux b/stdlib/source/library/lux/macro/syntax/export.lux index 56ee91491..077e36256 100644 --- a/stdlib/source/library/lux/macro/syntax/export.lux +++ b/stdlib/source/library/lux/macro/syntax/export.lux @@ -1,5 +1,5 @@ (.module: - {#.doc (.doc "Syntax for marking a definition as an export.")} + {#.doc (.example "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 d577d68e3..6754185af 100644 --- a/stdlib/source/library/lux/macro/syntax/input.lux +++ b/stdlib/source/library/lux/macro/syntax/input.lux @@ -12,7 +12,7 @@ ["." code]]]]) (type: .public Input - {#.doc (doc "The common typed-argument syntax used by many macros.")} + {#.doc (example "The common typed-argument syntax used by many macros.")} {#binding Code #type Code}) diff --git a/stdlib/source/library/lux/macro/syntax/type/variable.lux b/stdlib/source/library/lux/macro/syntax/type/variable.lux index 09dbdcd62..9f69dfbe0 100644 --- a/stdlib/source/library/lux/macro/syntax/type/variable.lux +++ b/stdlib/source/library/lux/macro/syntax/type/variable.lux @@ -12,7 +12,7 @@ ["." code]]]]) (type: .public Variable - {#.doc (doc "A variable'S name.")} + {#.doc (example "A variable'S name.")} Text) (def: .public equivalence diff --git a/stdlib/source/library/lux/macro/template.lux b/stdlib/source/library/lux/macro/template.lux index c8a211113..e3651d36e 100644 --- a/stdlib/source/library/lux/macro/template.lux +++ b/stdlib/source/library/lux/macro/template.lux @@ -36,7 +36,7 @@ body) (do {! meta.monad} [g!locals (|> locals - (list\map //.gensym) + (list\map //.identifier) (monad.seq !))] (in (list (` (.with_expansions [(~+ (|> (list.zipped/2 locals g!locals) (list\map (function (_ [name identifier]) @@ -177,7 +177,7 @@ (..macro local)]) locals))] (if expression? - (//.with_gensyms [g!body] + (//.with_identifiers [g!body] (in (list (` (.let [(~ g!body) (~ body)] (exec (~ g!pop) (~ g!body))))))) diff --git a/stdlib/source/library/lux/math/infix.lux b/stdlib/source/library/lux/math/infix.lux index 55653989a..a04cf8944 100644 --- a/stdlib/source/library/lux/math/infix.lux +++ b/stdlib/source/library/lux/math/infix.lux @@ -25,28 +25,32 @@ (#Unary Code Infix) (#Binary Infix Code Infix)) -(def: infix^ +(def: literal + (Parser Code) + ($_ <>.either + (<>\map code.bit .bit) + (<>\map code.nat .nat) + (<>\map code.int .int) + (<>\map code.rev .rev) + (<>\map code.frac .frac) + (<>\map code.text .text) + (<>\map code.identifier .identifier) + (<>\map code.tag .tag))) + +(def: expression (Parser Infix) - (<| <>.rec (function (_ infix^)) + (<| <>.rec (function (_ expression)) ($_ <>.or - ($_ <>.either - (<>\map code.bit .bit) - (<>\map code.nat .nat) - (<>\map code.int .int) - (<>\map code.rev .rev) - (<>\map code.frac .frac) - (<>\map code.text .text) - (<>\map code.identifier .identifier) - (<>\map code.tag .tag)) + ..literal (.form (<>.many .any)) - (.tuple (<>.and .any infix^)) + (.tuple (<>.and .any expression)) (.tuple ($_ <>.either (do <>.monad [_ (.this! (' #and)) - init_subject infix^ + init_subject expression init_op .any - init_param infix^ - steps (<>.some (<>.and .any infix^))] + init_param expression + steps (<>.some (<>.and .any expression))] (in (product.right (list\fold (function (_ [op param] [subject [_subject _op _param]]) [param [(#Binary _subject _op _param) (` and) @@ -54,10 +58,10 @@ [init_param [init_subject init_op init_param]] steps)))) (do <>.monad - [init_subject infix^ + [init_subject expression init_op .any - init_param infix^ - steps (<>.some (<>.and .any infix^))] + init_param expression + steps (<>.some (<>.and .any expression))] (in (list\fold (function (_ [op param] [_subject _op _param]) [(#Binary _subject _op _param) op param]) [init_subject init_op init_param] @@ -80,17 +84,17 @@ (#Binary left op right) (` ((~ op) (~ (prefix right)) (~ (prefix left)))))) -(syntax: .public (infix {expr infix^}) - {#.doc (doc "Infix math syntax." - (infix [x i.* +10]) - (infix [[x i.+ y] i.* [x i.- y]]) - (infix [sin [x i.+ y]]) - (infix [[x n.< y] and [y n.< z]]) - (infix [#and x n.< y n.< z]) - (infix [(n.* 3 9) gcd 450]) +(syntax: .public (infix {expr ..expression}) + {#.doc (example "Infix math syntax." + (infix [x i.* +10]) + (infix [[x i.+ y] i.* [x i.- y]]) + (infix [sin [x i.+ y]]) + (infix [[x n.< y] and [y n.< z]]) + (infix [#and x n.< y n.< z]) + (infix [(n.* 3 9) gcd 450]) - "The rules for infix syntax are simple." - "If you want your binary function to work well with it." - "Then take the argument to the right (y) as your first argument," - "and take the argument to the left (x) as your second argument.")} + "The rules for infix syntax are simple." + "If you want your binary function to work well with it." + "Then take the argument to the right (y) as your first argument," + "and take the argument to the left (x) as your second argument.")} (in (list (..prefix expr)))) diff --git a/stdlib/source/library/lux/math/logic/continuous.lux b/stdlib/source/library/lux/math/logic/continuous.lux index 0d36f9968..cffcc4e5d 100644 --- a/stdlib/source/library/lux/math/logic/continuous.lux +++ b/stdlib/source/library/lux/math/logic/continuous.lux @@ -1,8 +1,8 @@ ... 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).")} + {#.doc (.example "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 diff --git a/stdlib/source/library/lux/math/logic/fuzzy.lux b/stdlib/source/library/lux/math/logic/fuzzy.lux index 9e8e1835c..843af83ad 100644 --- a/stdlib/source/library/lux/math/logic/fuzzy.lux +++ b/stdlib/source/library/lux/math/logic/fuzzy.lux @@ -1,6 +1,6 @@ ... https://en.wikipedia.org/wiki/Fuzzy_logic (.module: - {#.doc (.doc "Fuzzy logic, implemented on top of the Rev type.")} + {#.doc "Fuzzy logic, implemented on top of the Rev type."} [library [lux #* [abstract @@ -18,7 +18,7 @@ ["#" continuous]]) (type: .public (Fuzzy a) - {#.doc (doc "A fuzzy set.")} + {#.doc (example "A fuzzy set.")} (-> a Rev)) (implementation: .public functor diff --git a/stdlib/source/library/lux/math/modular.lux b/stdlib/source/library/lux/math/modular.lux index 7bfbf34a0..5588ed574 100644 --- a/stdlib/source/library/lux/math/modular.lux +++ b/stdlib/source/library/lux/math/modular.lux @@ -72,7 +72,7 @@ (i\encode (//.divisor expected))))) (def: decode - (.run + (.result (do <>.monad [[value _ actual] ($_ <>.and intL (.this ..separator) intL) _ (<>.assertion (exception.error ..incorrect_modulus [expected actual]) diff --git a/stdlib/source/library/lux/math/modulus.lux b/stdlib/source/library/lux/math/modulus.lux index 72f5d583e..434535443 100644 --- a/stdlib/source/library/lux/math/modulus.lux +++ b/stdlib/source/library/lux/math/modulus.lux @@ -21,8 +21,8 @@ (exception: .public zero_cannot_be_a_modulus) (abstract: .public (Modulus %) - {#.doc (doc "A number used as a modulus in modular arithmetic." - "It cannot be 0.")} + {#.doc (example "A number used as a modulus in modular arithmetic." + "It cannot be 0.")} Int @@ -50,11 +50,11 @@ ) (syntax: .public (literal {divisor .int}) - {#.doc (doc "Success!" - (literal 123) + {#.doc (example "Success!" + (literal 123) - "Failure!" - (literal 0))} + "Failure!" + (literal 0))} (meta.lift (do try.monad [_ (..modulus divisor)] diff --git a/stdlib/source/library/lux/math/number.lux b/stdlib/source/library/lux/math/number.lux index 0aba205b5..2f2259c18 100644 --- a/stdlib/source/library/lux/math/number.lux +++ b/stdlib/source/library/lux/math/number.lux @@ -22,9 +22,9 @@ " number, generates a Nat, an Int, a Rev or a Frac.") separators "Allows for the presence of commas among the digits." description [location (#.Text ($_ "lux text concat" encoding " " separators))]] - (#try.Success [state (list (` (doc (~ description) - (~ example_1) - (~ example_2))))])) + (#try.Success [state (list (` (.example (~ description) + (~ example_1) + (~ example_2))))])) _ (#try.Failure "Wrong syntax for 'documentation'."))) diff --git a/stdlib/source/library/lux/math/number/complex.lux b/stdlib/source/library/lux/math/number/complex.lux index 63df9b5ae..ba63fec12 100644 --- a/stdlib/source/library/lux/math/number/complex.lux +++ b/stdlib/source/library/lux/math/number/complex.lux @@ -8,10 +8,10 @@ [codec (#+ Codec)] ["M" monad (#+ Monad do)]] [control + ["." maybe] ["<>" parser ["<.>" code (#+ Parser)]]] [data - ["." maybe] [collection ["." list ("#\." functor)]]] [macro @@ -24,15 +24,15 @@ ["." int]]]]]) (type: .public Complex - {#.doc (doc "A complex number.")} + {#.doc (example "A complex number.")} {#real Frac #imaginary Frac}) (syntax: .public (complex real {?imaginary (<>.maybe .any)}) - {#.doc (doc "Complex literals." - (complex real imaginary) - "The imaginary part can be omitted if it's +0.0." - (complex real))} + {#.doc (example "Complex literals." + (complex real imaginary) + "The imaginary part can be omitted if it's +0.0." + (complex real))} (in (list (` {#..real (~ real) #..imaginary (~ (maybe.else (' +0.0) ?imaginary))})))) diff --git a/stdlib/source/library/lux/math/number/frac.lux b/stdlib/source/library/lux/math/number/frac.lux index 977c5a8b7..9dce6d30b 100644 --- a/stdlib/source/library/lux/math/number/frac.lux +++ b/stdlib/source/library/lux/math/number/frac.lux @@ -11,9 +11,9 @@ [order (#+ Order)] [monad (#+ do)]] [control + ["." maybe] ["." try (#+ Try)]] [data - ["." maybe] ["." text]]]] ["." // #_ ["#." i64] diff --git a/stdlib/source/library/lux/math/number/i16.lux b/stdlib/source/library/lux/math/number/i16.lux index 0f273497c..3bbbbe6f4 100644 --- a/stdlib/source/library/lux/math/number/i16.lux +++ b/stdlib/source/library/lux/math/number/i16.lux @@ -3,7 +3,7 @@ [lux (#- i64) [abstract [equivalence (#+ Equivalence)]] - [data + [control ["." maybe]] [type (#+ :by_example)]]] [// @@ -13,7 +13,7 @@ (maybe.assume (i64.sub 16))) (def: .public I16 - {#.doc (doc "A 16-bit integer.")} + {#.doc (example "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 61fe87f40..bd0a705cf 100644 --- a/stdlib/source/library/lux/math/number/i32.lux +++ b/stdlib/source/library/lux/math/number/i32.lux @@ -1,11 +1,11 @@ (.module: [library [lux (#- i64) + [type (#+ :by_example)] [abstract [equivalence (#+ Equivalence)]] - [data - ["." maybe]] - [type (#+ :by_example)]]] + [control + ["." maybe]]]] [// ["." i64 (#+ Sub)]]) @@ -13,7 +13,7 @@ (maybe.assume (i64.sub 32))) (def: .public I32 - {#.doc (doc "A 32-bit integer.")} + {#.doc (example "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 4f44826f9..fd79d7bb3 100644 --- a/stdlib/source/library/lux/math/number/i64.lux +++ b/stdlib/source/library/lux/math/number/i64.lux @@ -37,16 +37,16 @@ ... https://en.wikipedia.org/wiki/Mask_(computing) (type: .public Mask - {#.doc (doc "A pattern of bits that can be imposed on I64 values.")} + {#.doc (example "A pattern of bits that can be imposed on I64 values.")} I64) (def: .public (bit position) - {#.doc (doc "A mask with only a specific bit set.")} + {#.doc (example "A mask with only a specific bit set.")} (-> Nat Mask) (|> 1 .i64 (..left_shifted (n.% ..width position)))) (def: .public sign - {#.doc (doc "A mask for the sign bit of ints.")} + {#.doc (example "A mask for the sign bit of ints.")} Mask (..bit (dec ..width))) @@ -64,7 +64,7 @@ (..not ..false)) (def: .public (mask amount_of_bits) - {#.doc (doc "Mask a block of bits of the specified size.")} + {#.doc (example "Mask a block of bits of the specified size.")} (-> Nat Mask) (case amount_of_bits 0 ..false @@ -72,21 +72,21 @@ 0 ..true bits (|> 1 .i64 (..left_shifted (n.% ..width bits)) .dec)))) -(def: (add_shift shift value) +(def: (with_shift shift value) (-> Nat Nat Nat) (|> value (right_shifted shift) (n.+ value))) -(def: .public (count subject) +(def: .public (ones subject) {#.doc "Count the number of 1s in a bit-map."} (-> (I64 Any) Nat) - (let [count' (n.- (|> subject (right_shifted 1) (..and 6148914691236517205) i64) - (i64 subject))] - (|> count' - (right_shifted 2) (..and 3689348814741910323) (n.+ (..and 3689348814741910323 count')) - (add_shift 4) (..and 1085102592571150095) - (add_shift 8) - (add_shift 16) - (add_shift 32) + (let [ones' (n.- (|> subject (right_shifted 1) (..and 6148914691236517205) i64) + (i64 subject))] + (|> ones' + (right_shifted 2) (..and 3689348814741910323) (n.+ (..and 3689348814741910323 ones')) + (with_shift 4) (..and 1085102592571150095) + (with_shift 8) + (with_shift 16) + (with_shift 32) (..and 127)))) (def: .public (clear index input) @@ -123,7 +123,7 @@ ) (def: .public (region offset size) - {#.doc (doc "A mask for a block of bits of the given size, starting at the given offset.")} + {#.doc (example "A mask for a block of bits of the given size, starting at the given offset.")} (-> Nat Nat Mask) (..left_rotated offset (..mask size))) @@ -189,7 +189,7 @@ swap/01))) (interface: .public (Sub size) - {#.doc (doc "A sub-space of I64 with a reduce amount of bits.")} + {#.doc (example "A sub-space of I64 with a reduce amount of bits.")} (: (Equivalence (I64 size)) &equivalence) @@ -201,7 +201,7 @@ widen)) (def: .public (sub width) - {#.doc (doc "Given a width in the interval (0,64), yields an implementation for integers of that width.")} + {#.doc (example "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 1c3bccea6..ba935b2d8 100644 --- a/stdlib/source/library/lux/math/number/i8.lux +++ b/stdlib/source/library/lux/math/number/i8.lux @@ -3,7 +3,7 @@ [lux (#- i64) [abstract [equivalence (#+ Equivalence)]] - [data + [control ["." maybe]] [type (#+ :by_example)]]] [// @@ -13,7 +13,7 @@ (maybe.assume (i64.sub 8))) (def: .public I8 - {#.doc (doc "An 8-bit integer.")} + {#.doc (example "An 8-bit integer.")} (:by_example [size] (Sub size) ..sub diff --git a/stdlib/source/library/lux/math/number/int.lux b/stdlib/source/library/lux/math/number/int.lux index afe1e7745..88ba6bba1 100644 --- a/stdlib/source/library/lux/math/number/int.lux +++ b/stdlib/source/library/lux/math/number/int.lux @@ -11,10 +11,10 @@ [predicate (#+ Predicate)] ["." order (#+ Order)]] [control + ["." maybe] ["." try (#+ Try)]] [data - [text (#+ Char)] - ["." maybe]]]] + [text (#+ Char)]]]] ["." // #_ ["#." nat] ["#." i64]]) @@ -90,19 +90,19 @@ (..% param subject)]) (def: .public (opposite value) - {#.doc (doc "A value of equal magnitude and opposite sign.")} + {#.doc (example "A value of equal magnitude and opposite sign.")} (-> Int Int) (..- value +0)) (def: .public (abs x) - {#.doc (doc "A value of equal magnitude and positive sign.")} + {#.doc (example "A value of equal magnitude and positive sign.")} (-> Int Int) (if (..< +0 x) (..* -1 x) x)) (def: .public (signum x) - {#.doc (doc "A value (either -1, 0 or +0) which represents the sign.")} + {#.doc (example "A value (either -1, 0 or +0) which represents the sign.")} (-> Int Int) (cond (..= +0 x) +0 (..< +0 x) -1 @@ -111,8 +111,8 @@ ... https://rob.conery.io/2018/08/21/mod-and-remainder-are-not-the-same/ (def: .public (mod divisor dividend) - {#.doc (doc "Integer modulo." - "Note: The modulo and the remainder are not the same.")} + {#.doc (example "Integer modulo." + "Note: The modulo and the remainder are not the same.")} (All [m] (-> Int Int Int)) (let [remainder (..% divisor dividend)] (if (or (and (..< +0 divisor) diff --git a/stdlib/source/library/lux/math/number/nat.lux b/stdlib/source/library/lux/math/number/nat.lux index 63c2302c4..bd6ff389c 100644 --- a/stdlib/source/library/lux/math/number/nat.lux +++ b/stdlib/source/library/lux/math/number/nat.lux @@ -11,9 +11,8 @@ ["." order (#+ Order)]] [control ["." function] - ["." try (#+ Try)]] - [data - ["." maybe]]]]) + ["." maybe] + ["." try (#+ Try)]]]]) (template [ ] [(def: .public ( parameter subject) diff --git a/stdlib/source/library/lux/math/number/ratio.lux b/stdlib/source/library/lux/math/number/ratio.lux index a9a494208..bf0b2eff2 100644 --- a/stdlib/source/library/lux/math/number/ratio.lux +++ b/stdlib/source/library/lux/math/number/ratio.lux @@ -10,12 +10,12 @@ [monad (#+ do)]] [control ["." function] + ["." maybe] ["." try] ["<>" parser ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ("#\." monoid)]] [macro [syntax (#+ syntax:)] @@ -24,7 +24,7 @@ ["n" nat ("#\." decimal)]]) (type: .public Ratio - {#.doc (doc "An unsigned ratio of numbers.")} + {#.doc (example "An unsigned ratio of numbers.")} {#numerator Nat #denominator Nat}) @@ -41,10 +41,10 @@ #denominator (n./ common denominator)})) (syntax: .public (ratio numerator {?denominator (<>.maybe .any)}) - {#.doc (doc "Rational literals." - (ratio numerator denominator) - "The denominator can be omitted if it is 1." - (ratio numerator))} + {#.doc (example "Rational literals." + (ratio numerator denominator) + "The denominator can be omitted if it is 1." + (ratio numerator))} (in (list (` ((~! ..normal) {#..numerator (~ numerator) #..denominator (~ (maybe.else (' 1) ?denominator))}))))) diff --git a/stdlib/source/library/lux/math/number/rev.lux b/stdlib/source/library/lux/math/number/rev.lux index 917f2ad72..20e1d6130 100644 --- a/stdlib/source/library/lux/math/number/rev.lux +++ b/stdlib/source/library/lux/math/number/rev.lux @@ -10,9 +10,9 @@ [codec (#+ Codec)] [order (#+ Order)]] [control + ["." maybe] ["." try]] [data - ["." maybe] [collection ["." array (#+ Array)]]]]] ["." // #_ @@ -142,7 +142,7 @@ {#.doc "Rev(olution) division."} (-> Rev Rev Rev) (if ("lux i64 =" +0 param) - (error! "Cannot divide Rev by zero!") + (panic! "Cannot divide Rev by zero!") (let [reciprocal (case (: Nat ("lux i64 and" param)) 0 (..even_reciprocal (.nat param)) _ (..odd_reciprocal (.nat param)))] diff --git a/stdlib/source/library/lux/math/random.lux b/stdlib/source/library/lux/math/random.lux index a6dbe75d4..2757d62e8 100644 --- a/stdlib/source/library/lux/math/random.lux +++ b/stdlib/source/library/lux/math/random.lux @@ -142,7 +142,7 @@ (\ ..monad map (|>> .i64 f.of_bits) ..nat)) (def: .public safe_frac - {#.doc (doc "A number in the interval [0.0,1.0].")} + {#.doc (example "A number in the interval [0.0,1.0].")} (Random Frac) (let [mantissa_range (.int (i64.left_shifted 53 1)) mantissa_max (i.frac (dec mantissa_range))] @@ -343,7 +343,7 @@ (..either (\in #day.Friday) (\in #day.Saturday)))))) -(def: .public (run prng calc) +(def: .public (result prng calc) (All [a] (-> PRNG (Random a) [PRNG a])) (calc prng)) @@ -355,8 +355,8 @@ (return state)]))) (def: .public (pcg_32 [increase seed]) - {#.doc (doc "An implementation of the PCG32 algorithm." - "For more information, please see: http://www.pcg-random.org/")} + {#.doc (example "An implementation of the PCG32 algorithm." + "For more information, please see: http://www.pcg-random.org/")} (-> [(I64 Any) (I64 Any)] PRNG) (let [magic 6364136223846793005] (function (_ _) @@ -370,8 +370,8 @@ .i64))]))) (def: .public (xoroshiro_128+ [s0 s1]) - {#.doc (doc "An implementation of the Xoroshiro128+ algorithm." - "For more information, please see: http://xoroshiro.di.unimi.it/")} + {#.doc (example "An implementation of the Xoroshiro128+ algorithm." + "For more information, please see: http://xoroshiro.di.unimi.it/")} (-> [(I64 Any) (I64 Any)] PRNG) (function (_ _) [(let [s01 (i64.xor s0 s1)] @@ -385,7 +385,7 @@ ... https://en.wikipedia.org/wiki/Xorshift#Initialization ... http://xorshift.di.unimi.it/splitmix64.c (def: .public split_mix_64 - {#.doc (doc "An implementation of the SplitMix64 algorithm.")} + {#.doc (example "An implementation of the SplitMix64 algorithm.")} (-> Nat PRNG) (let [twist (: (-> Nat Nat Nat) (function (_ shift value) diff --git a/stdlib/source/library/lux/meta.lux b/stdlib/source/library/lux/meta.lux index f966b9d9f..6c2d013c9 100644 --- a/stdlib/source/library/lux/meta.lux +++ b/stdlib/source/library/lux/meta.lux @@ -7,10 +7,10 @@ [apply (#+ Apply)] ["." monad (#+ Monad do)]] [control + ["." maybe] ["." try (#+ Try)]] [data ["." product] - ["." maybe] ["." text ("#\." monoid equivalence)] ["." name ("#\." codec equivalence)] [collection @@ -78,11 +78,11 @@ (#try.Success [compiler' ma]) (ma compiler'))))) -(def: .public (run' compiler action) +(def: .public (result' compiler action) (All [a] (-> Lux (Meta a) (Try [Lux a]))) (action compiler)) -(def: .public (run compiler action) +(def: .public (result compiler action) (All [a] (-> Lux (Meta a) (Try a))) (case (action compiler) (#try.Failure error) @@ -154,8 +154,8 @@ false))) (def: .public (normal name) - {#.doc (doc "If given a name without a module prefix, gives it the current module's name as prefix." - "Otherwise, returns the name as-is.")} + {#.doc (example "If given a name without a module prefix, gives it the current module's name as prefix." + "Otherwise, returns the name as-is.")} (-> Name (Meta Name)) (case name ["" name] diff --git a/stdlib/source/library/lux/meta/annotation.lux b/stdlib/source/library/lux/meta/annotation.lux index 5180187e6..42d151df3 100644 --- a/stdlib/source/library/lux/meta/annotation.lux +++ b/stdlib/source/library/lux/meta/annotation.lux @@ -1,11 +1,12 @@ (.module: - {#.doc (.doc "Machinary for querying annotations on modules and definitions.")} + {#.doc (.example "Machinary for querying annotations on modules and definitions.")} [library [lux (#- nat int rev) [abstract ["." monad (#+ do)]] + [control + ["." maybe]] [data - ["." maybe] ["." name ("#\." equivalence)]]]]) (type: .public Annotation diff --git a/stdlib/source/library/lux/meta/location.lux b/stdlib/source/library/lux/meta/location.lux index 7e21951ce..0c089da36 100644 --- a/stdlib/source/library/lux/meta/location.lux +++ b/stdlib/source/library/lux/meta/location.lux @@ -19,8 +19,8 @@ #.column 0}) (macro: .public (here tokens compiler) - {#.doc (doc "The Location of the current form." - (here))} + {#.doc (example "The Location of the current form." + (here))} (case tokens #.End (let [location (get@ #.location compiler)] diff --git a/stdlib/source/library/lux/program.lux b/stdlib/source/library/lux/program.lux index d2caa1a85..20939ab03 100644 --- a/stdlib/source/library/lux/program.lux +++ b/stdlib/source/library/lux/program.lux @@ -15,7 +15,7 @@ ["." text] [collection ["." list ("#\." monad)]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code]]]]) @@ -34,23 +34,23 @@ (syntax: .public (program: {args ..arguments^} body) - {#.doc (doc "Defines the entry-point to a program (similar to the 'main' function/method in other programming languages)." - "Can take a list of all the input parameters to the program." - "Or, can destructure them using CLI-option combinators from the lux/control/parser/cli module." - (program: all_args - (do io.monad - [foo init_program - bar (do_something all_args)] - (in []))) + {#.doc (example "Defines the entry-point to a program (similar to the 'main' function/method in other programming languages)." + "Can take a list of all the input parameters to the program." + "Or, can destructure them using CLI-option combinators from the lux/control/parser/cli module." + (program: all_args + (do io.monad + [foo init_program + bar (do_something all_args)] + (in []))) - (program: [name] - (io (log! (\ text.monoid compose "Hello, " name)))) + (program: [name] + (io (log! (\ text.monoid compose "Hello, " name)))) - (program: [{config configuration_parser}] - (do io.monad - [data (init_program config)] - (do_something data))))} - (with_gensyms [g!program g!args g!_ g!output g!message] + (program: [{config configuration_parser}] + (do io.monad + [data (init_program config)] + (do_something data))))} + (with_identifiers [g!program g!args g!_ g!output g!message] (let [initialization+event_loop (` ((~! do) (~! io.monad) [(~ g!output) (~ body) @@ -68,17 +68,17 @@ (#Parsed args) (` (.function ((~ g!program) (~ g!args)) - (case ((~! .run) (: (~! (.Parser (io.IO .Any))) - ((~! do) (~! <>.monad) - [(~+ (|> args - (list\map (function (_ [binding parser]) - (list binding parser))) - list\join)) - (~ g!_) (~! .end)] - ((~' in) (~ initialization+event_loop)))) + (case ((~! .result) (: (~! (.Parser (io.IO .Any))) + ((~! do) (~! <>.monad) + [(~+ (|> args + (list\map (function (_ [binding parser]) + (list binding parser))) + list\join)) + (~ g!_) (~! .end)] + ((~' in) (~ initialization+event_loop)))) (~ g!args)) (#.Right (~ g!output)) (~ g!output) (#.Left (~ g!message)) - (.error! (~ g!message)))))))))))))) + (.panic! (~ g!message)))))))))))))) diff --git a/stdlib/source/library/lux/target/jvm/bytecode.lux b/stdlib/source/library/lux/target/jvm/bytecode.lux index 2891e83fa..13363a06f 100644 --- a/stdlib/source/library/lux/target/jvm/bytecode.lux +++ b/stdlib/source/library/lux/target/jvm/bytecode.lux @@ -9,11 +9,11 @@ ["." writer (#+ Writer)] ["." state (#+ +State)] ["." function] + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)]] [data ["." product] - ["." maybe] [text ["%" format (#+ format)]] [collection @@ -876,10 +876,10 @@ (def: .public (lookupswitch default cases) (-> Label (List [S4 Label]) (Bytecode Any)) - (let [cases (list.sort (function (_ [left _] [right _]) - (i.< (//signed.value left) - (//signed.value right))) - cases) + (let [cases (list.sorted (function (_ [left _] [right _]) + (i.< (//signed.value left) + (//signed.value right))) + cases) [estimator bytecode] _.lookupswitch] (function (_ [pool environment tracker]) (do try.monad diff --git a/stdlib/source/library/lux/target/jvm/bytecode/environment/limit/stack.lux b/stdlib/source/library/lux/target/jvm/bytecode/environment/limit/stack.lux index a825e6699..5499207cf 100644 --- a/stdlib/source/library/lux/target/jvm/bytecode/environment/limit/stack.lux +++ b/stdlib/source/library/lux/target/jvm/bytecode/environment/limit/stack.lux @@ -4,9 +4,9 @@ [abstract ["." equivalence (#+ Equivalence)]] [control + ["." maybe] ["." try (#+ Try)]] [data - ["." maybe] [text ["%" format (#+ Format)]] [format diff --git a/stdlib/source/library/lux/target/jvm/bytecode/instruction.lux b/stdlib/source/library/lux/target/jvm/bytecode/instruction.lux index 7d76f4c78..22777c083 100644 --- a/stdlib/source/library/lux/target/jvm/bytecode/instruction.lux +++ b/stdlib/source/library/lux/target/jvm/bytecode/instruction.lux @@ -52,7 +52,7 @@ Instruction function.identity) -(def: .public run +(def: .public result (-> Instruction Specification) (function.apply format.no_op)) diff --git a/stdlib/source/library/lux/target/jvm/class.lux b/stdlib/source/library/lux/target/jvm/class.lux index 17561fa0d..b4cb88ec4 100644 --- a/stdlib/source/library/lux/target/jvm/class.lux +++ b/stdlib/source/library/lux/target/jvm/class.lux @@ -92,7 +92,7 @@ (Try Class)) (do try.monad [[pool [@this @super @interfaces] =fields =methods] - (<| (state.run' //constant/pool.empty) + (<| (state.result' //constant/pool.empty) (do //constant/pool.monad [classes (install_classes this super interfaces) =fields (monad.seq //constant/pool.monad fields) diff --git a/stdlib/source/library/lux/target/jvm/loader.lux b/stdlib/source/library/lux/target/jvm/loader.lux index 5676f1f4a..892d1e1ee 100644 --- a/stdlib/source/library/lux/target/jvm/loader.lux +++ b/stdlib/source/library/lux/target/jvm/loader.lux @@ -113,7 +113,7 @@ (java/lang/Class [? < java/lang/Object]) #throws [java/lang/ClassNotFoundException] (let [class_name (:as Text class_name) - classes (|> library atom.read! io.run)] + classes (|> library atom.read! io.run!)] (case (dictionary.get class_name classes) (#.Some bytecode) (case (..define class_name bytecode (<| self)) @@ -121,10 +121,10 @@ (:assume class) (#try.Failure error) - (error! (exception.error ..cannot_define [class_name error]))) + (panic! (exception.error ..cannot_define [class_name error]))) #.None - (error! (exception.error ..unknown [class_name]))))))))) + (panic! (exception.error ..unknown [class_name]))))))))) (def: .public (store name bytecode library) (-> Text Binary Library (IO (Try Any))) diff --git a/stdlib/source/library/lux/target/jvm/method.lux b/stdlib/source/library/lux/target/jvm/method.lux index 54aee2e60..8c42130d1 100644 --- a/stdlib/source/library/lux/target/jvm/method.lux +++ b/stdlib/source/library/lux/target/jvm/method.lux @@ -68,7 +68,7 @@ (#try.Failure error) (function (_ _) (#try.Failure error))) [environment exceptions instruction output] (//bytecode.resolve environment code) - .let [bytecode (|> instruction //bytecode/instruction.run format.instance)] + .let [bytecode (|> instruction //bytecode/instruction.result format.instance)] @code (//attribute.code {#//attribute/code.limit (get@ #//bytecode/environment.limit environment) #//attribute/code.code bytecode #//attribute/code.exception_table exceptions diff --git a/stdlib/source/library/lux/target/jvm/modifier.lux b/stdlib/source/library/lux/target/jvm/modifier.lux index 92aeafec2..8689834c4 100644 --- a/stdlib/source/library/lux/target/jvm/modifier.lux +++ b/stdlib/source/library/lux/target/jvm/modifier.lux @@ -11,7 +11,7 @@ [data [format [".F" binary (#+ Writer)]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)] ["." code]] [math @@ -81,7 +81,7 @@ ) (syntax: .public (modifiers: ofT {options (<>.many .any)}) - (with_gensyms [g!modifier g!code] + (with_identifiers [g!modifier g!code] (in (list (` (template [(~ g!code) (~ g!modifier)] [(def: (~' .public) (~ g!modifier) (..Modifier (~ ofT)) diff --git a/stdlib/source/library/lux/target/jvm/reflection.lux b/stdlib/source/library/lux/target/jvm/reflection.lux index 256fc2863..eb219a297 100644 --- a/stdlib/source/library/lux/target/jvm/reflection.lux +++ b/stdlib/source/library/lux/target/jvm/reflection.lux @@ -243,7 +243,7 @@ [/reflection.double /.double] [/reflection.char /.char])) (if (text.starts_with? /descriptor.array_prefix class_name) - (.run /parser.value (|> class_name //name.internal //name.read)) + (.result /parser.value (|> class_name //name.internal //name.read)) (#try.Success (/.class class_name (list))))))) _) (case (ffi.check java/lang/reflect/GenericArrayType reflection) diff --git a/stdlib/source/library/lux/target/jvm/type.lux b/stdlib/source/library/lux/target/jvm/type.lux index c4a5abd0b..e6beb53d2 100644 --- a/stdlib/source/library/lux/target/jvm/type.lux +++ b/stdlib/source/library/lux/target/jvm/type.lux @@ -4,8 +4,9 @@ [abstract [equivalence (#+ Equivalence)] [hash (#+ Hash)]] + [control + ["." maybe]] [data - ["." maybe] ["." text ["%" format (#+ Format)]] [collection diff --git a/stdlib/source/library/lux/target/jvm/type/alias.lux b/stdlib/source/library/lux/target/jvm/type/alias.lux index 05ecd1f29..9c01faea3 100644 --- a/stdlib/source/library/lux/target/jvm/type/alias.lux +++ b/stdlib/source/library/lux/target/jvm/type/alias.lux @@ -4,12 +4,12 @@ [abstract ["." monad (#+ do)]] [control + ["." maybe] ["." try] ["." exception (#+ exception:)] ["<>" parser ["<.>" text (#+ Parser)]]] [data - ["." maybe] ["." text ["%" format (#+ format)]] [collection @@ -119,13 +119,13 @@ (-> Aliasing (-> (Type Method) (Type Method))) (|>> //.signature //signature.signature - (.run (do <>.monad - [type_variables (|> (<>.some (..bound_type_var aliasing)) - (<>.after (.this //signature.parameters_start)) - (<>.before (.this //signature.parameters_end)) - (<>.else (list))) - inputs (..inputs aliasing) - return (..return aliasing) - exceptions (<>.some (..exception aliasing))] - (in (//.method [type_variables inputs return exceptions])))) + (.result (do <>.monad + [type_variables (|> (<>.some (..bound_type_var aliasing)) + (<>.after (.this //signature.parameters_start)) + (<>.before (.this //signature.parameters_end)) + (<>.else (list))) + inputs (..inputs aliasing) + return (..return aliasing) + exceptions (<>.some (..exception aliasing))] + (in (//.method [type_variables inputs return exceptions])))) try.assumed)) diff --git a/stdlib/source/library/lux/target/jvm/type/descriptor.lux b/stdlib/source/library/lux/target/jvm/type/descriptor.lux index df751407b..60e8eead3 100644 --- a/stdlib/source/library/lux/target/jvm/type/descriptor.lux +++ b/stdlib/source/library/lux/target/jvm/type/descriptor.lux @@ -3,8 +3,9 @@ [lux (#- int char) [abstract [equivalence (#+ Equivalence)]] + [control + ["." maybe]] [data - ["." maybe] ["." text ("#\." equivalence) ["%" format (#+ format)]] [collection diff --git a/stdlib/source/library/lux/target/jvm/type/lux.lux b/stdlib/source/library/lux/target/jvm/type/lux.lux index dc10d216a..c6721ab41 100644 --- a/stdlib/source/library/lux/target/jvm/type/lux.lux +++ b/stdlib/source/library/lux/target/jvm/type/lux.lux @@ -228,7 +228,7 @@ (def: .public (check operation input) (All [a] (-> (Parser (Check a)) Text (Check a))) - (case (.run operation input) + (case (.result operation input) (#try.Success check) check diff --git a/stdlib/source/library/lux/target/jvm/type/parser.lux b/stdlib/source/library/lux/target/jvm/type/parser.lux index f54b961cc..6712f7ee0 100644 --- a/stdlib/source/library/lux/target/jvm/type/parser.lux +++ b/stdlib/source/library/lux/target/jvm/type/parser.lux @@ -90,14 +90,14 @@ (-> (Type Value) (Maybe Text)) (|>> //.signature //signature.signature - (.run ..var') + (.result ..var') try.maybe)) (def: .public name (-> (Type Var) Text) (|>> //.signature //signature.signature - (.run ..var') + (.result ..var') try.assumed)) (template [ ] @@ -125,7 +125,7 @@ (def: class' (-> (Parser (Type Parameter)) (Parser (Type Class))) (|>> ..class'' - (\ <>.monad map (product.uncurry //.class)))) + (\ <>.monad map (product.uncurried //.class)))) (def: .public parameter (Parser (Type Parameter)) @@ -154,7 +154,7 @@ (-> (Type Value) (Maybe (Type Class))) (|>> //.signature //signature.signature - (.run (<>.after (.this ) ..class)) + (.result (<>.after (.this ) ..class)) try.maybe))] [lower? //signature.lower_prefix //.lower] @@ -165,7 +165,7 @@ (-> (Type Class) [External (List (Type Parameter))]) (|>> //.signature //signature.signature - (.run (..class'' ..parameter)) + (.result (..class'' ..parameter)) try.assumed)) (def: .public value @@ -223,7 +223,7 @@ (<>.some ..exception)))] (|>> //.signature //signature.signature - (.run parser) + (.result parser) try.assumed))) (template [ ] @@ -231,7 +231,7 @@ (-> (Type Value) (Maybe )) (|>> //.signature //signature.signature - (.run ) + (.result ) try.maybe))] [array? (Type Value) @@ -261,5 +261,5 @@ (-> (Type Declaration) [External (List (Type Var))]) (|>> //.signature //signature.signature - (.run ..declaration') + (.result ..declaration') try.assumed)) diff --git a/stdlib/source/library/lux/target/r.lux b/stdlib/source/library/lux/target/r.lux index e446c0cb1..d0a5f7b58 100644 --- a/stdlib/source/library/lux/target/r.lux +++ b/stdlib/source/library/lux/target/r.lux @@ -4,10 +4,10 @@ [control [pipe (#+ case> cond> new>)] ["." function] + ["." maybe ("#\." functor)] [parser ["<.>" code]]] [data - ["." maybe ("#\." functor)] ["." text ["%" format (#+ format)]] [collection diff --git a/stdlib/source/library/lux/test.lux b/stdlib/source/library/lux/test.lux index a2ff484ab..310243fc4 100644 --- a/stdlib/source/library/lux/test.lux +++ b/stdlib/source/library/lux/test.lux @@ -8,6 +8,7 @@ ["." monad (#+ do)]] [control [pipe (#+ case>)] + ["." maybe] ["." try] ["." exception (#+ exception:)] ["." io] @@ -17,7 +18,6 @@ ["<>" parser ["<.>" code]]] [data - ["." maybe] ["." product] ["." name] ["." text @@ -93,7 +93,7 @@ (write! [(..total l_tally r_tally) (format l_documentation ..separator r_documentation)])) right))) - io.run)] + io.run!)] read!)) (def: .public (and left right) @@ -153,8 +153,8 @@ (def: .public (seed value test) (-> Seed Test Test) (function (_ prng) - (let [[_ result] (random.run (random.pcg_32 [..pcg_32_magic_inc value]) - test)] + (let [[_ result] (random.result (random.pcg_32 [..pcg_32_magic_inc value]) + test)] [prng result]))) (def: failed? @@ -175,7 +175,7 @@ _ (do random.monad [seed random.nat] (function (recur prng) - (let [[prng' instance] (random.run (random.pcg_32 [..pcg_32_magic_inc seed]) test)] + (let [[prng' instance] (random.result (random.pcg_32 [..pcg_32_magic_inc seed]) test)] [prng' (do {! async.monad} [[tally documentation] instance] (if (..failed? tally) @@ -184,7 +184,7 @@ 1 instance _ (|> test (times (dec amount)) - (random.run prng') + (random.result prng') product.right))))]))))) (def: (description duration tally) @@ -197,7 +197,7 @@ (get@ #actual_coverage tally)) report (: (-> (Set Name) Text) (|>> set.list - (list.sort (\ name.order <)) + (list.sorted (\ name.order <)) (exception.listing %.name))) expected_definitions_to_cover (set.size (get@ #expected_coverage tally)) unexpected_definitions_covered (set.size unexpected) @@ -246,7 +246,7 @@ [pre (async.future instant.now) .let [seed (instant.millis pre) prng (random.pcg_32 [..pcg_32_magic_inc seed])] - [tally documentation] (|> test (random.run prng) product.right) + [tally documentation] (|> test (random.result prng) product.right) post (async.future instant.now) .let [duration (instant.span pre post) _ (debug.log! (format documentation text.new_line text.new_line @@ -382,7 +382,7 @@ [seed random.nat .let [prng (random.pcg_32 [..pcg_32_magic_inc seed]) run! (: (-> Test Assertion) - (|>> (random.run prng) + (|>> (random.result prng) product.right (function (_ _)) "lux try" @@ -399,22 +399,22 @@ [read! write!] (: [Assertion (async.Resolver [Tally Text])] (async.async [])) - _ (io.run (monad.map io.monad - (function (_ [index test]) - (async.upon! (function (_ assertion) - (do io.monad - [[_ results] (atom.update! (dictionary.put index assertion) state)] - (if (n.= expected_tests (dictionary.size results)) - (let [assertions (|> results - dictionary.entries - (list\map product.right))] - (write! [(|> assertions - (list\map product.left) - (list\fold ..total ..start)) - (|> assertions - (list\map product.right) - (text.join_with ..separator))])) - (in [])))) - (run! test))) - (list.enumeration tests)))]] + _ (io.run! (monad.map io.monad + (function (_ [index test]) + (async.upon! (function (_ assertion) + (do io.monad + [[_ results] (atom.update! (dictionary.put index assertion) state)] + (if (n.= expected_tests (dictionary.size results)) + (let [assertions (|> results + dictionary.entries + (list\map product.right))] + (write! [(|> assertions + (list\map product.left) + (list\fold ..total ..start)) + (|> assertions + (list\map product.right) + (text.join_with ..separator))])) + (in [])))) + (run! test))) + (list.enumeration tests)))]] (in read!)))) diff --git a/stdlib/source/library/lux/time.lux b/stdlib/source/library/lux/time.lux index fe40eece2..dbe7ff1fa 100644 --- a/stdlib/source/library/lux/time.lux +++ b/stdlib/source/library/lux/time.lux @@ -209,9 +209,9 @@ (..millis_format milli_second)))) (implementation: .public codec - {#.doc (doc "Based on ISO 8601." - "For example: 21:14:51.827")} + {#.doc (example "Based on ISO 8601." + "For example: 21:14:51.827")} (Codec Text Time) (def: encode ..format) - (def: decode (.run ..parser))) + (def: decode (.result ..parser))) diff --git a/stdlib/source/library/lux/time/date.lux b/stdlib/source/library/lux/time/date.lux index 9318e7be0..402700a81 100644 --- a/stdlib/source/library/lux/time/date.lux +++ b/stdlib/source/library/lux/time/date.lux @@ -8,12 +8,12 @@ [codec (#+ Codec)] [monad (#+ do)]] [control + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)] ["<>" parser ["<.>" text (#+ Parser)]]] [data - ["." maybe] ["." text ("#\." monoid)] [collection ["." list ("#\." fold)] @@ -68,14 +68,14 @@ "-") (abstract: .public Date - {#.doc (doc "A date specified as a year/month/day triplet.")} + {#.doc (example "A date specified as a year/month/day triplet.")} {#year Year #month Month #day Nat} (def: .public (date year month day_of_month) - {#.doc (doc "A date, within the allowed limits.")} + {#.doc (example "A date, within the allowed limits.")} (-> Year Month Nat (Try Date)) (if (..day_is_within_limits? year month day_of_month) (#try.Success @@ -190,12 +190,12 @@ ..separator (..padded (..day_of_month value)))) (implementation: .public codec - {#.doc (doc "Based on ISO 8601." - "For example: 2017-01-15")} + {#.doc (example "Based on ISO 8601." + "For example: 2017-01-15")} (Codec Text Date) (def: encode ..format) - (def: decode (.run ..parser))) + (def: decode (.result ..parser))) (def: days_per_leap (|> //year.days diff --git a/stdlib/source/library/lux/time/day.lux b/stdlib/source/library/lux/time/day.lux index 384802851..b44ace3a8 100644 --- a/stdlib/source/library/lux/time/day.lux +++ b/stdlib/source/library/lux/time/day.lux @@ -19,7 +19,7 @@ ["n" nat]]]]]) (type: .public Day - {#.doc (doc "A day of the week.")} + {#.doc (example "A day of the week.")} #Sunday #Monday #Tuesday @@ -123,7 +123,7 @@ _ (exception.except ..not_a_day_of_the_week [value])))) (def: .public week - {#.doc (doc "All the days, ordered by when they come in a week.")} + {#.doc (example "All the days, ordered by when they come in a week.")} (List Day) (list #Sunday #Monday diff --git a/stdlib/source/library/lux/time/duration.lux b/stdlib/source/library/lux/time/duration.lux index 6de3b80a7..995d0c678 100644 --- a/stdlib/source/library/lux/time/duration.lux +++ b/stdlib/source/library/lux/time/duration.lux @@ -187,7 +187,7 @@ (Codec Text Duration) (def: encode ..encode) - (def: decode (.run ..parser))) + (def: decode (.result ..parser))) (def: .public (difference from to) (-> Duration Duration Duration) diff --git a/stdlib/source/library/lux/time/instant.lux b/stdlib/source/library/lux/time/instant.lux index 630388641..cc19a4ecc 100644 --- a/stdlib/source/library/lux/time/instant.lux +++ b/stdlib/source/library/lux/time/instant.lux @@ -10,12 +10,12 @@ [monad (#+ Monad do)]] [control [io (#+ IO io)] + ["." maybe] ["." try] ["." exception (#+ exception:)] ["<>" parser ["<.>" text (#+ Parser)]]] [data - ["." maybe] ["." text ("#\." monoid)] [collection ["." row]]] @@ -148,15 +148,15 @@ ..absolute)))) (implementation: .public codec - {#.doc (doc "Based on ISO 8601." - "For example: 2017-01-15T21:14:51.827Z")} + {#.doc (example "Based on ISO 8601." + "For example: 2017-01-15T21:14:51.827Z")} (Codec Text Instant) (def: encode ..format) - (def: decode (.run ..parser))) + (def: decode (.result ..parser))) (def: .public now - {#.doc (doc "Yields the current instant, as measured from the operating-system's clock.")} + {#.doc (example "Yields the current instant, as measured from the operating-system's clock.")} (IO Instant) (io (..of_millis (for {@.old ("jvm invokestatic:java.lang.System:currentTimeMillis:") @.jvm (|> ("jvm member invoke static" [] "java.lang.System" "currentTimeMillis" []) diff --git a/stdlib/source/library/lux/time/month.lux b/stdlib/source/library/lux/time/month.lux index 6e626f325..d8203e175 100644 --- a/stdlib/source/library/lux/time/month.lux +++ b/stdlib/source/library/lux/time/month.lux @@ -19,7 +19,7 @@ ["n" nat]]]]]) (type: .public Month - {#.doc (doc "A month of the year.")} + {#.doc (example "A month of the year.")} #January #February #March @@ -159,7 +159,7 @@ #January #December))) (def: .public (days month) - {#.doc (doc "The amount of days of a month.")} + {#.doc (example "The amount of days of a month.")} (-> Month Nat) (case month (^template [ ] @@ -181,14 +181,14 @@ [31 #December]))) (def: .public (leap_year_days month) - {#.doc (doc "The amount of days of a month (in a leap year).")} + {#.doc (example "The amount of days of a month (in a leap year).")} (-> Month Nat) (case month #February (inc (..days month)) _ (..days month))) (def: .public year - {#.doc (doc "All the months, ordered by when they come in a year.")} + {#.doc (example "All the months, ordered by when they come in a year.")} (List Month) (list #January #February diff --git a/stdlib/source/library/lux/time/year.lux b/stdlib/source/library/lux/time/year.lux index 44534707c..e7ed644ce 100644 --- a/stdlib/source/library/lux/time/year.lux +++ b/stdlib/source/library/lux/time/year.lux @@ -36,14 +36,14 @@ ... https://en.wikipedia.org/wiki/Gregorian_calendar (abstract: .public Year - {#.doc (doc "A year in the gregorian calendar." - "Both negative (< 0) and positive (> 0) values are valid, but not 0." - "This is because the first year of the gregorian calendar was year 1.")} + {#.doc (example "A year in the gregorian calendar." + "Both negative (< 0) and positive (> 0) values are valid, but not 0." + "This is because the first year of the gregorian calendar was year 1.")} Int (def: .public (year value) - {#.doc (doc "A valid year in the gregorian calendar, if possible.")} + {#.doc (example "A valid year in the gregorian calendar, if possible.")} (-> Int (Try Year)) (case value +0 (exception.except ..there_is_no_year_0 []) @@ -59,12 +59,12 @@ ) (def: .public days - {#.doc (doc "The amount of days in a typical year.")} + {#.doc (example "The amount of days in a typical year.")} Nat 365) (type: .public Period - {#.doc (doc "An amount of years.")} + {#.doc (example "An amount of years.")} Nat) (template [ ] @@ -96,7 +96,7 @@ days))) (def: .public (leaps year) - {#.doc (doc "The number of leap years in a period of years.")} + {#.doc (example "The number of leap years in a period of years.")} (-> Year Int) (let [year (|> year ..value ..internal) limit (if (i.> +0 year) @@ -130,12 +130,12 @@ (#.Right _) raw_year))))) (implementation: .public codec - {#.doc (doc "Based on ISO 8601." - "For example: 2017")} + {#.doc (example "Based on ISO 8601." + "For example: 2017")} (Codec Text Year) (def: encode ..encode) - (def: decode (.run ..parser))) + (def: decode (.result ..parser))) (implementation: .public equivalence (Equivalence Year) diff --git a/stdlib/source/library/lux/tool/compiler/default/init.lux b/stdlib/source/library/lux/tool/compiler/default/init.lux index 6127ea59a..6af02e080 100644 --- a/stdlib/source/library/lux/tool/compiler/default/init.lux +++ b/stdlib/source/library/lux/tool/compiler/default/init.lux @@ -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.result' state (..iteration' archive expander reader source pre_payload)) (#try.Success [state source&requirements&buffer]) (#try.Success [state (#.Some source&requirements&buffer)]) @@ -239,17 +239,17 @@ #///.process (function (_ state archive) (do {! try.monad} [.let [hash (text\hash (get@ #///.code input))] - [state [source buffer]] (<| (///phase.run' state) + [state [source buffer]] (<| (///phase.result' state) (..begin dependencies hash input)) .let [module (get@ #///.module input)]] - (loop [iteration (<| (///phase.run' state) + (loop [iteration (<| (///phase.result' state) (..iteration archive expander module source buffer ///syntax.no_aliases))] (do ! [[state ?source&requirements&temporary_payload] iteration] (case ?source&requirements&temporary_payload #.None (do ! - [[state [analysis_module [final_buffer final_registry]]] (///phase.run' state (..end module)) + [[state [analysis_module [final_buffer final_registry]]] (///phase.result' state (..end module)) .let [descriptor {#descriptor.hash hash #descriptor.name module #descriptor.file (get@ #///.file input) @@ -270,7 +270,7 @@ (get@ #///directive.imports) (list\map product.left)) #///.process (function (_ state archive) - (recur (<| (///phase.run' state) + (recur (<| (///phase.result' state) (do {! ///phase.monad} [analysis_module (<| (: (Operation .Module)) ///directive.lift_analysis diff --git a/stdlib/source/library/lux/tool/compiler/default/platform.lux b/stdlib/source/library/lux/tool/compiler/default/platform.lux index 814e6dfd2..e5ed96552 100644 --- a/stdlib/source/library/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/library/lux/tool/compiler/default/platform.lux @@ -8,6 +8,7 @@ ["." monad (#+ Monad do)]] [control ["." function] + ["." maybe] ["." try (#+ Try) ("#\." monad)] ["." exception (#+ exception:)] [concurrency @@ -17,7 +18,6 @@ ["." binary (#+ Binary)] ["." bit] ["." product] - ["." maybe] ["." text ("#\." equivalence) ["%" format (#+ format)]] [collection @@ -105,7 +105,7 @@ [_ (ioW.prepare system static module_id) _ (for {@.python (|> output row.list - (list.chunk 128) + (list.sub 128) (monad.map ! (monad.map ! write_artifact!)) (: (Action (List (List Any)))))} (|> output @@ -115,7 +115,7 @@ document (\ async.monad in (document.check $.key document))] (ioW.cache system static module_id - (_.run ..writer [descriptor document]))))) + (_.result ..writer [descriptor document]))))) ... TODO: Inline ASAP (def: initialize_buffer! @@ -192,7 +192,7 @@ (extension.with extender (:assume generators))) _ (extension.with extender (:assume directives))] (in []))) - (///phase.run' state) + (///phase.result' state) (\ try.monad map product.left))) (def: (phase_wrapper archive platform state) @@ -202,7 +202,7 @@ (|> archive phase_wrapper ///directive.lift_generation - (///phase.run' state)))) + (///phase.result' state)))) (def: (complete_extensions host_directive_bundle phase_wrapper [analysers synthesizers generators directives]) (All [] @@ -263,7 +263,7 @@ (in [state archive])) (do ! [[state [archive payload]] (|> (..process_runtime archive platform) - (///phase.run' state) + (///phase.result' state) async\in) _ (..cache_module static platform 0 payload) @@ -519,7 +519,7 @@ (All [] (-> Module )) (|> (///directive.set_current_module module) - (///phase.run' state) + (///phase.result' state) try.assumed product.left)) @@ -593,7 +593,7 @@ ... 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) + (///phase.result' state) try.assumed product.left) archive) 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 c79f514c3..eb325ddd0 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux @@ -7,11 +7,11 @@ [monad (#+ do)]] [control ["." function] + ["." maybe] ["." try] ["." exception (#+ Exception)]] [data ["." product] - ["." maybe] ["." bit ("#\." equivalence)] ["." text ("#\." equivalence) ["%" format (#+ Format format)]] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux index 74cadee55..5ae124d96 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux @@ -49,9 +49,9 @@ module (extensionP.lift meta.current_module_name)] (phase.lift (do try.monad - [exprS (|> exprA (synthesisP.phase archive) (phase.run synthesis_state))] - (phase.run generation_state - (do phase.monad - [exprO (generate archive exprS) - module_id (generation.module_id module archive)] - (generation.evaluate! (..context [module_id count]) exprO))))))))) + [exprS (|> exprA (synthesisP.phase archive) (phase.result synthesis_state))] + (phase.result generation_state + (do phase.monad + [exprO (generate archive exprS) + module_id (generation.module_id module archive)] + (generation.evaluate! (..context [module_id count]) exprO))))))))) 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 315424e3c..0a1841ad1 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/generation.lux @@ -173,7 +173,7 @@ _ (extension.update (update@ #counter inc))] (in count))) -(def: .public (gensym prefix) +(def: .public (identifier prefix) (All [anchor expression directive] (-> Text (Operation anchor expression directive Text))) (\ phase.monad map (|>> %.nat (format prefix)) ..next)) 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 11c4ba626..454704918 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 @@ -5,11 +5,11 @@ [abstract ["." monad (#+ do)]] [control + ["." maybe] ["." try] ["." exception (#+ exception:)]] [data ["." product] - ["." maybe] [text ["%" format (#+ format)]] [collection 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 7dd813c09..5a47352b4 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 @@ -5,11 +5,11 @@ equivalence ["." monad (#+ do)]] [control + ["." maybe] ["." try (#+ Try) ("#\." monad)] ["." exception (#+ exception:)]] [data ["." bit ("#\." equivalence)] - ["." maybe] ["." text ["%" format (#+ Format format)]] [collection 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 265311550..8063f450d 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 @@ -4,9 +4,9 @@ [abstract monad] [control + ["." maybe] ["ex" exception (#+ exception:)]] [data - ["." maybe] ["." text ["%" format (#+ format)]] [collection 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 a07afe1fa..1a8d43477 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 @@ -4,9 +4,9 @@ [abstract [monad (#+ do)]] [control + ["." maybe] ["." exception (#+ exception:)]] [data - ["." maybe] ["." text ["%" format (#+ format)]] [collection diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/scope.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/scope.lux index 097f47cce..351c396e0 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/scope.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/scope.lux @@ -4,11 +4,11 @@ [abstract monad] [control + ["." maybe ("#\." monad)] ["." try] ["." exception (#+ exception:)]] [data ["." text ("#\." equivalence)] - ["." maybe ("#\." monad)] ["." product] [collection ["." list ("#\." functor fold monoid)] @@ -118,8 +118,8 @@ (|>> (update@ #.counter inc) (update@ #.mappings (plist.put name [type new_var_id])))) head)] - (case (///.run' [bundle (set@ #.scopes (#.Item new_head tail) state)] - action) + (case (///.result' [bundle (set@ #.scopes (#.Item new_head tail) state)] + action) (#try.Success [[bundle' state'] output]) (case (get@ #.scopes state') (#.Item head' tail') 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 6ff5f7ce4..f5f5d89c8 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 @@ -5,12 +5,12 @@ [abstract ["." monad (#+ do)]] [control + ["." maybe] ["ex" exception (#+ exception:)] ["." state]] [data ["." name] ["." product] - ["." maybe] [text ["%" format (#+ format)]] [collection 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 0620b8c01..3142451e4 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 @@ -80,7 +80,7 @@ ["Extension" (%.text name)] ["Available" (|> bundle dictionary.keys - (list.sort text\<) + (list.sorted text\<) (exception.listing %.text))])) (type: .public (Extender 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 d74b18019..27ce292a0 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 @@ -7,13 +7,13 @@ ["." monad (#+ do)]] [control pipe + ["." maybe] ["." try (#+ Try) ("#\." monad)] ["." exception (#+ exception:)] ["<>" parser ["<.>" code (#+ Parser)] ["<.>" text]]] [data - ["." maybe] ["." product] ["." text ("#\." equivalence) ["%" format (#+ format)]] @@ -400,7 +400,7 @@ [objectJ (jvm_type objectT)] (|> objectJ ..signature - (.run jvm_parser.array) + (.result jvm_parser.array) phase.lift))) (def: (primitive_array_length_handler primitive_type) @@ -845,7 +845,7 @@ (template [ ] [(def: .public ( mapping typeJ) (-> Mapping (Type ) (Operation .Type)) - (case (|> typeJ ..signature (.run ( mapping))) + (case (|> typeJ ..signature (.result ( mapping))) (#try.Success check) (typeA.with_env check) 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 5a76b1804..979af197a 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 @@ -4,12 +4,12 @@ [abstract ["." monad (#+ do)]] [control + ["." maybe] ["." try] ["." exception (#+ exception:)] ["<>" parser ["<.>" code (#+ Parser)]]] [data - ["." maybe] ["." text ["%" format (#+ format)]] [collection @@ -40,7 +40,7 @@ (-> Text Phase Archive s (Operation Analysis))] Handler)) (function (_ extension_name analyse archive args) - (case (.run syntax args) + (case (.result syntax args) (#try.Success inputs) (handler extension_name analyse archive inputs) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux index 5c130e466..6e3ca3a70 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux @@ -12,7 +12,6 @@ ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ["%" format (#+ format)]] [collection @@ -54,7 +53,7 @@ (Operation anchor expression directive Requirements))] (Handler anchor expression directive))) (function (_ extension_name phase archive inputs) - (case (.run syntax inputs) + (case (.result syntax inputs) (#try.Success inputs) (handler extension_name phase archive inputs) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/common.lux index bfe808472..e8518812e 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/common.lux @@ -44,7 +44,7 @@ (-> Text (Generator s))] Handler)) (function (_ extension_name phase archive input) - (case (.run parser input) + (case (.result parser input) (#try.Success input') (handler extension_name phase archive input') @@ -64,7 +64,7 @@ ... .any)))) ... (function (_ extension_name phase archive [input else conditionals]) ... (do {! /////.monad} -... [@input (\ ! map _.var (generation.gensym "input")) +... [@input (\ ! map _.var (generation.identifier "input")) ... inputG (phase archive input) ... elseG (phase archive else) ... conditionalsG (: (Operation (List [Expression Expression])) @@ -101,7 +101,7 @@ (/.install "or" (binary _.logior/2)) (/.install "xor" (binary _.logxor/2)) (/.install "left-shift" (binary _.ash/2)) - (/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shifted))) + (/.install "right-shift" (binary (product.uncurried //runtime.i64//right_shifted))) (/.install "=" (binary _.=/2)) (/.install "<" (binary _. /.empty - ... (/.install "=" (binary (product.uncurry _.=/2))) - ... (/.install "<" (binary (product.uncurry _. /.empty (/.install "=" (binary _.string=/2)) - ... (/.install "<" (binary (product.uncurry _.string Text (Generator s))] Handler)) (function (_ extension_name phase archive input) - (case (.run parser input) + (case (.result parser input) (#try.Success input') (handler extension_name phase archive input') @@ -122,25 +122,25 @@ Bundle (|> /.empty (/.install "syntax char case!" lux::syntax_char_case!) - (/.install "is" (binary (product.uncurry _.=))) + (/.install "is" (binary (product.uncurried _.=))) (/.install "try" (unary //runtime.lux//try)))) (def: i64_procs Bundle (<| (/.prefix "i64") (|> /.empty - (/.install "and" (binary (product.uncurry //runtime.i64//and))) - (/.install "or" (binary (product.uncurry //runtime.i64//or))) - (/.install "xor" (binary (product.uncurry //runtime.i64//xor))) + (/.install "and" (binary (product.uncurried //runtime.i64//and))) + (/.install "or" (binary (product.uncurried //runtime.i64//or))) + (/.install "xor" (binary (product.uncurried //runtime.i64//xor))) (/.install "left-shift" (binary i64//left_shifted)) (/.install "right-shift" (binary i64//right_shifted)) - (/.install "=" (binary (product.uncurry //runtime.i64//=))) - (/.install "<" (binary (product.uncurry //runtime.i64//<))) - (/.install "+" (binary (product.uncurry //runtime.i64//+))) - (/.install "-" (binary (product.uncurry //runtime.i64//-))) - (/.install "*" (binary (product.uncurry //runtime.i64//*))) - (/.install "/" (binary (product.uncurry //runtime.i64///))) - (/.install "%" (binary (product.uncurry //runtime.i64//%))) + (/.install "=" (binary (product.uncurried //runtime.i64//=))) + (/.install "<" (binary (product.uncurried //runtime.i64//<))) + (/.install "+" (binary (product.uncurried //runtime.i64//+))) + (/.install "-" (binary (product.uncurried //runtime.i64//-))) + (/.install "*" (binary (product.uncurried //runtime.i64//*))) + (/.install "/" (binary (product.uncurried //runtime.i64///))) + (/.install "%" (binary (product.uncurried //runtime.i64//%))) (/.install "f64" (unary //runtime.i64//number)) (/.install "char" (unary i64//char)) ))) @@ -149,13 +149,13 @@ Bundle (<| (/.prefix "f64") (|> /.empty - (/.install "+" (binary (product.uncurry _.+))) - (/.install "-" (binary (product.uncurry _.-))) - (/.install "*" (binary (product.uncurry _.*))) - (/.install "/" (binary (product.uncurry _./))) - (/.install "%" (binary (product.uncurry _.%))) - (/.install "=" (binary (product.uncurry _.=))) - (/.install "<" (binary (product.uncurry _.<))) + (/.install "+" (binary (product.uncurried _.+))) + (/.install "-" (binary (product.uncurried _.-))) + (/.install "*" (binary (product.uncurried _.*))) + (/.install "/" (binary (product.uncurried _./))) + (/.install "%" (binary (product.uncurried _.%))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "<" (binary (product.uncurried _.<))) (/.install "i64" (unary //runtime.i64//of_number)) (/.install "encode" (unary (_.do "toString" (list)))) (/.install "decode" (unary f64//decode))))) @@ -164,12 +164,12 @@ Bundle (<| (/.prefix "text") (|> /.empty - (/.install "=" (binary (product.uncurry _.=))) - (/.install "<" (binary (product.uncurry _.<))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "<" (binary (product.uncurried _.<))) (/.install "concat" (binary text//concat)) (/.install "index" (trinary text//index)) (/.install "size" (unary (|>> (_.the "length") //runtime.i64//of_number))) - (/.install "char" (binary (product.uncurry //runtime.text//char))) + (/.install "char" (binary (product.uncurried //runtime.text//char))) (/.install "clip" (trinary text//clip)) ))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux index b2c84251e..9e681c65d 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux @@ -133,7 +133,7 @@ (do {! ////////phase.monad} [abstractionG (phase archive abstractionS) .let [variable (: (-> Text (Operation Var)) - (|>> generation.gensym + (|>> generation.identifier (\ ! map _.var)))] g!inputs (monad.map ! (function (_ _) (variable "input")) (list.repeated (.nat arity) [])) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux index 4bd10e9ec..770e1cce0 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux @@ -48,7 +48,7 @@ (-> Text Phase Archive s (Operation (Bytecode Any)))] Handler)) (function (_ extension_name phase archive input) - (case (.run parser input) + (case (.result parser input) (#try.Success input') (handler extension_name phase archive input') 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 953a4b88a..b3b4be343 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 @@ -4,6 +4,7 @@ [abstract ["." monad (#+ do)]] [control + ["." maybe] ["." try] ["." exception (#+ exception:)] ["<>" parser @@ -11,7 +12,6 @@ ["" synthesis (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ("#\." equivalence) ["%" format (#+ format)]] [number @@ -1070,7 +1070,7 @@ bodyG (returnG returnT))))))) normalized_methods) - bytecode (<| (\ ! map (format.run class.writer)) + bytecode (<| (\ ! map (format.result class.writer)) //////.lift (class.class version.v6_0 ($_ modifier\compose class.public class.final) (name.internal anonymous_class_name) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux index 1ef715e28..db25d1d70 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux @@ -41,7 +41,7 @@ (-> Text (Generator s))] Handler)) (function (_ extension_name phase archive input) - (case (.run parser input) + (case (.result parser input) (#try.Success input') (handler extension_name phase archive input') @@ -63,7 +63,7 @@ (do {! /////.monad} [inputG (phase archive input) elseG (phase archive else) - @input (\ ! map _.var (generation.gensym "input")) + @input (\ ! map _.var (generation.identifier "input")) conditionalsG (: (Operation (List [Expression Expression])) (monad.map ! (function (_ [chars branch]) (do ! @@ -88,25 +88,25 @@ Bundle (|> /.empty (/.install "syntax char case!" lux::syntax_char_case!) - (/.install "is" (binary (product.uncurry _.=))) + (/.install "is" (binary (product.uncurried _.=))) (/.install "try" (unary //runtime.lux//try)))) (def: i64_procs Bundle (<| (/.prefix "i64") (|> /.empty - (/.install "and" (binary (product.uncurry _.bit_and))) - (/.install "or" (binary (product.uncurry _.bit_or))) - (/.install "xor" (binary (product.uncurry _.bit_xor))) - (/.install "left-shift" (binary (product.uncurry //runtime.i64//left_shift))) - (/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shift))) - (/.install "=" (binary (product.uncurry _.=))) - (/.install "+" (binary (product.uncurry _.+))) - (/.install "-" (binary (product.uncurry _.-))) - (/.install "<" (binary (product.uncurry _.<))) - (/.install "*" (binary (product.uncurry _.*))) - (/.install "/" (binary (product.uncurry //runtime.i64//division))) - (/.install "%" (binary (product.uncurry //runtime.i64//remainder))) + (/.install "and" (binary (product.uncurried _.bit_and))) + (/.install "or" (binary (product.uncurried _.bit_or))) + (/.install "xor" (binary (product.uncurried _.bit_xor))) + (/.install "left-shift" (binary (product.uncurried //runtime.i64//left_shift))) + (/.install "right-shift" (binary (product.uncurried //runtime.i64//right_shift))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "+" (binary (product.uncurried _.+))) + (/.install "-" (binary (product.uncurried _.-))) + (/.install "<" (binary (product.uncurried _.<))) + (/.install "*" (binary (product.uncurried _.*))) + (/.install "/" (binary (product.uncurried //runtime.i64//division))) + (/.install "%" (binary (product.uncurried //runtime.i64//remainder))) (/.install "f64" (unary (_./ (_.float +1.0)))) (/.install "char" (unary (_.apply/1 (_.var "utf8.char")))) ))) @@ -119,13 +119,13 @@ Bundle (<| (/.prefix "f64") (|> /.empty - (/.install "+" (binary (product.uncurry _.+))) - (/.install "-" (binary (product.uncurry _.-))) - (/.install "*" (binary (product.uncurry _.*))) - (/.install "/" (binary (product.uncurry _./))) - (/.install "%" (binary (product.uncurry (function.flip (_.apply/2 (_.var "math.fmod")))))) - (/.install "=" (binary (product.uncurry _.=))) - (/.install "<" (binary (product.uncurry _.<))) + (/.install "+" (binary (product.uncurried _.+))) + (/.install "-" (binary (product.uncurried _.-))) + (/.install "*" (binary (product.uncurried _.*))) + (/.install "/" (binary (product.uncurried _./))) + (/.install "%" (binary (product.uncurried (function.flip (_.apply/2 (_.var "math.fmod")))))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "<" (binary (product.uncurried _.<))) (/.install "i64" (unary (!unary "math.floor"))) (/.install "encode" (unary (_.apply/2 (_.var "string.format") (_.string "%.17g")))) (/.install "decode" (unary ..f64//decode))))) @@ -146,9 +146,9 @@ Bundle (<| (/.prefix "text") (|> /.empty - (/.install "=" (binary (product.uncurry _.=))) - (/.install "<" (binary (product.uncurry _.<))) - (/.install "concat" (binary (product.uncurry (function.flip _.concat)))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "<" (binary (product.uncurried _.<))) + (/.install "concat" (binary (product.uncurried (function.flip _.concat)))) (/.install "index" (trinary ..text//index)) (/.install "size" (unary //runtime.text//size)) ... TODO: Use version below once the Lua compiler becomes self-hosted. 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 e3363fe01..f3525e411 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 @@ -171,7 +171,7 @@ (do {! ////////phase.monad} [abstractionG (phase archive abstractionS) .let [variable (: (-> Text (Operation Var)) - (|>> generation.gensym + (|>> generation.identifier (\ ! map _.var)))] g!inputs (monad.map ! (function (_ _) (variable "input")) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux index b061d4cc1..957407cc8 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux @@ -44,7 +44,7 @@ (-> Text (Generator s))] Handler)) (function (_ extension_name phase archive input) - (case (.run parser input) + (case (.result parser input) (#try.Success input') (handler extension_name phase archive input') @@ -67,7 +67,7 @@ [inputG (phase archive input) [[context_module context_artifact] elseG] (generation.with_new_context archive (phase archive else)) - @input (\ ! map _.var (generation.gensym "input")) + @input (\ ! map _.var (generation.identifier "input")) conditionalsG (: (Operation (List [Expression Expression])) (monad.map ! (function (_ [chars branch]) (do ! @@ -101,7 +101,7 @@ Bundle (|> /.empty (/.install "syntax char case!" lux::syntax_char_case!) - (/.install "is" (binary (product.uncurry _.===))) + (/.install "is" (binary (product.uncurried _.===))) (/.install "try" (unary //runtime.lux//try)) )) @@ -113,19 +113,19 @@ Bundle (<| (/.prefix "i64") (|> /.empty - (/.install "and" (binary (product.uncurry _.bit_and))) - (/.install "or" (binary (product.uncurry _.bit_or))) - (/.install "xor" (binary (product.uncurry _.bit_xor))) + (/.install "and" (binary (product.uncurried _.bit_and))) + (/.install "or" (binary (product.uncurried _.bit_or))) + (/.install "xor" (binary (product.uncurried _.bit_xor))) (/.install "left-shift" (binary ..left_shifted)) - (/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shifted))) - (/.install "=" (binary (product.uncurry _.==))) - (/.install "<" (binary (product.uncurry _.<))) - (/.install "+" (binary (product.uncurry //runtime.i64//+))) - (/.install "-" (binary (product.uncurry //runtime.i64//-))) - (/.install "*" (binary (product.uncurry //runtime.i64//*))) + (/.install "right-shift" (binary (product.uncurried //runtime.i64//right_shifted))) + (/.install "=" (binary (product.uncurried _.==))) + (/.install "<" (binary (product.uncurried _.<))) + (/.install "+" (binary (product.uncurried //runtime.i64//+))) + (/.install "-" (binary (product.uncurried //runtime.i64//-))) + (/.install "*" (binary (product.uncurried //runtime.i64//*))) (/.install "/" (binary (function (_ [parameter subject]) (_.intdiv/2 [subject parameter])))) - (/.install "%" (binary (product.uncurry _.%))) + (/.install "%" (binary (product.uncurried _.%))) (/.install "f64" (unary (_./ (_.float +1.0)))) (/.install "char" (unary //runtime.i64//char)) ))) @@ -142,12 +142,12 @@ Bundle (<| (/.prefix "f64") (|> /.empty - (/.install "=" (binary (product.uncurry _.==))) - (/.install "<" (binary (product.uncurry _.<))) - (/.install "+" (binary (product.uncurry _.+))) - (/.install "-" (binary (product.uncurry _.-))) - (/.install "*" (binary (product.uncurry _.*))) - (/.install "/" (binary (product.uncurry _./))) + (/.install "=" (binary (product.uncurried _.==))) + (/.install "<" (binary (product.uncurried _.<))) + (/.install "+" (binary (product.uncurried _.+))) + (/.install "-" (binary (product.uncurried _.-))) + (/.install "*" (binary (product.uncurried _.*))) + (/.install "/" (binary (product.uncurried _./))) (/.install "%" (binary ..f64//%)) (/.install "i64" (unary _.intval/1)) (/.install "encode" (unary ..f64//encode)) @@ -165,12 +165,12 @@ Bundle (<| (/.prefix "text") (|> /.empty - (/.install "=" (binary (product.uncurry _.==))) - (/.install "<" (binary (product.uncurry _.<))) - (/.install "concat" (binary (product.uncurry (function.flip _.concat)))) + (/.install "=" (binary (product.uncurried _.==))) + (/.install "<" (binary (product.uncurried _.<))) + (/.install "concat" (binary (product.uncurried (function.flip _.concat)))) (/.install "index" (trinary ..text//index)) (/.install "size" (unary //runtime.text//size)) - (/.install "char" (binary (product.uncurry //runtime.text//char))) + (/.install "char" (binary (product.uncurried //runtime.text//char))) (/.install "clip" (trinary ..text//clip)) ))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux index 7d32ad88a..5b9eba41e 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux @@ -41,7 +41,7 @@ (-> Text (Generator s))] Handler)) (function (_ extension_name phase archive input) - (case (.run parser input) + (case (.result parser input) (#try.Success input') (handler extension_name phase archive input') @@ -60,7 +60,7 @@ (do {! /////.monad} [inputG (phase archive input) elseG (phase archive else) - @input (\ ! map _.var (generation.gensym "input")) + @input (\ ! map _.var (generation.identifier "input")) conditionalsG (: (Operation (List [(Expression Any) (Expression Any)])) (monad.map ! (function (_ [chars branch]) @@ -86,7 +86,7 @@ Bundle (|> /.empty (/.install "syntax char case!" lux::syntax_char_case!) - (/.install "is" (binary (product.uncurry _.is))) + (/.install "is" (binary (product.uncurried _.is))) (/.install "try" (unary //runtime.lux::try)))) (def: (capped operation parameter subject) @@ -98,19 +98,19 @@ Bundle (<| (/.prefix "i64") (|> /.empty - (/.install "and" (binary (product.uncurry //runtime.i64::and))) - (/.install "or" (binary (product.uncurry //runtime.i64::or))) - (/.install "xor" (binary (product.uncurry //runtime.i64::xor))) - (/.install "left-shift" (binary (product.uncurry //runtime.i64::left_shift))) - (/.install "right-shift" (binary (product.uncurry //runtime.i64::right_shift))) + (/.install "and" (binary (product.uncurried //runtime.i64::and))) + (/.install "or" (binary (product.uncurried //runtime.i64::or))) + (/.install "xor" (binary (product.uncurried //runtime.i64::xor))) + (/.install "left-shift" (binary (product.uncurried //runtime.i64::left_shift))) + (/.install "right-shift" (binary (product.uncurried //runtime.i64::right_shift))) - (/.install "<" (binary (product.uncurry _.<))) - (/.install "=" (binary (product.uncurry _.=))) - (/.install "+" (binary (product.uncurry (..capped _.+)))) - (/.install "-" (binary (product.uncurry (..capped _.-)))) - (/.install "*" (binary (product.uncurry (..capped _.*)))) - (/.install "/" (binary (product.uncurry //runtime.i64::division))) - (/.install "%" (binary (product.uncurry //runtime.i64::remainder))) + (/.install "<" (binary (product.uncurried _.<))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "+" (binary (product.uncurried (..capped _.+)))) + (/.install "-" (binary (product.uncurried (..capped _.-)))) + (/.install "*" (binary (product.uncurried (..capped _.*)))) + (/.install "/" (binary (product.uncurried //runtime.i64::division))) + (/.install "%" (binary (product.uncurried //runtime.i64::remainder))) (/.install "f64" (unary _.float/1)) (/.install "char" (unary //runtime.i64::char)) ))) @@ -119,15 +119,15 @@ Bundle (<| (/.prefix "f64") (|> /.empty - (/.install "+" (binary (product.uncurry _.+))) - (/.install "-" (binary (product.uncurry _.-))) - (/.install "*" (binary (product.uncurry _.*))) - (/.install "/" (binary (product.uncurry //runtime.f64::/))) + (/.install "+" (binary (product.uncurried _.+))) + (/.install "-" (binary (product.uncurried _.-))) + (/.install "*" (binary (product.uncurried _.*))) + (/.install "/" (binary (product.uncurried //runtime.f64::/))) (/.install "%" (binary (function (_ [parameter subject]) (|> (_.__import__/1 (_.unicode "math")) (_.do "fmod" (list subject parameter)))))) - (/.install "=" (binary (product.uncurry _.=))) - (/.install "<" (binary (product.uncurry _.<))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "<" (binary (product.uncurried _.<))) (/.install "i64" (unary _.int/1)) (/.install "encode" (unary _.repr/1)) (/.install "decode" (unary //runtime.f64::decode))))) @@ -144,12 +144,12 @@ Bundle (<| (/.prefix "text") (|> /.empty - (/.install "=" (binary (product.uncurry _.=))) - (/.install "<" (binary (product.uncurry _.<))) - (/.install "concat" (binary (product.uncurry (function.flip _.+)))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "<" (binary (product.uncurried _.<))) + (/.install "concat" (binary (product.uncurried (function.flip _.+)))) (/.install "index" (trinary ..text::index)) (/.install "size" (unary _.len/1)) - (/.install "char" (binary (product.uncurry //runtime.text::char))) + (/.install "char" (binary (product.uncurried //runtime.text::char))) (/.install "clip" (trinary ..text::clip)) ))) 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 81d1373d6..8db4b2ffd 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 @@ -131,7 +131,7 @@ (do {! ////////phase.monad} [abstractionG (phase archive abstractionS) .let [variable (: (-> Text (Operation SVar)) - (|>> generation.gensym + (|>> generation.identifier (\ ! map _.var)))] g!inputs (monad.map ! (function (_ _) (variable "input")) (list.repeated (.nat arity) []))] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux index f14017891..25e244035 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux @@ -44,7 +44,7 @@ (-> Text (Generator s))] Handler)) (function (_ extension_name phase archive input) - (case (.run parser input) + (case (.result parser input) (#try.Success input') (handler extension_name phase archive input') @@ -64,7 +64,7 @@ ... ... .any)))) ... ... (function (_ extension_name phase archive [input else conditionals]) ... ... (do {! /////.monad} -... ... [@input (\ ! map _.var (generation.gensym "input")) +... ... [@input (\ ! map _.var (generation.identifier "input")) ... ... inputG (phase archive input) ... ... elseG (phase archive else) ... ... conditionalsG (: (Operation (List [Expression Expression])) @@ -101,7 +101,7 @@ ... (/.install "or" (binary _.logior/2)) ... (/.install "xor" (binary _.logxor/2)) ... (/.install "left-shift" (binary _.ash/2)) - ... (/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shift))) + ... (/.install "right-shift" (binary (product.uncurried //runtime.i64//right_shift))) ... (/.install "=" (binary _.=/2)) ... (/.install "<" (binary _. /.empty -... ... (/.install "=" (binary (product.uncurry _.=/2))) -... ... (/.install "<" (binary (product.uncurry _. /.empty ... (/.install "=" (binary _.string=/2)) - ... (/.install "<" (binary (product.uncurry _.string Text (Generator s))] Handler)) (function (_ extension_name phase archive input) - (case (.run parser input) + (case (.result parser input) (#try.Success input') (handler extension_name phase archive input') @@ -60,7 +60,7 @@ (do {! /////.monad} [inputG (phase archive input) elseG (phase archive else) - @input (\ ! map _.local (generation.gensym "input")) + @input (\ ! map _.local (generation.identifier "input")) conditionalsG (: (Operation (List [Expression Expression])) (monad.map ! (function (_ [chars branch]) (do ! @@ -98,18 +98,18 @@ Bundle (<| (/.prefix "i64") (|> /.empty - (/.install "and" (binary (product.uncurry //runtime.i64//and))) - (/.install "or" (binary (product.uncurry //runtime.i64//or))) - (/.install "xor" (binary (product.uncurry //runtime.i64//xor))) - (/.install "left-shift" (binary (product.uncurry //runtime.i64//left_shift))) - (/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shift))) + (/.install "and" (binary (product.uncurried //runtime.i64//and))) + (/.install "or" (binary (product.uncurried //runtime.i64//or))) + (/.install "xor" (binary (product.uncurried //runtime.i64//xor))) + (/.install "left-shift" (binary (product.uncurried //runtime.i64//left_shift))) + (/.install "right-shift" (binary (product.uncurried //runtime.i64//right_shift))) - (/.install "<" (binary (product.uncurry _.<))) - (/.install "=" (binary (product.uncurry _.=))) - (/.install "+" (binary (product.uncurry (..capped _.+)))) - (/.install "-" (binary (product.uncurry (..capped _.-)))) - (/.install "*" (binary (product.uncurry (..capped _.*)))) - (/.install "/" (binary (product.uncurry //runtime.i64//division))) + (/.install "<" (binary (product.uncurried _.<))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "+" (binary (product.uncurried (..capped _.+)))) + (/.install "-" (binary (product.uncurried (..capped _.-)))) + (/.install "*" (binary (product.uncurried (..capped _.*)))) + (/.install "/" (binary (product.uncurried //runtime.i64//division))) (/.install "%" (binary (function (_ [parameter subject]) (_.do "remainder" (list parameter) subject)))) @@ -121,14 +121,14 @@ Bundle (<| (/.prefix "f64") (|> /.empty - (/.install "+" (binary (product.uncurry _.+))) - (/.install "-" (binary (product.uncurry _.-))) - (/.install "*" (binary (product.uncurry _.*))) - (/.install "/" (binary (product.uncurry _./))) + (/.install "+" (binary (product.uncurried _.+))) + (/.install "-" (binary (product.uncurried _.-))) + (/.install "*" (binary (product.uncurried _.*))) + (/.install "/" (binary (product.uncurried _./))) (/.install "%" (binary (function (_ [parameter subject]) (_.do "remainder" (list parameter) subject)))) - (/.install "=" (binary (product.uncurry _.=))) - (/.install "<" (binary (product.uncurry _.<))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "<" (binary (product.uncurried _.<))) (/.install "i64" (unary (_.do "floor" (list)))) (/.install "encode" (unary (_.do "to_s" (list)))) (/.install "decode" (unary //runtime.f64//decode))))) @@ -149,12 +149,12 @@ Bundle (<| (/.prefix "text") (|> /.empty - (/.install "=" (binary (product.uncurry _.=))) - (/.install "<" (binary (product.uncurry _.<))) - (/.install "concat" (binary (product.uncurry (function.flip _.+)))) + (/.install "=" (binary (product.uncurried _.=))) + (/.install "<" (binary (product.uncurried _.<))) + (/.install "concat" (binary (product.uncurried (function.flip _.+)))) (/.install "index" (trinary text//index)) (/.install "size" (unary (_.the "length"))) - (/.install "char" (binary (product.uncurry //runtime.text//char))) + (/.install "char" (binary (product.uncurried //runtime.text//char))) (/.install "clip" (trinary text//clip)) ))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/common.lux index c90072ef1..2b2fca71f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/common.lux @@ -44,7 +44,7 @@ (-> Text (Generator s))] Handler)) (function (_ extension_name phase archive input) - (case (.run parser input) + (case (.result parser input) (#try.Success input') (handler extension_name phase archive input') @@ -64,7 +64,7 @@ .any)))) (function (_ extension_name phase archive [input else conditionals]) (do {! /////.monad} - [@input (\ ! map _.var (generation.gensym "input")) + [@input (\ ! map _.var (generation.identifier "input")) inputG (phase archive input) elseG (phase archive else) conditionalsG (: (Operation (List [Expression Expression])) @@ -84,7 +84,7 @@ Bundle (|> /.empty (/.install "syntax char case!" lux::syntax_char_case!) - (/.install "is" (binary (product.uncurry _.eq?/2))) + (/.install "is" (binary (product.uncurried _.eq?/2))) (/.install "try" (unary //runtime.lux//try)) )) @@ -97,18 +97,18 @@ Bundle (<| (/.prefix "i64") (|> /.empty - (/.install "and" (binary (product.uncurry //runtime.i64//and))) - (/.install "or" (binary (product.uncurry //runtime.i64//or))) - (/.install "xor" (binary (product.uncurry //runtime.i64//xor))) - (/.install "left-shift" (binary (product.uncurry //runtime.i64//left_shift))) - (/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shift))) - (/.install "=" (binary (product.uncurry _.=/2))) - (/.install "<" (binary (product.uncurry _.> _.integer->char/1 (_.make_string/2 (_.int +1))))) ))) @@ -117,13 +117,13 @@ Bundle (<| (/.prefix "f64") (|> /.empty - (/.install "=" (binary (product.uncurry _.=/2))) - (/.install "<" (binary (product.uncurry _.string/1)) (/.install "decode" (unary //runtime.f64//decode))))) @@ -140,12 +140,12 @@ Bundle (<| (/.prefix "text") (|> /.empty - (/.install "=" (binary (product.uncurry _.string=?/2))) - (/.install "<" (binary (product.uncurry _.string bundle.empty - (bundle.install "is" (binary (product.uncurry _.eq))) + (bundle.install "is" (binary (product.uncurried _.eq))) (bundle.install "try" (unary ///runtime.lux//try)))) (def: (i64//left_shifted [paramG subjectG]) @@ -46,19 +46,19 @@ Bundle (<| (bundle.prefix "i64") (|> bundle.empty - (bundle.install "and" (binary (product.uncurry _.logand))) - (bundle.install "or" (binary (product.uncurry _.logior))) - (bundle.install "xor" (binary (product.uncurry _.logxor))) + (bundle.install "and" (binary (product.uncurried _.logand))) + (bundle.install "or" (binary (product.uncurried _.logior))) + (bundle.install "xor" (binary (product.uncurried _.logxor))) (bundle.install "left-shift" (binary i64//left_shifted)) (bundle.install "logical-right-shift" (binary i64//logic_right_shifted)) (bundle.install "arithmetic-right-shift" (binary i64//arithmetic_right_shifted)) - (bundle.install "=" (binary (product.uncurry _.=))) - (bundle.install "<" (binary (product.uncurry _.<))) - (bundle.install "+" (binary (product.uncurry _.+))) - (bundle.install "-" (binary (product.uncurry _.-))) - (bundle.install "*" (binary (product.uncurry _.*))) - (bundle.install "/" (binary (product.uncurry _.floor))) - (bundle.install "%" (binary (product.uncurry _.rem))) + (bundle.install "=" (binary (product.uncurried _.=))) + (bundle.install "<" (binary (product.uncurried _.<))) + (bundle.install "+" (binary (product.uncurried _.+))) + (bundle.install "-" (binary (product.uncurried _.-))) + (bundle.install "*" (binary (product.uncurried _.*))) + (bundle.install "/" (binary (product.uncurried _.floor))) + (bundle.install "%" (binary (product.uncurried _.rem))) (bundle.install "f64" (unary (function (_ value) (_.coerce/2 [value (_.symbol "double-float")])))) (bundle.install "char" (unary (|>> _.code_char/1 _.string/1))) @@ -68,13 +68,13 @@ Bundle (<| (bundle.prefix "f64") (|> bundle.empty - (bundle.install "+" (binary (product.uncurry _.+))) - (bundle.install "-" (binary (product.uncurry _.-))) - (bundle.install "*" (binary (product.uncurry _.*))) - (bundle.install "/" (binary (product.uncurry _./))) - (bundle.install "%" (binary (product.uncurry _.mod))) - (bundle.install "=" (binary (product.uncurry _.=))) - (bundle.install "<" (binary (product.uncurry _.<))) + (bundle.install "+" (binary (product.uncurried _.+))) + (bundle.install "-" (binary (product.uncurried _.-))) + (bundle.install "*" (binary (product.uncurried _.*))) + (bundle.install "/" (binary (product.uncurried _./))) + (bundle.install "%" (binary (product.uncurried _.mod))) + (bundle.install "=" (binary (product.uncurried _.=))) + (bundle.install "<" (binary (product.uncurried _.<))) (bundle.install "i64" (unary _.floor/1)) (bundle.install "encode" (unary _.write_to_string/1)) (bundle.install "decode" (unary (let [@temp (_.var "temp")] @@ -103,7 +103,7 @@ Bundle (<| (bundle.prefix "text") (|> bundle.empty - (bundle.install "=" (binary (product.uncurry _.string=))) + (bundle.install "=" (binary (product.uncurried _.string=))) (bundle.install "<" (binary text//<)) (bundle.install "concat" (binary _.concatenate/2|string)) (bundle.install "index" (trinary text//index)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/function.lux index 9731cb94c..ce6b2bdc6 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/function.lux @@ -48,7 +48,7 @@ _ (do {! ///////phase.monad} - [@closure (\ ! map _.var (/////generation.gensym "closure"))] + [@closure (\ ! map _.var (/////generation.identifier "closure"))] (in (_.labels (list [@closure [(|> (list.enumeration inits) (list\map (|>> product.left ..capture)) _.args) 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 32b090ae1..172a4d13c 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 @@ -105,7 +105,7 @@ code) (do meta.monad [runtime_id meta.seed] - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.var (~ (code.text (%.code runtime)))))] (case declaration diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/extension.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/extension.lux index 5d8406d48..aeeb17528 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/extension.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/extension.lux @@ -10,7 +10,7 @@ [collection ["." list ("#\." functor)]]] ["." meta] - ["." macro (#+ with_gensyms) + ["." macro (#+ with_identifiers) ["." code] [syntax (#+ syntax:)]]]] ["." /// #_ @@ -31,9 +31,9 @@ (type: .public (Variadic of) (-> (List of) of)) (syntax: (arity: {arity s.nat} {name s.local_identifier} type) - (with_gensyms [g!_ g!extension g!name g!phase g!archive g!inputs g!of g!anchor g!expression g!directive] + (with_identifiers [g!_ g!extension g!name g!phase g!archive g!inputs g!of g!anchor g!expression g!directive] (do {! meta.monad} - [g!input+ (monad.seq ! (list.repeated arity (macro.gensym "input")))] + [g!input+ (monad.seq ! (list.repeated arity (macro.identifier "input")))] (in (list (` (def: .public ((~ (code.local_identifier name)) (~ g!extension)) (All [(~ g!anchor) (~ g!expression) (~ g!directive)] (-> ((~ type) (~ g!expression)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux index 6671f1e3f..12bce545f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/case.lux @@ -3,8 +3,9 @@ [lux (#- case let if) [abstract ["." monad (#+ do)]] + [control + ["." maybe]] [data - ["." maybe] ["." text] [collection ["." list ("#\." functor fold)]]] 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 815ee4a36..84e546a41 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 @@ -101,7 +101,7 @@ (.form (<>.and .local_identifier (<>.some .local_identifier))))} code) - (macro.with_gensyms [g!_ runtime] + (macro.with_identifiers [g!_ runtime] (let [runtime_name (` (_.var (~ (code.text (%.code runtime)))))] (case declaration (#.Left name) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux index 7a8dd2860..095c973b4 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux @@ -111,7 +111,7 @@ fields methods (row.row))) - .let [bytecode (format.run class.writer class)] + .let [bytecode (format.result class.writer class)] _ (generation.execute! [function_class bytecode]) _ (generation.save! function_class #.None [function_class bytecode])] (in instance))) @@ -124,7 +124,7 @@ (in ($_ _.compose abstractionG (|> inputsG - (list.chunk /arity.maximum) + (list.sub /arity.maximum) (monad.map _.monad (function (_ batchG) ($_ _.compose diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux index c3d119ec4..4db70e828 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/host.lux @@ -113,27 +113,27 @@ (_.putstatic (type.class bytecode_name (list)) ..value::field ..value::type) _.return)))) (row.row))] - (io.run (do {! (try.with io.monad)} - [bytecode (\ ! map (format.run class.writer) - (io.io bytecode)) - _ (loader.store eval_class bytecode library) - class (loader.load eval_class loader) - value (\ io.monad in (class_value eval_class class))] - (in [value - [eval_class bytecode]]))))) + (io.run! (do {! (try.with io.monad)} + [bytecode (\ ! map (format.result class.writer) + (io.io bytecode)) + _ (loader.store eval_class bytecode library) + class (loader.load eval_class loader) + value (\ io.monad in (class_value eval_class class))] + (in [value + [eval_class bytecode]]))))) (def: (execute! library loader temp_label [class_name class_bytecode]) (-> Library java/lang/ClassLoader Text Definition (Try Any)) - (io.run (do (try.with io.monad) - [existing_class? (|> (atom.read! library) - (\ io.monad map (function (_ library) - (dictionary.key? library class_name))) - (try.lift io.monad) - (: (IO (Try Bit)))) - _ (if existing_class? - (in []) - (loader.store class_name class_bytecode library))] - (loader.load class_name loader)))) + (io.run! (do (try.with io.monad) + [existing_class? (|> (atom.read! library) + (\ io.monad map (function (_ library) + (dictionary.key? library class_name))) + (try.lift io.monad) + (: (IO (Try Bit)))) + _ (if existing_class? + (in []) + (loader.store class_name class_bytecode library))] + (loader.load class_name loader)))) (def: (define! library loader [module name] valueG) (-> Library java/lang/ClassLoader Name (Bytecode Any) (Try [Text Any Definition])) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/program.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/program.lux index 0a749f337..f7ba0eb93 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/program.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/program.lux @@ -139,7 +139,7 @@ ..run_io _.return)))] [..class - (<| (format.run class.writer) + (<| (format.result class.writer) try.assumed (class.class version.v6_0 ..program::modifier diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux index dff909982..8fcd70360 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux @@ -515,7 +515,7 @@ ($_ modifier\compose class.public class.final)) - bytecode (<| (format.run class.writer) + bytecode (<| (format.result class.writer) try.assumed (class.class jvm/version.v6_0 modifier @@ -583,7 +583,7 @@ //function/count.field //function/count.type (row.row))) - bytecode (<| (format.run class.writer) + bytecode (<| (format.result class.writer) try.assumed (class.class jvm/version.v6_0 modifier 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 bfb1ab115..5ba5d0f5e 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 @@ -123,12 +123,12 @@ code) (do meta.monad [runtime_id meta.seed] - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.var (~ (code.text (%.code runtime)))))] (case declaration (#.Left name) - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [g!name (code.local_identifier name)] (in (list (` (def: .public (~ g!name) Var @@ -141,7 +141,7 @@ (_.set (~ g!name) (~ code)))))))))) (#.Right [name inputs]) - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [g!name (code.local_identifier name) inputsC (list\map code.local_identifier inputs) inputs_typesC (list\map (function.constant (` _.Expression)) 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 9b99a1ca6..bfc75d6ca 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 @@ -257,10 +257,6 @@ iteration!) (_.throw (_.new (_.constant "Exception") (list (_.string ////synthesis/case.pattern_matching_error)))))))) -(def: (gensym prefix) - (-> Text (Operation Text)) - (\ ///////phase.monad map (|>> %.nat (format prefix)) /////generation.next)) - (def: .public dependencies (-> Path (List Var)) (|>> ////synthesis/case.storage 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 a630b31c3..c236c3f75 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 @@ -27,32 +27,32 @@ (def: lux_procs Bundle (|> bundle.empty - (bundle.install "is" (binary (product.uncurry _.=))) + (bundle.install "is" (binary (product.uncurried _.=))) (bundle.install "try" (unary ///runtime.lux//try)))) (def: i64_procs Bundle (<| (bundle.prefix "i64") (|> bundle.empty - (bundle.install "and" (binary (product.uncurry _.bit_and))) - (bundle.install "or" (binary (product.uncurry _.bit_or))) - (bundle.install "xor" (binary (product.uncurry _.bit_xor))) - (bundle.install "left-shift" (binary (product.uncurry _.bit_shl))) - (bundle.install "logical-right-shift" (binary (product.uncurry ///runtime.i64//logic_right_shift))) - (bundle.install "arithmetic-right-shift" (binary (product.uncurry _.bit_shr))) - (bundle.install "=" (binary (product.uncurry _.=))) - (bundle.install "+" (binary (product.uncurry _.+))) - (bundle.install "-" (binary (product.uncurry _.-))) + (bundle.install "and" (binary (product.uncurried _.bit_and))) + (bundle.install "or" (binary (product.uncurried _.bit_or))) + (bundle.install "xor" (binary (product.uncurried _.bit_xor))) + (bundle.install "left-shift" (binary (product.uncurried _.bit_shl))) + (bundle.install "logical-right-shift" (binary (product.uncurried ///runtime.i64//logic_right_shift))) + (bundle.install "arithmetic-right-shift" (binary (product.uncurried _.bit_shr))) + (bundle.install "=" (binary (product.uncurried _.=))) + (bundle.install "+" (binary (product.uncurried _.+))) + (bundle.install "-" (binary (product.uncurried _.-))) ))) (def: int_procs Bundle (<| (bundle.prefix "int") (|> bundle.empty - (bundle.install "<" (binary (product.uncurry _.<))) - (bundle.install "*" (binary (product.uncurry _.*))) - (bundle.install "/" (binary (product.uncurry _./))) - (bundle.install "%" (binary (product.uncurry _.%))) + (bundle.install "<" (binary (product.uncurried _.<))) + (bundle.install "*" (binary (product.uncurried _.*))) + (bundle.install "/" (binary (product.uncurried _./))) + (bundle.install "%" (binary (product.uncurried _.%))) (bundle.install "frac" (unary _.floatval/1)) (bundle.install "char" (unary _.chr/1))))) @@ -60,13 +60,13 @@ Bundle (<| (bundle.prefix "frac") (|> bundle.empty - (bundle.install "+" (binary (product.uncurry _.+))) - (bundle.install "-" (binary (product.uncurry _.-))) - (bundle.install "*" (binary (product.uncurry _.*))) - (bundle.install "/" (binary (product.uncurry _./))) - (bundle.install "%" (binary (product.uncurry _.%))) - (bundle.install "=" (binary (product.uncurry _.=))) - (bundle.install "<" (binary (product.uncurry _.<))) + (bundle.install "+" (binary (product.uncurried _.+))) + (bundle.install "-" (binary (product.uncurried _.-))) + (bundle.install "*" (binary (product.uncurried _.*))) + (bundle.install "/" (binary (product.uncurried _./))) + (bundle.install "%" (binary (product.uncurried _.%))) + (bundle.install "=" (binary (product.uncurried _.=))) + (bundle.install "<" (binary (product.uncurried _.<))) (bundle.install "int" (unary _.intval/1)) (bundle.install "encode" (unary _.strval/1)) (bundle.install "decode" (unary (|>> _.floatval/1 ///runtime.some))) @@ -80,9 +80,9 @@ Bundle (<| (bundle.prefix "text") (|> bundle.empty - (bundle.install "=" (binary (product.uncurry _.=))) - (bundle.install "<" (binary (product.uncurry _.<))) - (bundle.install "concat" (binary (product.uncurry _.concat))) + (bundle.install "=" (binary (product.uncurried _.=))) + (bundle.install "<" (binary (product.uncurried _.<))) + (bundle.install "concat" (binary (product.uncurried _.concat))) (bundle.install "index" (trinary text//index)) (bundle.install "size" (unary _.strlen/1)) (bundle.install "char" (binary (function (text//char [text idx]) 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 f1c4c0eb6..62238c960 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 @@ -91,12 +91,12 @@ code) (do meta.monad [runtime_id meta.seed] - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.constant (~ (code.text (%.code runtime)))))] (case declaration (#.Left name) - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [g!name (code.local_identifier name)] (in (list (` (def: .public (~ g!name) Var @@ -109,7 +109,7 @@ (_.define (~ g!name) (~ code)))))))))) (#.Right [name inputs]) - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [g!name (code.local_identifier name) inputsC (list\map code.local_identifier inputs) inputs_typesC (list\map (function.constant (` _.Expression)) 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 137623c8a..b00d65682 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 @@ -34,7 +34,7 @@ [meta [archive (#+ Archive)]]]]]]]) -(def: .public (gensym prefix) +(def: .public (identifier prefix) (-> Text (Operation SVar)) (///////phase\map (|>> %.nat (format prefix) _.var) /////generation.next)) @@ -279,7 +279,7 @@ (do ! [pre! (recur preP) post! (recur postP) - g!once (..gensym "once")] + g!once (..identifier "once")] (in (..alternation in_closure? g!once pre! post!))) _ @@ -289,7 +289,7 @@ (-> Bit Phase! Phase Archive Path (Operation (Statement Any))) (do ///////phase.monad [pattern_matching! (pattern_matching' in_closure? statement expression archive pathP) - g!once (..gensym "once")] + g!once (..identifier "once")] (in ($_ _.then (..with_looping in_closure? g!once pattern_matching!) 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 4332539e5..6739e6ec5 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 @@ -110,7 +110,7 @@ (Generator! (List Synthesis)) (do {! ///////phase.monad} [offset /////generation.anchor - @temp (//case.gensym "lux_recur_values") + @temp (//case.identifier "lux_recur_values") argsO+ (monad.map ! (expression archive) argsS+) .let [re_binds (|> argsO+ list.enumeration 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 2cd100ce9..360d33002 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 @@ -127,7 +127,7 @@ code) (case declaration (#.Left name) - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [nameC (code.local_identifier name) code_nameC (code.local_identifier (format "@" name)) runtime_nameC (` (runtime_name (~ (code.text name))))] @@ -139,7 +139,7 @@ (_.set (list (~ g!_)) (~ code)))))))))) (#.Right [name inputs]) - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [nameC (code.local_identifier name) code_nameC (code.local_identifier (format "@" name)) runtime_nameC (` (runtime_name (~ (code.text name)))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/loop.lux index cdbaf6e1f..859744980 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/loop.lux @@ -43,7 +43,7 @@ ... true loop _ (do {! ///////phase.monad} - [$scope (\ ! map _.var (/////generation.gensym "loop_scope")) + [$scope (\ ! map _.var (/////generation.identifier "loop_scope")) initsO+ (monad.map ! (expression archive) initsS+) bodyO (/////generation.with_anchor $scope (expression archive bodyS))] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/procedure/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/procedure/common.lux index c257a2c0c..18de8ffef 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/procedure/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/procedure/common.lux @@ -10,7 +10,7 @@ [number] (coll [list "list/" Functor] (dictionary ["dict" unordered #+ Dict]))) - [macro #+ with_gensyms] + [macro #+ with_identifiers] (macro [code] ["s" syntax #+ syntax:]) [host]) @@ -63,9 +63,9 @@ " Actual: " (|> actual .int %i))) (syntax: (arity: {name s.local_identifier} {arity s.nat}) - (with_gensyms [g!_ g!proc g!name g!translate g!inputs] + (with_identifiers [g!_ g!proc g!name g!translate g!inputs] (do {@ macro.monad} - [g!input+ (monad.seq @ (list.repeated arity (macro.gensym "input")))] + [g!input+ (monad.seq @ (list.repeated arity (macro.identifier "input")))] (in (list (` (def: .public ((~ (code.local_identifier name)) (~ g!proc)) (-> (-> (..Vector (~ (code.nat arity)) Expression) Expression) (-> Text ..Proc)) @@ -123,7 +123,7 @@ (-> Text Proc) (function (_ proc_name) (function (_ translate inputsS) - (case (s.run inputsS ($_ p.seq s.nat (s.tuple (p.many s.any)) s.any)) + (case (s.result inputsS ($_ p.seq s.nat (s.tuple (p.many s.any)) s.any)) (#e.Success [offset initsS+ bodyS]) (loopT.translate_loop translate offset initsS+ bodyS) 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 b416fc128..1bcb51d73 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 @@ -94,7 +94,7 @@ code) (do meta.monad [runtime_id meta.seed] - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.var (~ (code.text (%.code runtime)))))] (case declaration 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 253bec114..dbdb0b1d0 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 @@ -36,7 +36,7 @@ [meta [archive (#+ Archive)]]]]]]]) -(def: .public (gensym prefix) +(def: .public (identifier prefix) (-> Text (Operation LVar)) (///////phase\map (|>> %.nat (format prefix) _.local) /////generation.next)) @@ -322,8 +322,8 @@ (do ///////phase.monad [pre! (recur preP) post! (recur postP) - g!once (..gensym "once") - g!continue? (..gensym "continue")] + g!once (..identifier "once") + g!continue? (..identifier "continue")] (in (..alternation in_closure? g!once g!continue? pre! post!))) _ @@ -333,8 +333,8 @@ (-> Bit (Generator! Path)) (do ///////phase.monad [pattern_matching! (pattern_matching' in_closure? statement expression archive pathP) - g!once (..gensym "once") - g!continue? (..gensym "continue")] + g!once (..identifier "once") + g!continue? (..identifier "continue")] (in ($_ _.then (..with_looping in_closure? g!once g!continue? pattern_matching!) 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 9e2a43500..9fe46c86d 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 @@ -84,7 +84,7 @@ (Generator! (List Synthesis)) (do {! ///////phase.monad} [offset /////generation.anchor - @temp (//case.gensym "lux_recur_values") + @temp (//case.identifier "lux_recur_values") argsO+ (monad.map ! (expression archive) argsS+) .let [re_binds (|> argsO+ list.enumeration 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 9de984f61..424d8b14b 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 @@ -92,12 +92,12 @@ code) (do meta.monad [runtime_id meta.seed] - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.local (~ (code.text (%.code runtime)))))] (case declaration (#.Left name) - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [g!name (code.local_identifier name)] (in (list (` (def: .public (~ g!name) LVar (~ runtime_name))) (` (def: (~ (code.local_identifier (format "@" name))) @@ -107,7 +107,7 @@ (_.set (list (~ g!name)) (~ code)))))))))) (#.Right [name inputs]) - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [g!name (code.local_identifier name) inputsC (list\map code.local_identifier inputs) inputs_typesC (list\map (function.constant (` _.Expression)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/extension/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/extension/common.lux index 95e2f1edb..c6d6f4da8 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/extension/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/extension/common.lux @@ -15,7 +15,7 @@ [collection ["." list ("#\." functor)] ["dict" dictionary (#+ Dictionary)]]] - ["." macro (#+ with_gensyms) + ["." macro (#+ with_identifiers) ["." code] [syntax (#+ syntax:)]] [target @@ -38,9 +38,9 @@ (type: .public Variadic (-> (List Expression) Computation)) (syntax: (arity: {name s.local_identifier} {arity s.nat}) - (with_gensyms [g!_ g!extension g!name g!phase g!inputs] + (with_identifiers [g!_ g!extension g!name g!phase g!inputs] (do {! macro.monad} - [g!input+ (monad.seq ! (list.repeated arity (macro.gensym "input")))] + [g!input+ (monad.seq ! (list.repeated arity (macro.identifier "input")))] (in (list (` (def: .public ((~ (code.local_identifier name)) (~ g!extension)) (-> (-> (..Vector (~ (code.nat arity)) Expression) Computation) Handler) @@ -73,7 +73,7 @@ (def: bundle::lux Bundle (|> bundle.empty - (bundle.install "is?" (binary (product.uncurry _.eq?/2))) + (bundle.install "is?" (binary (product.uncurried _.eq?/2))) (bundle.install "try" (unary ///runtime.lux//try)))) (template [ ] @@ -189,7 +189,7 @@ (|> bundle.empty (bundle.install "=" (binary text::=)) (bundle.install "<" (binary text::<)) - (bundle.install "concat" (binary (product.uncurry _.string_append/2))) + (bundle.install "concat" (binary (product.uncurried _.string_append/2))) (bundle.install "size" (unary _.string_length/1)) (bundle.install "char" (binary text::char)) (bundle.install "clip" (trinary text::clip))))) 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 e61519d16..f5f293f92 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 @@ -76,7 +76,7 @@ code) (do meta.monad [runtime_id meta.seed] - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [runtime (code.local_identifier (///reference.artifact [..module_id runtime_id])) runtime_name (` (_.var (~ (code.text (%.code runtime)))))] (case declaration diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis.lux index 4adb10f57..2b9202239 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis.lux @@ -7,7 +7,6 @@ [pipe (#+ case>)] ["." try]] [data - ["." maybe] [collection ["." list ("#\." functor)] ["." dictionary (#+ Dictionary)]]]]] @@ -86,7 +85,7 @@ (/.with_currying? false (function (_ state) (|> (//extension.apply archive optimization [name args]) - (phase.run' state) + (phase.result' state) (case> (#try.Success output) (#try.Success output) @@ -94,7 +93,7 @@ (|> args (monad.map phase.monad optimization') (phase\map (|>> [name] #/.Extension)) - (phase.run' state)))))) + (phase.result' state)))))) ))) (def: .public (phase archive analysis) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/case.lux index 46189fb26..875b2ca60 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/case.lux @@ -227,7 +227,7 @@ (-> Phase Archive Synthesis Match (Operation Synthesis)) (do {! ///.monad} [headSP (path archive synthesize headP headA) - tailSP+ (monad.map ! (product.uncurry (path archive synthesize)) tailPA+)] + tailSP+ (monad.map ! (product.uncurried (path archive synthesize)) tailPA+)] (in (/.branch/case [input (list\fold weave headSP tailSP+)])))) (template: (!masking ) 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 83822639e..7becfbe4d 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 @@ -6,9 +6,9 @@ ["." enum]] [control [pipe (#+ case>)] + ["." maybe ("#\." functor)] ["." exception (#+ exception:)]] [data - ["." maybe ("#\." functor)] ["." text ["%" format (#+ format)]] [collection 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 23227e4df..d9890dbc9 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 @@ -3,8 +3,9 @@ [lux #* [abstract ["." monad (#+ do)]] + [control + ["." maybe ("#\." monad)]] [data - ["." maybe ("#\." monad)] [collection ["." list]]] [math diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux index 6ba15c700..41d618cc3 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux @@ -4,11 +4,11 @@ [abstract ["." monad (#+ do)]] [control + ["." maybe ("#\." functor)] ["." try (#+ Try)] ["." exception (#+ exception:)]] [data ["." product] - ["." maybe ("#\." functor)] ["." text ["%" format]] [collection @@ -312,7 +312,7 @@ (list\map product.left))]] (in [(list\fold dictionary.remove redundancy (set.list bindings)) (|> redundants - (list.sort n.>) + (list.sorted n.>) (list\fold (..remove_local_from_path ..remove_local) (#/.Seq pre post)))])) (#/.Then then) 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 af17d9e15..365f9e804 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/program.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/program.lux @@ -4,11 +4,11 @@ [abstract ["." monad (#+ do)]] [control + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)]] [data ["." product] - ["." maybe] [text ["%" format (#+ format)]] [collection 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 6615d49a9..6db98721b 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux @@ -31,11 +31,11 @@ [abstract monad] [control + ["." maybe] ["." exception (#+ exception:)] [parser [text (#+ Offset)]]] [data - ["." maybe] ["." text ["%" format (#+ format)]] [collection diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux index 0f02d37be..806fdc3c9 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/synthesis.lux @@ -7,11 +7,11 @@ [hash (#+ Hash)]] [control [pipe (#+ case>)] + ["." maybe] ["." exception (#+ exception:)]] [data ["." sum] ["." product] - ["." maybe] ["." bit ("#\." equivalence)] ["." text ("#\." equivalence) ["%" format (#+ Format format)]] diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive.lux b/stdlib/source/library/lux/tool/compiler/meta/archive.lux index e42b2d2c5..348a7ced9 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive.lux @@ -239,7 +239,7 @@ (#.Some _) (#.Some [module id]) #.None #.None))) [version next] - (binary.run ..writer)))) + (binary.result ..writer)))) (exception: .public (version_mismatch {expected Version} {actual Version}) (exception.report @@ -272,7 +272,7 @@ (def: .public (import expected binary) (-> Version Binary (Try Archive)) (do try.monad - [[actual next reservations] (.run ..reader binary) + [[actual next reservations] (.result ..reader binary) _ (exception.assertion ..version_mismatch [expected actual] (n\= expected actual)) _ (exception.assertion ..corrupt_data [] diff --git a/stdlib/source/library/lux/tool/compiler/meta/cache/dependency.lux b/stdlib/source/library/lux/tool/compiler/meta/cache/dependency.lux index 4a9773f6c..66a903ca1 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/cache/dependency.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/cache/dependency.lux @@ -4,12 +4,12 @@ [abstract ["." monad (#+ do)]] [control + ["." maybe ("#\." functor)] ["." try (#+ Try)] ["." state] ["." function ["." memo (#+ Memo)]]] [data - ["." maybe ("#\." functor)] ["." text ["%" format (#+ format)]] [collection @@ -87,7 +87,7 @@ (let [ancestry (..ancestry archive)] (|> ancestry dictionary.keys - (list.sort (..dependency? ancestry)) + (list.sorted (..dependency? ancestry)) (monad.map try.monad (function (_ module) (do try.monad diff --git a/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux b/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux index 21d657352..a87c3840b 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux @@ -412,7 +412,7 @@ (monad.map ! (function (_ [module_name module_id]) (do ! [data (..read_module_descriptor fs static module_id) - [descriptor document] (async\in (.run ..parser data))] + [descriptor document] (async\in (.result ..parser data))] (if (text\= archive.runtime_module module_name) (in [true [module_name [module_id [descriptor document]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux index a36b2fda0..993b2264d 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux @@ -5,10 +5,10 @@ [abstract ["." monad (#+ Monad do)]] [control + ["." maybe ("#\." functor)] ["." try (#+ Try)]] [data ["." binary (#+ Binary)] - ["." maybe ("#\." functor)] ["." text ["%" format (#+ format)]] [collection @@ -162,7 +162,7 @@ (def: (read_jar_entry_with_unknown_size input) (-> java/util/jar/JarInputStream [Nat Binary]) - (let [chunk (binary.create ..mebi_byte) + (let [chunk (binary.empty ..mebi_byte) chunk_size (.int ..mebi_byte) buffer (java/io/ByteArrayOutputStream::new chunk_size)] (loop [so_far 0] @@ -178,7 +178,7 @@ (def: (read_jar_entry_with_known_size expected_size input) (-> Nat java/util/jar/JarInputStream [Nat Binary]) - (let [buffer (binary.create expected_size)] + (let [buffer (binary.empty expected_size)] (loop [so_far 0] (let [so_far' (|> input (java/io/InputStream::read buffer (.int so_far) (.int (n.- so_far expected_size))) diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux index f3bfea5b0..42a1a378c 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux @@ -129,4 +129,4 @@ entries (monad.map ! (..write_module now mapping) order)] (in (|> entries row.of_list - (binary.run tar.writer)))))) + (binary.result tar.writer)))))) diff --git a/stdlib/source/library/lux/tool/compiler/phase.lux b/stdlib/source/library/lux/tool/compiler/phase.lux index 73aef8bcd..5bfdac402 100644 --- a/stdlib/source/library/lux/tool/compiler/phase.lux +++ b/stdlib/source/library/lux/tool/compiler/phase.lux @@ -34,12 +34,12 @@ (type: .public (Phase s i o) (-> Archive i (Operation s o))) -(def: .public (run' state operation) +(def: .public (result' state operation) (All [s o] (-> s (Operation s o) (Try [s o]))) (operation state)) -(def: .public (run state operation) +(def: .public (result state operation) (All [s o] (-> s (Operation s o) (Try o))) (|> state @@ -107,10 +107,10 @@ (-> Name Text (Operation s a) (Operation s a))) (do ..monad [_ (in []) - .let [pre (io.run instant.now)] + .let [pre (io.run! instant.now)] output operation .let [_ (|> instant.now - io.run + io.run! instant.relative (duration.difference (instant.relative pre)) %.duration diff --git a/stdlib/source/library/lux/tool/interpreter.lux b/stdlib/source/library/lux/tool/interpreter.lux index 4631daec4..14f53e927 100644 --- a/stdlib/source/library/lux/tool/interpreter.lux +++ b/stdlib/source/library/lux/tool/interpreter.lux @@ -83,7 +83,7 @@ #.Interpreter state)) [state _] (\ (get@ #platform.file_system platform) - lift (phase.run' state enter_module)) + lift (phase.result' state enter_module)) _ (\ Console write ..welcome_message)] (in state))) @@ -128,7 +128,7 @@ (All [anchor expression directive] (-> Configuration Code )) (function (_ state) - (case (<| (phase.run' state) + (case (<| (phase.result' state) (:sharing [anchor expression directive] {(State+ anchor expression directive) state} @@ -139,7 +139,7 @@ (#try.Failure error) (if (ex.match? total.not_a_directive error) - (<| (phase.run' state) + (<| (phase.result' state) (:sharing [anchor expression directive] {(State+ anchor expression directive) state} @@ -179,7 +179,7 @@ context} {(State+ anchor expression directive) (get@ #state context)})] - (<| (phase.run' state) + (<| (phase.result' state) ... TODO: Simplify ASAP (:sharing [anchor expression directive] { @@ -191,7 +191,7 @@ (set@ #source source')) representation])))) -(def: .public (run Monad Console platform configuration generation_bundle) +(def: .public (run! Monad Console platform configuration generation_bundle) (All [! anchor expression directive] (-> (Monad !) (Console !) (Platform ! anchor expression directive) diff --git a/stdlib/source/library/lux/type.lux b/stdlib/source/library/lux/type.lux index ba0384442..7a93c29dd 100644 --- a/stdlib/source/library/lux/type.lux +++ b/stdlib/source/library/lux/type.lux @@ -8,12 +8,12 @@ [monad (#+ Monad do)]] [control ["." function] + ["." maybe] ["." exception (#+ exception:)] ["<>" parser ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ("#\." monoid equivalence)] ["." name ("#\." equivalence codec)] [collection @@ -96,7 +96,7 @@ (|> ( type) (list\map format) list.reversed - (list.interpose " ") + (list.interposed " ") (list\fold text\compose "")) )]) ([#.Sum "(Or " ")" flat_variant] @@ -108,7 +108,7 @@ (|> ins (list\map format) list.reversed - (list.interpose " ") + (list.interposed " ") (list\fold text\compose "")) " " (format out) ")")) @@ -123,7 +123,7 @@ (#.Apply param fun) (let [[type_func type_args] (flat_application type)] - ($_ text\compose "(" (format type_func) " " (|> type_args (list\map format) list.reversed (list.interpose " ") (list\fold text\compose "")) ")")) + ($_ text\compose "(" (format type_func) " " (|> type_args (list\map format) list.reversed (list.interposed " ") (list\fold text\compose "")) ")")) (^template [ ] [( env body) @@ -160,7 +160,7 @@ [#.ExQ]) (#.Parameter idx) - (maybe.else (error! ($_ text\compose + (maybe.else (panic! ($_ text\compose "Unknown type parameter" text.new_line " Index: " (n\encode idx) text.new_line "Environment: " (|> env @@ -381,7 +381,7 @@ (n.> 0))) (syntax: (new_secret_marker) - (macro.with_gensyms [g!_secret_marker_] + (macro.with_identifiers [g!_secret_marker_] (in (list g!_secret_marker_)))) (def: secret_marker @@ -409,7 +409,7 @@ (in (list (code.identifier valueN)))) (#.Right valueC) - (macro.with_gensyms [g!value] + (macro.with_identifiers [g!value] (in (list (` (.let [(~ g!value) (~ valueC)] (..:log! (~ valueC) (~ (code.identifier ..secret_marker)) (~ g!value))))))))) @@ -443,7 +443,7 @@ (syntax: .public (:sharing {type_vars ..type_parameters} {exemplar ..typed} {computation ..typed}) - (macro.with_gensyms [g!_] + (macro.with_identifiers [g!_] (let [shareC (` (: (All [(~+ (list\map code.local_identifier type_vars))] (-> (~ (get@ #type exemplar)) (~ (get@ #type computation)))) diff --git a/stdlib/source/library/lux/type/abstract.lux b/stdlib/source/library/lux/type/abstract.lux index 79c5ecb41..84a2b2942 100644 --- a/stdlib/source/library/lux/type/abstract.lux +++ b/stdlib/source/library/lux/type/abstract.lux @@ -35,7 +35,7 @@ list.tail) (type: .public Frame - {#.doc (doc "Meta-data about an abstract/nominal type in a stack of them.")} + {#.doc (example "Meta-data about an abstract/nominal type in a stack of them.")} {#name Text #type_vars (List Code) #abstraction Code @@ -93,12 +93,12 @@ (exception.except ..no_active_frames []))))) (def: .public current - {#.doc (doc "The currently-being-defined abstract/nominal type.")} + {#.doc (example "The currently-being-defined abstract/nominal type.")} (Meta Frame) (..peek! #.None)) (def: .public (specific name) - {#.doc (doc "A specific abstract/nominal type still being defined somewhere in the scope.")} + {#.doc (example "A specific abstract/nominal type still being defined somewhere in the scope.")} (-> Text (Meta Frame)) (..peek! (#.Some name))) @@ -179,10 +179,10 @@ (template [ ] [(syntax: .public ( {[frame value] ..cast}) - {#.doc (doc "Type-casting macro for abstract/nominal types." - (: - ( (: - value))))} + {#.doc (example "Type-casting macro for abstract/nominal types." + (: + ( (: + value))))} (do meta.monad [[name type_vars abstraction representation] (peek! frame)] (in (list (` ((~! :cast) [(~+ type_vars)] (~ ) (~ ) @@ -229,84 +229,84 @@ (syntax: .public (abstract: {[export_policy [name type_vars] annotations representation_type primitives] ..abstract}) - {#.doc (doc "Define abstract/nominal types which hide their representation details." - "You can convert between the abstraction and its representation selectively to access the value, while hiding it from others." - (abstract: String - {#.doc "An opaque text."} + {#.doc (example "Define abstract/nominal types which hide their representation details." + "You can convert between the abstraction and its representation selectively to access the value, while hiding it from others." + (abstract: String + {#.doc "An opaque text."} - Text + Text - (def: (string value) - (-> Text String) - (:abstraction value)) + (def: (string value) + (-> Text String) + (:abstraction value)) - (def: (text value) - (-> String Text) - (:representation value))) + (def: (text value) + (-> String Text) + (:representation value))) - "Type-parameters are optional." - (abstract: (Duplicate a) - {} + "Type-parameters are optional." + (abstract: (Duplicate a) + {} - [a a] + [a a] - (def: (duplicate value) - (All [a] (-> a (Duplicate a))) - (:abstraction [value value]))) + (def: (duplicate value) + (All [a] (-> a (Duplicate a))) + (:abstraction [value value]))) - "Definitions can be nested." - (abstract: (Single a) - {} + "Definitions can be nested." + (abstract: (Single a) + {} - a + a - (def: (single value) - (All [a] (-> a (Single a))) - (:abstraction value)) + (def: (single value) + (All [a] (-> a (Single a))) + (:abstraction value)) - (abstract: (Double a) - {} + (abstract: (Double a) + {} - [a a] + [a a] - (def: (double value) - (All [a] (-> a (Double a))) - (:abstraction [value value])) + (def: (double value) + (All [a] (-> a (Double a))) + (:abstraction [value value])) - (def: (single' value) - (All [a] (-> a (Single a))) - (:abstraction Single [value value])) + (def: (single' value) + (All [a] (-> a (Single a))) + (:abstraction Single [value value])) - (let [value 0123] - (is? value - (|> value - single' - (:representation Single) - double - :representation))))) + (let [value 0123] + (is? value + (|> value + single' + (:representation Single) + double + :representation))))) - "Type-parameters do not necessarily have to be used in the representation type." - "If they are not used, they become phantom types and can be used to customize types without changing the representation." - (abstract: (JavaScript a) - {} + "Type-parameters do not necessarily have to be used in the representation type." + "If they are not used, they become phantom types and can be used to customize types without changing the representation." + (abstract: (JavaScript a) + {} - Text + Text - (abstract: Expression {} Any) - (abstract: Statement {} Any) + (abstract: Expression {} Any) + (abstract: Statement {} Any) - (def: (+ x y) - (-> (JavaScript Expression) (JavaScript Expression) (JavaScript Expression)) - (:abstraction - (format "(" (:representation x) "+" (:representation y) ")"))) + (def: (+ x y) + (-> (JavaScript Expression) (JavaScript Expression) (JavaScript Expression)) + (:abstraction + (format "(" (:representation x) "+" (:representation y) ")"))) - (def: (while test body) - (-> (JavaScript Expression) (JavaScript Statement) (JavaScript Statement)) - (:abstraction - (format "while(" (:representation test) ") {" - (:representation body) - "}")))) - )} + (def: (while test body) + (-> (JavaScript Expression) (JavaScript Statement) (JavaScript Statement)) + (:abstraction + (format "while(" (:representation test) ") {" + (:representation body) + "}")))) + )} (do meta.monad [current_module meta.current_module_name .let [type_varsC (list\map code.local_identifier type_vars) @@ -337,22 +337,22 @@ parser)) (syntax: .public (:transmutation {selection (..selection .any)}) - {#.doc (doc "Transmutes an abstract/nominal type's phantom types." - (abstract: (JavaScript a) - {} + {#.doc (example "Transmutes an abstract/nominal type's phantom types." + (abstract: (JavaScript a) + {} - Text + Text - (abstract: Expression {} Any) - (abstract: Statement {} Any) + (abstract: Expression {} Any) + (abstract: Statement {} Any) - (def: (statement expression) - (-> (JavaScript Expression) (JavaScript Statement)) - (:transmutation expression)) + (def: (statement expression) + (-> (JavaScript Expression) (JavaScript Statement)) + (:transmutation expression)) - (def: (statement' expression) - (-> (JavaScript Expression) (JavaScript Statement)) - (:transmutation JavaScript expression))))} + (def: (statement' expression) + (-> (JavaScript Expression) (JavaScript Statement)) + (:transmutation JavaScript expression))))} (case selection (#Specific specific value) (in (list (` (.|> (~ value) @@ -365,11 +365,11 @@ (syntax: .public (^:representation {selection (.form (..selection .local_identifier))} body {branches (<>.some .any)}) - {#.doc (doc "Pattern-matching macro to easily extract a representation." - (def: (computation abstraction) - (All [a] (-> (Abstract a) ???)) - (let [(^:representation value) abstraction] - (foo (bar (baz value))))))} + {#.doc (example "Pattern-matching macro to easily extract a representation." + (def: (computation abstraction) + (All [a] (-> (Abstract a) ???)) + (let [(^:representation value) abstraction] + (foo (bar (baz value))))))} (case selection (#Specific specific name) (let [g!var (code.local_identifier name)] diff --git a/stdlib/source/library/lux/type/check.lux b/stdlib/source/library/lux/type/check.lux index 1c04d9482..10fe700e8 100644 --- a/stdlib/source/library/lux/type/check.lux +++ b/stdlib/source/library/lux/type/check.lux @@ -8,10 +8,10 @@ [apply (#+ Apply)] ["." monad (#+ Monad do)]] [control + ["." maybe] ["." try (#+ Try)] ["." exception (#+ Exception exception:)]] [data - ["." maybe] ["." product] ["." text ("#\." monoid equivalence)] [collection @@ -53,14 +53,14 @@ ["Actual" (//.format actual)])) (type: .public Var - {#.doc (doc "The ID for a type-variable in a type-checking context.")} + {#.doc (example "The ID for a type-variable in a type-checking context.")} Nat) (type: Assumption [Type Type]) (type: .public (Check a) - {#.doc (doc "A type-checking computation which may fail or yield a value.")} + {#.doc (example "A type-checking computation which may fail or yield a value.")} (-> Type_Context (Try [Type_Context a]))) (type: (Checker a) @@ -159,7 +159,7 @@ (#.Item [var_id var_type] (var::put id value plist'))))) -(def: .public (run context proc) +(def: .public (result context proc) (All [a] (-> Type_Context (Check a) (Try a))) (case (proc context) (#try.Success [context' output]) @@ -236,8 +236,8 @@ (exception.except ..unknown_type_var id)))) (def: .public (bind type id) - {#.doc (doc "Attemmpts to buy a type-variable." - "Fails if the variable has been bound already.")} + {#.doc (example "Attemmpts to buy a type-variable." + "Fails if the variable has been bound already.")} (-> Type Var (Check Any)) (function (_ context) (case (|> context (get@ #.var_bindings) (var::get id)) @@ -263,7 +263,7 @@ (exception.except ..unknown_type_var id)))) (def: .public var - {#.doc (doc "A brand-new (unbound) type-variable.")} + {#.doc (example "A brand-new (unbound) type-variable.")} (Check [Var Type]) (function (_ context) (let [id (get@ #.var_counter context)] @@ -329,7 +329,7 @@ (exception.except ..unknown_type_var current))))) (def: .public fresh_context - {#.doc (doc "An empty/un-used type-checking context.")} + {#.doc (example "An empty/un-used type-checking context.")} Type_Context {#.var_counter 0 #.ex_counter 0 @@ -675,10 +675,10 @@ (-> Type Type (Check Any)) (check' (list) expected actual)) -(def: .public (checks? expected actual) +(def: .public (subsumes? expected actual) {#.doc "A simple type-checking function that just returns a yes/no answer."} (-> Type Type Bit) - (case (..run ..fresh_context (..check' (list) expected actual)) + (case (..result ..fresh_context (..check' (list) expected actual)) (#try.Failure _) false @@ -686,13 +686,13 @@ true)) (def: .public context - {#.doc (doc "The current state of the type-checking context.")} + {#.doc (example "The current state of the type-checking context.")} (Check Type_Context) (function (_ context) (#try.Success [context context]))) (def: .public (clean inputT) - {#.doc (doc "Resolves every bound type-variable to yield a new type that is as resolved as possible.")} + {#.doc (example "Resolves every bound type-variable to yield a new type that is as resolved as possible.")} (-> Type (Check Type)) (case inputT (#.Primitive name paramsT+) diff --git a/stdlib/source/library/lux/type/dynamic.lux b/stdlib/source/library/lux/type/dynamic.lux index 8b4780d1f..db594d293 100644 --- a/stdlib/source/library/lux/type/dynamic.lux +++ b/stdlib/source/library/lux/type/dynamic.lux @@ -8,7 +8,7 @@ [data [text ["%" format]]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) ["." syntax (#+ syntax:)]] ["." type abstract]]]) @@ -27,16 +27,16 @@ (def: representation (-> Dynamic [Type Any]) (|>> :representation)) (syntax: .public (:dynamic value) - {#.doc (doc (: Dynamic - (:dynamic 123)))} - (with_gensyms [g!value] + {#.doc (example (: Dynamic + (:dynamic 123)))} + (with_identifiers [g!value] (in (list (` (let [(~ g!value) (~ value)] ((~! ..abstraction) [(:of (~ g!value)) (~ g!value)]))))))) (syntax: .public (:static type value) - {#.doc (doc (: (try.Try Nat) - (:static Nat (:dynamic 123))))} - (with_gensyms [g!type g!value] + {#.doc (example (: (try.Try Nat) + (:static Nat (:dynamic 123))))} + (with_identifiers [g!type g!value] (in (list (` (let [[(~ g!type) (~ g!value)] ((~! ..representation) (~ value))] (: ((~! try.Try) (~ type)) (if (\ (~! type.equivalence) (~' =) diff --git a/stdlib/source/library/lux/type/implicit.lux b/stdlib/source/library/lux/type/implicit.lux index 74853320d..d9e962ba2 100644 --- a/stdlib/source/library/lux/type/implicit.lux +++ b/stdlib/source/library/lux/type/implicit.lux @@ -5,12 +5,12 @@ ["." monad (#+ do)] ["." equivalence]] [control + ["." maybe] ["." try] ["<>" parser ["<.>" code (#+ Parser)]]] [data ["." product] - ["." maybe] ["." text ("#\." equivalence) ["%" format (#+ format)]] [collection @@ -212,14 +212,14 @@ [compiler meta.get_compiler] (case (|> alts (list\map (function (_ [alt_name alt_type]) - (case (check.run context - (do {! check.monad} - [[tvars alt_type] (concrete_type alt_type) - .let [[deps alt_type] (type.flat_function alt_type)] - _ (check.check dep alt_type) - context' check.context - =deps (monad.map ! (provision compiler context') deps)] - (in =deps))) + (case (check.result context + (do {! check.monad} + [[tvars alt_type] (concrete_type alt_type) + .let [[deps alt_type] (type.flat_function alt_type)] + _ (check.check dep alt_type) + context' check.context + =deps (monad.map ! (provision compiler context') deps)] + (in =deps))) (#.Left error) (list) @@ -234,11 +234,11 @@ (def: (provision compiler context dep) (-> Lux Type_Context Type (Check Instance)) - (case (meta.run compiler - ($_ meta.either - (do meta.monad [alts ..local_env] (..candidate_provision provision context dep alts)) - (do meta.monad [alts ..local_structs] (..candidate_provision provision context dep alts)) - (do meta.monad [alts ..imported_structs] (..candidate_provision provision context dep alts)))) + (case (meta.result compiler + ($_ meta.either + (do meta.monad [alts ..local_env] (..candidate_provision provision context dep alts)) + (do meta.monad [alts ..local_structs] (..candidate_provision provision context dep alts)) + (do meta.monad [alts ..imported_structs] (..candidate_provision provision context dep alts)))) (#.Left error) (check.failure error) @@ -261,7 +261,7 @@ context meta.type_context] (case (|> alts (list\map (function (_ [alt_name alt_type]) - (case (<| (check.run context) + (case (<| (check.result context) (do {! check.monad} [[tvars alt_type] (concrete_type alt_type) .let [[deps alt_type] (type.flat_function alt_type)] @@ -317,29 +317,29 @@ {member .identifier} {args (<>.or (<>.and (<>.some .identifier) .end!) (<>.and (<>.some .any) .end!))}) - {#.doc (doc "Automatic implementation selection (for type-class style polymorphism)." - "This feature layers type-class style polymorphism on top of Lux's signatures and implementations." - "When calling a polymorphic function, or using a polymorphic constant," - "this macro will check the types of the arguments, and the expected type for the whole expression" - "and it will search in the local scope, the module's scope and the imports' scope" - "in order to find suitable implementations to satisfy those requirements." - "If a single alternative is found, that one will be used automatically." - "If no alternative is found, or if more than one alternative is found (ambiguity)" - "a compile-time error will be raised, to alert the user." - "Examples:" - "Nat equivalence" - (\ number.equivalence = x y) - (\\ = x y) - "Can optionally add the prefix of the module where the signature was defined." - (\\ equivalence.= x y) - "(List Nat) equivalence" - (\\ = - (list.indices 10) - (list.indices 10)) - "(Functor List) map" - (\\ map inc (list.indices 10)) - "Caveat emptor: You need to make sure to import the module of any implementation you want to use." - "Otherwise, this macro will not find it.")} + {#.doc (example "Automatic implementation selection (for type-class style polymorphism)." + "This feature layers type-class style polymorphism on top of Lux's signatures and implementations." + "When calling a polymorphic function, or using a polymorphic constant," + "this macro will check the types of the arguments, and the expected type for the whole expression" + "and it will search in the local scope, the module's scope and the imports' scope" + "in order to find suitable implementations to satisfy those requirements." + "If a single alternative is found, that one will be used automatically." + "If no alternative is found, or if more than one alternative is found (ambiguity)" + "a compile-time error will be raised, to alert the user." + "Examples:" + "Nat equivalence" + (\ number.equivalence = x y) + (\\ = x y) + "Can optionally add the prefix of the module where the signature was defined." + (\\ equivalence.= x y) + "(List Nat) equivalence" + (\\ = + (list.indices 10) + (list.indices 10)) + "(Functor List) map" + (\\ map inc (list.indices 10)) + "Caveat emptor: You need to make sure to import the module of any implementation you want to use." + "Otherwise, this macro will not find it.")} (case args (#.Left [args _]) (do {! meta.monad} @@ -365,14 +365,14 @@ (#.Right [args _]) (do {! meta.monad} - [labels (|> (macro.gensym "") (list.repeated (list.size args)) (monad.seq !))] + [labels (|> (macro.identifier "") (list.repeated (list.size args)) (monad.seq !))] (in (list (` (let [(~+ (|> args (list.zipped/2 labels) (list\map ..pair_list) list\join))] (..\\ (~ (code.identifier member)) (~+ labels))))))) )) (def: (implicit_bindings amount) (-> Nat (Meta (List Code))) - (|> (macro.gensym "g!implicit") + (|> (macro.identifier "g!implicit") (list.repeated amount) (monad.seq meta.monad))) @@ -381,10 +381,10 @@ (.tuple (<>.many .any))) (syntax: .public (with {implementations ..implicits} body) - {#.doc (doc "Establish lexical bindings for implementations that will be prioritized over non-lexically-bound implementations." - (with [n.addition] - (n.= (\ n.addition compose left right) - (\\ compose left right))))} + {#.doc (example "Establish lexical bindings for implementations that will be prioritized over non-lexically-bound implementations." + (with [n.addition] + (n.= (\ n.addition compose left right) + (\\ compose left right))))} (do meta.monad [g!implicit+ (implicit_bindings (list.size implementations))] (in (list (` (let [(~+ (|> (list.zipped/2 g!implicit+ implementations) @@ -394,11 +394,11 @@ (~ body))))))) (syntax: .public (implicit: {implementations ..implicits}) - {#.doc (doc "Establish local definitions for implementations that will be prioritized over foreign definitions." - (implicit: [n.multiplication]) - - (n.= (\ n.multiplication compose left right) - (\\ compose left right)))} + {#.doc (example "Establish local definitions for implementations that will be prioritized over foreign definitions." + (implicit: [n.multiplication]) + + (n.= (\ n.multiplication compose left right) + (\\ compose left right)))} (do meta.monad [g!implicit+ (implicit_bindings (list.size implementations))] (in (|> (list.zipped/2 g!implicit+ implementations) diff --git a/stdlib/source/library/lux/type/quotient.lux b/stdlib/source/library/lux/type/quotient.lux index f68a1c099..a2ac468af 100644 --- a/stdlib/source/library/lux/type/quotient.lux +++ b/stdlib/source/library/lux/type/quotient.lux @@ -3,13 +3,13 @@ [lux (#- type) [abstract [equivalence (#+ Equivalence)]] - [macro (#+ with_gensyms) + [macro (#+ with_identifiers) [syntax (#+ syntax:)]] ["." type abstract]]]) (abstract: .public (Class t c %) - {#.doc (doc "The class knows how to classify/label values that are meant to be equivalent to one another.")} + {#.doc (example "The class knows how to classify/label values that are meant to be equivalent to one another.")} (-> t c) @@ -20,9 +20,9 @@ (|>> :abstraction)) (abstract: .public (Quotient t c %) - {#.doc (doc "A quotient value has been labeled with a class." - "All equivalent values will belong to the same class." - "This means all equivalent values possess the same label.")} + {#.doc (example "A quotient value has been labeled with a class." + "All equivalent values will belong to the same class." + "This means all equivalent values possess the same label.")} {#value t #label c} @@ -46,17 +46,17 @@ ) (syntax: .public (type class) - {#.doc (doc "The Quotient type associated with a Class type." - (def: even - (class even?)) + {#.doc (example "The Quotient type associated with a Class type." + (def: even + (class even?)) - (def: Even - Type - (type even)) + (def: Even + Type + (type even)) - (: Even - (quotient even 123)))} - (with_gensyms [g!t g!c g!%] + (: Even + (quotient even 123)))} + (with_identifiers [g!t g!c g!%] (in (list (` ((~! type.:by_example) [(~ g!t) (~ g!c) (~ g!%)] diff --git a/stdlib/source/library/lux/type/refinement.lux b/stdlib/source/library/lux/type/refinement.lux index 0ea7bf75c..78e289e4a 100644 --- a/stdlib/source/library/lux/type/refinement.lux +++ b/stdlib/source/library/lux/type/refinement.lux @@ -15,7 +15,7 @@ #predicate (Predicate t)} (type: .public (Refiner t %) - {#.doc (doc "A selection mechanism for refined instances of a type.")} + {#.doc (example "A selection mechanism for refined instances of a type.")} (-> t (Maybe (Refined t %)))) (def: .public (refiner predicate) @@ -38,8 +38,8 @@ ) (def: .public (lift transform) - {#.doc (doc "Yields a function that can work on refined values." - "Respects the constraints of the refinement.")} + {#.doc (example "Yields a function that can work on refined values." + "Respects the constraints of the refinement.")} (All [t %] (-> (-> t t) (-> (Refined t %) (Maybe (Refined t %))))) @@ -68,7 +68,7 @@ (only refiner tail)))) (def: .public (partition refiner values) - {#.doc (doc "Separates refined values from the un-refined ones.")} + {#.doc (example "Separates refined values from the un-refined ones.")} (All [t %] (-> (Refiner t %) (List t) [(List (Refined t %)) (List t)])) (case values @@ -87,17 +87,17 @@ (#.Item head no)])))) (syntax: .public (type refiner) - {#.doc (doc "The Refined type associated with a Refiner type." - (def: even - (refiner even?)) + {#.doc (example "The Refined type associated with a Refiner type." + (def: even + (refiner even?)) - (def: Even - Type - (type even)) + (def: Even + Type + (type even)) - (: (Maybe Even) - (even 123)))} - (macro.with_gensyms [g!t g!%] + (: (Maybe Even) + (even 123)))} + (macro.with_identifiers [g!t g!%] (in (list (` ((~! type.:by_example) [(~ g!t) (~ g!%)] (..Refiner (~ g!t) (~ g!%)) (~ refiner) diff --git a/stdlib/source/library/lux/type/resource.lux b/stdlib/source/library/lux/type/resource.lux index 8d389b11e..9ecd67608 100644 --- a/stdlib/source/library/lux/type/resource.lux +++ b/stdlib/source/library/lux/type/resource.lux @@ -6,11 +6,11 @@ ["." monad (#+ Monad do) [indexed (#+ IxMonad)]]] [control + ["." maybe] ["." exception (#+ exception:)] ["<>" parser ["<.>" code (#+ Parser)]]] [data - ["." maybe] [text ["%" format (#+ format)]] [collection @@ -26,25 +26,25 @@ abstract]]]) (type: .public (Procedure monad input output value) - {#.doc (doc "A computation that takes a sequence of resource access rights as inputs and yields a different sequence as outputs." - "A procedure yields a result value." - "A procedure can make use of monadic effects.")} + {#.doc (example "A computation that takes a sequence of resource access rights as inputs and yields a different sequence as outputs." + "A procedure yields a result value." + "A procedure can make use of monadic effects.")} (-> input (monad [output value]))) (type: .public (Linear monad value) - {#.doc (doc "A procedure that is constant with regards to resource access rights." - "This means no additional resources will be available after the computation is over." - "This also means no previously available resources will have been consumed.")} + {#.doc (example "A procedure that is constant with regards to resource access rights." + "This means no additional resources will be available after the computation is over." + "This also means no previously available resources will have been consumed.")} (All [keys] (Procedure monad keys keys value))) (type: .public (Affine monad permissions value) - {#.doc (doc "A procedure which expands the number of available resources.")} + {#.doc (example "A procedure which expands the number of available resources.")} (All [keys] (Procedure monad keys [permissions keys] value))) (type: .public (Relevant monad permissions value) - {#.doc (doc "A procedure which reduces the number of available resources.")} + {#.doc (example "A procedure which reduces the number of available resources.")} (All [keys] (Procedure monad [permissions keys] keys value))) @@ -61,7 +61,7 @@ [[keysT value] (input keysI)] ((f value) keysT))))) -(def: .public (run monad procedure) +(def: .public (run! monad procedure) (All [! v] (-> (Monad !) (Linear ! v) (! v))) (do monad [[_ output] (procedure [])] @@ -75,16 +75,16 @@ (in [keys output])))) (abstract: .public Ordered - {#.doc (doc "The mode of keys which CANNOT be swapped, and for whom order of release/consumption matters.")} + {#.doc (example "The mode of keys which CANNOT be swapped, and for whom order of release/consumption matters.")} Any) (abstract: .public Commutative - {#.doc (doc "The mode of keys which CAN be swapped, and for whom order of release/consumption DOES NOT matters.")} + {#.doc (example "The mode of keys which CAN be swapped, and for whom order of release/consumption DOES NOT matters.")} Any) (abstract: .public (Key mode key) - {#.doc (doc "The access right for a resource." - "Without the key for a resource existing somewhere among the available ambient rights, one cannot use a resource.")} + {#.doc (example "The access right for a resource." + "Without the key for a resource existing somewhere among the available ambient rights, one cannot use a resource.")} Any @@ -98,14 +98,14 @@ )) (abstract: .public (Res key value) - {#.doc (doc "A resource locked by a key." - "The 'key' represents the right to access/consume a resource.")} + {#.doc (example "A resource locked by a key." + "The 'key' represents the right to access/consume a resource.")} value (template [ ] [(def: .public ( monad value) - {#.doc (doc "Makes a value into a resource and adds the key/access-right to it to the ambient keyring for future use.")} + {#.doc (example "Makes a value into a resource and adds the key/access-right to it to the ambient keyring for future use.")} (All [! v] (Ex [k] (-> (Monad !) v (Affine ! (Key k) (Res k v))))) (function (_ keys) (\ monad in [[( []) keys] (:abstraction value)])))] @@ -115,7 +115,7 @@ ) (def: .public (read monad resource) - {#.doc (doc "Access the value of a resource, so long as its key is available.")} + {#.doc (example "Access the value of a resource, so long as its key is available.")} (All [! v k m] (-> (Monad !) (Res k v) (Relevant ! (Key m k) v))) (function (_ [key keys]) @@ -148,17 +148,17 @@ (\ monad in [context []]))) (syntax: .public (exchange {swaps ..indices}) - {#.doc (doc "A function that can exchange the keys for resource, so long as they are commutative." - "This keys will be placed at the front of the keyring in the order they are specified." - "The specific keys must be specified based of their index into the current keyring." - (do (..monad !) - [res|left (/.commutative ! pre) - res|right (/.commutative ! post) - _ ((/.exchange [1 0]) !) - left (/.read ! res|left) - right (/.read ! res|right)] - (in (format left right))))} - (macro.with_gensyms [g!_ g!context g!!] + {#.doc (example "A function that can exchange the keys for resource, so long as they are commutative." + "This keys will be placed at the front of the keyring in the order they are specified." + "The specific keys must be specified based of their index into the current keyring." + (do (..monad !) + [res|left (/.commutative ! pre) + res|right (/.commutative ! post) + _ ((/.exchange [1 0]) !) + left (/.read ! res|left) + right (/.read ! res|right)] + (in (format left right))))} + (macro.with_identifiers [g!_ g!context g!!] (case swaps #.End (in (list (` (~! no_op)))) @@ -166,7 +166,7 @@ (#.Item head tail) (do {! meta.monad} [.let [max_idx (list\fold n.max head tail)] - g!inputs (<| (monad.seq !) (list.repeated (inc max_idx)) (macro.gensym "input")) + g!inputs (<| (monad.seq !) (list.repeated (inc max_idx)) (macro.identifier "input")) .let [g!outputs (|> (monad.fold maybe.monad (function (_ from to) (do maybe.monad @@ -197,18 +197,18 @@ (template [ ] [(syntax: .public ( {amount ..amount}) - {#.doc (doc "Group/un-group keys in the keyring into/out-of tuples." - (do (..monad !) - [res|left (/.commutative ! pre) - res|right (/.commutative ! post) - _ ((/.group 2) !) - _ ((/.un_group 2) !) - right (/.read ! res|right) - left (/.read ! res|left)] - (in (format left right))))} - (macro.with_gensyms [g!_ g!context g!!] + {#.doc (example "Group/un-group keys in the keyring into/out-of tuples." + (do (..monad !) + [res|left (/.commutative ! pre) + res|right (/.commutative ! post) + _ ((/.group 2) !) + _ ((/.un_group 2) !) + right (/.read ! res|right) + left (/.read ! res|left)] + (in (format left right))))} + (macro.with_identifiers [g!_ g!context g!!] (do {! meta.monad} - [g!keys (|> (macro.gensym "keys") + [g!keys (|> (macro.identifier "keys") (list.repeated amount) (monad.seq !))] (in (list (` (: (All [(~ g!!) (~+ g!keys) (~ g!context)] diff --git a/stdlib/source/library/lux/type/unit.lux b/stdlib/source/library/lux/type/unit.lux index 35d0c66c8..511bbbb33 100644 --- a/stdlib/source/library/lux/type/unit.lux +++ b/stdlib/source/library/lux/type/unit.lux @@ -28,7 +28,7 @@ abstract]]]) (abstract: .public (Qty unit) - {#.doc (doc "A quantity with an associated unit of measurement.")} + {#.doc (example "A quantity with an associated unit of measurement.")} Int @@ -62,14 +62,14 @@ ) (interface: .public (Unit a) - {#.doc (doc "A unit of measurement, to qualify numbers with.")} + {#.doc (example "A unit of measurement, to qualify numbers with.")} (: (-> Int (Qty a)) in) (: (-> (Qty a) Int) out)) (interface: .public (Scale s) - {#.doc (doc "A scale of magnitude.")} + {#.doc (example "A scale of magnitude.")} (: (All [u] (-> (Qty u) (Qty (s u)))) scale) (: (All [u] (-> (Qty (s u)) (Qty u))) @@ -78,7 +78,7 @@ ratio)) (type: .public Pure - {#.doc (doc "A pure, unit-less quantity.")} + {#.doc (example "A pure, unit-less quantity.")} (Qty Any)) (def: .public pure @@ -95,10 +95,10 @@ .local_identifier .local_identifier (<>.else |annotations|.empty |annotations|.parser)))}) - {#.doc (doc "Define a unit of measurement." - "Both the name of the type, and the name of the Unit implementation must be specified." - (unit: .public Feet feet - {#.doc (doc "Optional annotations.")}))} + {#.doc (example "Define a unit of measurement." + "Both the name of the type, and the name of the Unit implementation must be specified." + (unit: .public Feet feet + {#.doc (example "Optional annotations.")}))} (do meta.monad [@ meta.current_module_name .let [g!type (code.local_identifier type_name)]] @@ -131,10 +131,10 @@ .local_identifier ..scale (<>.else |annotations|.empty |annotations|.parser)))}) - {#.doc (doc "Define a scale of magnitude." - (scale: .public Bajillion bajillion - [1 1,234,567,890] - {#.doc (doc "Optional annotations.")}))} + {#.doc (example "Define a scale of magnitude." + (scale: .public Bajillion bajillion + [1 1,234,567,890] + {#.doc (example "Optional annotations.")}))} (do meta.monad [.let [(^slots [#ratio.numerator #ratio.denominator]) ratio] @ meta.current_module_name @@ -177,7 +177,7 @@ [(`` (scale: .public (~~ (implementation_name )) [ ] - {#.doc (doc (~~ (template.text ["'" "' scale from " " to " "."])))}))] + {#.doc (example (~~ (template.text ["'" "' scale from " " to " "."])))}))] [Kilo 1 1,000] [Mega 1 1,000,000] @@ -191,7 +191,7 @@ (template [] [(`` (unit: .public (~~ (implementation_name )) - {#.doc (doc (~~ (template.text ["'" "' unit of meaurement."])))}))] + {#.doc (example (~~ (template.text ["'" "' unit of meaurement."])))}))] [Gram] [Meter] diff --git a/stdlib/source/library/lux/type/variance.lux b/stdlib/source/library/lux/type/variance.lux index 8755777b9..8502ec6fa 100644 --- a/stdlib/source/library/lux/type/variance.lux +++ b/stdlib/source/library/lux/type/variance.lux @@ -3,13 +3,13 @@ [lux #*]]) (type: .public (Co t) - {#.doc (doc "A constraint for covariant types.")} + {#.doc (example "A constraint for covariant types.")} (-> Any t)) (type: .public (Contra t) - {#.doc (doc "A constraint for contravariant types.")} + {#.doc (example "A constraint for contravariant types.")} (-> t Any)) (type: .public (In t) - {#.doc (doc "A constraint for invariant types.")} + {#.doc (example "A constraint for invariant types.")} (-> t t)) diff --git a/stdlib/source/library/lux/world/console.lux b/stdlib/source/library/lux/world/console.lux index 83b83145d..80e8eaebb 100644 --- a/stdlib/source/library/lux/world/console.lux +++ b/stdlib/source/library/lux/world/console.lux @@ -17,6 +17,8 @@ ["%" format (#+ format)]]]]]) (interface: .public (Console !) + {#.doc (example "An interface to console/terminal I/O.")} + (: (-> [] (! (Try Char))) read) (: (-> [] (! (Try Text))) @@ -99,10 +101,14 @@ (as_is))) (def: .public (write_line message console) + {#.doc (example "Writes the message on the console and appends a new-line/line-feed at the end.")} (All [!] (-> Text (Console !) (! (Try Any)))) (\ console write (format message text.new_line))) (interface: .public (Mock s) + {#.doc (example "A mock/simulation of a console." + "Useful for testing.")} + (: (-> s (Try [s Char])) on_read) (: (-> s (Try [s Text])) diff --git a/stdlib/source/library/lux/world/db/jdbc.lux b/stdlib/source/library/lux/world/db/jdbc.lux index 5ee34d9f7..2906cebeb 100644 --- a/stdlib/source/library/lux/world/db/jdbc.lux +++ b/stdlib/source/library/lux/world/db/jdbc.lux @@ -172,5 +172,5 @@ (do (try.with async.monad) [db (async.future (..connect creds)) result (action (..async db)) - _ (async\in (io.run (!.use (\ db close) [])))] + _ (async\in (io.run! (!.use (\ db close) [])))] (in result))) diff --git a/stdlib/source/library/lux/world/db/sql.lux b/stdlib/source/library/lux/world/db/sql.lux index e7ebd8acf..eb368954b 100644 --- a/stdlib/source/library/lux/world/db/sql.lux +++ b/stdlib/source/library/lux/world/db/sql.lux @@ -97,8 +97,8 @@ (def: Any_Query (.type (Query Any Any Any Any Any Any))) (def: .public read - {#.doc (doc "Only use this function for debugging purposes." - "Do not use this function to actually execute SQL code.")} + {#.doc (example "Only use this function for debugging purposes." + "Do not use this function to actually execute SQL code.")} (-> (SQL Any) Text) (|>> :representation)) diff --git a/stdlib/source/library/lux/world/file.lux b/stdlib/source/library/lux/world/file.lux index 8e2adf93b..19dde66f4 100644 --- a/stdlib/source/library/lux/world/file.lux +++ b/stdlib/source/library/lux/world/file.lux @@ -7,6 +7,7 @@ ["." monad (#+ Monad do)]] [control [pipe (#+ case>)] + ["." maybe ("#\." functor)] ["." try (#+ Try) ("#\." functor)] ["." exception (#+ exception:)] ["." io (#+ IO) ("#\." functor)] @@ -17,7 +18,6 @@ [data ["." bit ("#\." equivalence)] ["." product] - ["." maybe ("#\." functor)] ["." binary (#+ Binary)] ["." text ("#\." equivalence) ["%" format (#+ format)]] @@ -36,9 +36,12 @@ ["." duration]]]]) (type: .public Path + {#.doc (example "A path to a file or a directory in a file-system.")} Text) (`` (interface: .public (System !) + {#.doc (example "An interface to a file-system.")} + (: Text separator) @@ -90,12 +93,14 @@ (in [parent child]))))) (def: .public (parent fs path) + {#.doc (example "If a path represents a nested file/directory, extracts its parent directory.")} (All [!] (-> (System !) Path (Maybe Path))) (|> path (..un_rooted fs) (maybe\map product.left))) (def: .public (name fs path) + {#.doc (example "The un-nested name of a file/directory.")} (All [!] (-> (System !) Path Text)) (|> path (..un_rooted fs) @@ -137,6 +142,7 @@ ))) (def: .public (rooted fs parent child) + {#.doc (example "A nested path for a file/directory, given a root/parent path and a file/directory name within it.")} (All [!] (-> (System !) Path Text Path)) (format parent (\ fs separator) child)) @@ -260,7 +266,7 @@ (do (try.with io.monad) [.let [file (java/io/File::new path)] size (java/io/File::length file) - .let [data (binary.create (.nat size))] + .let [data (binary.empty (.nat size))] stream (java/io/FileInputStream::new file) bytes_read (java/io/InputStream::read data stream) _ (java/lang/AutoCloseable::close stream)] @@ -349,7 +355,7 @@ (def: (any_callback write!) (-> (async.Resolver (Try Any)) ffi.Function) (<| (ffi.closure [error]) - io.run + io.run! write! (if (ffi.null? error) (#try.Success []) @@ -358,7 +364,7 @@ (def: (value_callback write!) (All [a] (-> (async.Resolver (Try a)) ffi.Function)) (<| (ffi.closure [error datum]) - io.run + io.run! write! (if (ffi.null? error) (#try.Success (:assume datum)) @@ -963,7 +969,7 @@ ... (def: (make_file path) ... (do {! (try.with io.monad)} - ... [verdict (..touch [path (|> instant.now io.run instant.relative duration.millis (i./ +1,000))])] + ... [verdict (..touch [path (|> instant.now io.run! instant.relative duration.millis (i./ +1,000))])] ... (\ io.monad in ... (if verdict ... (#try.Success (..file path)) @@ -985,6 +991,7 @@ (as_is))) (def: .public (exists? monad fs path) + {#.doc (example "Checks if either a file or a directory exists at the given path.")} (All [!] (-> (Monad !) (System !) Path (! Bit))) (do monad [verdict (\ fs file? path)] @@ -1170,6 +1177,8 @@ (recur sub_directory tail))))))) (def: .public (mock separator) + {#.doc (example "A purely in-memory simulation of a file-system." + "Useful for testing.")} (-> Text (System Async)) (let [store (stm.var ..empty_mock)] (`` (implementation @@ -1318,6 +1327,8 @@ (\ fs make_directory path)))) (def: .public (make_directories monad fs path) + {#.doc (example "Creates the directory specified by the given path." + "Also, creates every super-directory necessary to make the given path valid.")} (All [!] (-> (Monad !) (System !) Path (! (Try Any)))) (let [rooted? (text.starts_with? (\ fs separator) path) segments (text.split_all_with (\ fs separator) path)] @@ -1350,6 +1361,7 @@ (in (#try.Failure error))))))))) (def: .public (make_file monad fs content path) + {#.doc (example "Creates a new file with the given content if-and-only-if the file does not already exist.")} (All [!] (-> (Monad !) (System !) Binary Path (! (Try Any)))) (do monad [? (\ fs file? path)] diff --git a/stdlib/source/library/lux/world/file/watch.lux b/stdlib/source/library/lux/world/file/watch.lux index f9229b17c..e3d26e30c 100644 --- a/stdlib/source/library/lux/world/file/watch.lux +++ b/stdlib/source/library/lux/world/file/watch.lux @@ -8,6 +8,7 @@ ["." monad (#+ do)]] [control ["." io (#+ IO)] + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)] [concurrency @@ -15,7 +16,6 @@ ["." stm (#+ STM Var)]]] [data ["." product] - ["." maybe] ["." text ["%" format (#+ format)]] [collection @@ -33,7 +33,7 @@ ["." //]) (abstract: .public Concern - {} + {#.doc (example "A particular concern to watch-out for.")} {#create Bit #modify Bit @@ -83,6 +83,8 @@ ) (interface: .public (Watcher !) + {#.doc (example "Machinery for watching a file-system for changes to files and directories.")} + (: (-> Concern //.Path (! (Try Any))) start) (: (-> //.Path (! (Try Concern))) @@ -185,6 +187,8 @@ deletions]]))) (def: .public (polling fs) + {#.doc (example "A simple watcher that works for any file-system." + "Polls files and directories to detect changes.")} (-> (//.System Async) (Watcher Async)) (let [tracker (: (Var Directory_Tracker) (stm.var (dictionary.empty text.hash)))] @@ -257,6 +261,8 @@ ))) (def: .public (mock separator) + {#.doc (example "A fake/emulated watcher." + "Must be given a path separator for the file-system.")} (-> Text [(//.System Async) (Watcher Async)]) (let [fs (//.mock separator)] [fs @@ -408,6 +414,7 @@ )) (def: .public default + {#.doc (example "The default watcher for the default file-system.")} (IO (Try (Watcher Async))) (do (try.with io.monad) [watcher (java/nio/file/FileSystem::newWatchService diff --git a/stdlib/source/library/lux/world/input/keyboard.lux b/stdlib/source/library/lux/world/input/keyboard.lux index 38e93e56c..4b3127c18 100644 --- a/stdlib/source/library/lux/world/input/keyboard.lux +++ b/stdlib/source/library/lux/world/input/keyboard.lux @@ -3,6 +3,7 @@ [lux #*]]) (type: .public Key + {#.doc (example "A key from a keyboard, identify by a numeric ID.")} Nat) (template [ ] @@ -98,6 +99,7 @@ ) (type: .public Press + {#.doc (example "A key-press for a key.")} {#pressed? Bit #input Key}) diff --git a/stdlib/source/library/lux/world/net.lux b/stdlib/source/library/lux/world/net.lux index 76b85d499..d1acb1f01 100644 --- a/stdlib/source/library/lux/world/net.lux +++ b/stdlib/source/library/lux/world/net.lux @@ -2,11 +2,17 @@ [library [lux (#- Location)]]) -(type: .public Address Text) +(type: .public Address + {#.doc (example "A TCP/IP address.")} + Text) -(type: .public Port Nat) +(type: .public Port + {#.doc (example "A TCP/IP port.")} + Nat) -(type: .public URL Text) +(type: .public URL + {#.doc (example "A Uniform Resource Locator.")} + Text) (type: .public Location {#address Address diff --git a/stdlib/source/library/lux/world/net/http/client.lux b/stdlib/source/library/lux/world/net/http/client.lux index 8055dce6e..6b2d9eb99 100644 --- a/stdlib/source/library/lux/world/net/http/client.lux +++ b/stdlib/source/library/lux/world/net/http/client.lux @@ -8,15 +8,21 @@ [control [pipe (#+ case>)] ["." io (#+ IO)] + ["." maybe ("#\." functor)] ["." try (#+ Try)] [concurrency - ["." async (#+ Async)]]] + ["." async (#+ Async)]] + [parser + ["<.>" code]]] [data ["." binary (#+ Binary)] - ["." maybe ("#\." functor)] ["." text] [collection ["." dictionary]]] + [macro + [syntax (#+ syntax:)] + ["." code] + ["." template]] [math [number ["n" nat] @@ -25,26 +31,38 @@ [// (#+ URL)]]) (interface: .public (Client !) + {#.doc (example "A HTTP client capable of issuing requests to a HTTP server.")} + (: (-> //.Method URL //.Headers (Maybe Binary) (! (Try (//.Response !)))) request)) -(template [ ] - [(def: .public ( url headers data client) - (All [!] - (-> URL //.Headers (Maybe Binary) (Client !) - (! (Try (//.Response !))))) - (\ client request url headers data))] - - [post #//.Post] - [get #//.Get] - [put #//.Put] - [patch #//.Patch] - [delete #//.Delete] - [head #//.Head] - [connect #//.Connect] - [options #//.Options] - [trace #//.Trace] +(syntax: (method_name {[_ name] .tag}) + (in (list (code.text (text.upper_cased name))))) + +(syntax: (method_function {[_ name] .tag}) + (in (list (code.local_identifier (text.lower_cased name))))) + +(template [] + [(with_expansions [ (method_function ) + (method_name ) + (template.text ["A " " request."])] + (def: .public ( url headers data client) + {#.doc (example )} + (All [!] + (-> URL //.Headers (Maybe Binary) (Client !) + (! (Try (//.Response !))))) + (\ client request url headers data)))] + + [#//.Post] + [#//.Get] + [#//.Put] + [#//.Patch] + [#//.Delete] + [#//.Head] + [#//.Connect] + [#//.Options] + [#//.Trace] ) (def: default_buffer_size @@ -52,7 +70,7 @@ (def: empty_body [Nat Binary] - [0 (binary.create 0)]) + [0 (binary.empty 0)]) (def: (body_of data) (-> Binary [Nat Binary]) @@ -117,7 +135,7 @@ (in ..empty_body)) [partial? buffer_size] - (let [buffer (binary.create buffer_size)] + (let [buffer (binary.empty buffer_size)] (if partial? (loop [so_far +0] (do {! (try.with io.monad)} diff --git a/stdlib/source/library/lux/world/net/http/cookie.lux b/stdlib/source/library/lux/world/net/http/cookie.lux index 07437df10..a138f556c 100644 --- a/stdlib/source/library/lux/world/net/http/cookie.lux +++ b/stdlib/source/library/lux/world/net/http/cookie.lux @@ -86,4 +86,4 @@ (def: .public (get header) (-> Text (Try Context)) - (l.run header (..cookies context.empty))) + (l.result header (..cookies context.empty))) diff --git a/stdlib/source/library/lux/world/net/http/query.lux b/stdlib/source/library/lux/world/net/http/query.lux index 1beb1a06f..86ee79c2b 100644 --- a/stdlib/source/library/lux/world/net/http/query.lux +++ b/stdlib/source/library/lux/world/net/http/query.lux @@ -62,4 +62,4 @@ (def: .public (parameters raw) (-> Text (Try Context)) - (l.run raw (..form context.empty))) + (l.result raw (..form context.empty))) diff --git a/stdlib/source/library/lux/world/net/http/request.lux b/stdlib/source/library/lux/world/net/http/request.lux index 8ab9265cb..b934e01d5 100644 --- a/stdlib/source/library/lux/world/net/http/request.lux +++ b/stdlib/source/library/lux/world/net/http/request.lux @@ -4,6 +4,7 @@ [control pipe ["." monad (#+ do)] + ["." maybe] ["." try (#+ Try)] [concurrency ["." async (#+ Async)] @@ -11,7 +12,6 @@ [parser ["<.>" json]]] [data - ["." maybe] ["." number ["n" nat]] ["." text @@ -40,7 +40,7 @@ [0 (|> inputs (list\map binary.size) (list\fold n.+ 0) - binary.create)] + binary.empty)] inputs))] output)) @@ -60,7 +60,7 @@ (case (do try.monad [raw ?raw content (\ json.codec decode raw)] - (json.run content reader)) + (json.result content reader)) (#try.Success input) (server input request) @@ -88,7 +88,7 @@ (maybe.else [full ""]))] (case (do try.monad [query (//query.parameters query) - input (context.run query property)] + input (context.result query property)] (in [[identification protocol (set@ #//.uri uri resource) message] input])) (#try.Success [request input]) @@ -105,7 +105,7 @@ (case (do try.monad [body ?body form (//query.parameters body)] - (context.run form property)) + (context.result form property)) (#try.Success input) (server input request) @@ -120,7 +120,7 @@ (dictionary.get "Cookie") (maybe.else "") //cookie.get)] - (context.run cookies property)) + (context.result cookies property)) (#try.Success input) (server input request) diff --git a/stdlib/source/library/lux/world/net/http/route.lux b/stdlib/source/library/lux/world/net/http/route.lux index 15f89bb99..d9519a95d 100644 --- a/stdlib/source/library/lux/world/net/http/route.lux +++ b/stdlib/source/library/lux/world/net/http/route.lux @@ -3,10 +3,10 @@ [lux (#- or) [control [monad (#+ do)] + ["." maybe] [concurrency ["." async]]] [data - ["." maybe] ["." text] [number ["n" nat]]]]] diff --git a/stdlib/source/library/lux/world/net/http/status.lux b/stdlib/source/library/lux/world/net/http/status.lux index e7810c7fa..57a88ef09 100644 --- a/stdlib/source/library/lux/world/net/http/status.lux +++ b/stdlib/source/library/lux/world/net/http/status.lux @@ -1,13 +1,28 @@ (.module: [library - [lux #*]] + [lux #* + [control + [parser + ["<.>" code]]] + [data + ["." text]] + [macro + [syntax (#+ syntax:)] + ["." code] + ["." template]]]] [// (#+ Status)]) +(syntax: (status_description {name .local_identifier}) + (in (list (code.text (text.replaced "_" " " name))))) + ... https://en.wikipedia.org/wiki/List_of_HTTP_status_codes (template [ ] - [(def: .public - Status - )] + [(with_expansions [ (status_description ) + (template.text [ ": " ])] + (def: .public + {#.doc } + Status + ))] ... 1xx Informational response [100 continue] diff --git a/stdlib/source/library/lux/world/net/uri.lux b/stdlib/source/library/lux/world/net/uri.lux index 275c1539d..84df2b716 100644 --- a/stdlib/source/library/lux/world/net/uri.lux +++ b/stdlib/source/library/lux/world/net/uri.lux @@ -2,8 +2,11 @@ [library [lux #*]]) +... https://en.wikipedia.org/wiki/Uniform_Resource_Identifier (type: .public URI + {#.doc (example "A Uniform Resource Identifier.")} Text) (def: .public separator + {#.doc (example "A separator for the pieces of a URI.")} "/") diff --git a/stdlib/source/library/lux/world/output/video/resolution.lux b/stdlib/source/library/lux/world/output/video/resolution.lux index 4ad3813d3..bbe7bdd74 100644 --- a/stdlib/source/library/lux/world/output/video/resolution.lux +++ b/stdlib/source/library/lux/world/output/video/resolution.lux @@ -4,13 +4,22 @@ [abstract [equivalence (#+ Equivalence)] [hash (#+ Hash)]] + [control + [parser + ["<.>" code]]] [data - ["." product]] + ["." product] + ["." text]] + [macro + [syntax (#+ syntax:)] + ["." code] + ["." template]] [math [number ["." nat]]]]]) (type: .public Resolution + {#.doc (example "A screen resolution.")} {#width Nat #height Nat}) @@ -22,12 +31,22 @@ (Equivalence Resolution) (\ ..hash &equivalence)) +(syntax: (description {name .local_identifier}) + (in (list (|> name + (text.replaced "/" " ") + (text.replaced "_" " ") + text.upper_cased + code.text)))) + ... https://en.wikipedia.org/wiki/Display_resolution#Common_display_resolutions (template [ ] - [(def: .public - Resolution - {#width - #height })] + [(with_expansions [ (..description ) + (template.text [ " resolution: " "x" "."])] + (def: .public + {#.doc } + Resolution + {#width + #height }))] [svga 800 600] [wsvga 1024 600] diff --git a/stdlib/source/library/lux/world/program.lux b/stdlib/source/library/lux/world/program.lux index 3216c6b93..ea1ecc83b 100644 --- a/stdlib/source/library/lux/world/program.lux +++ b/stdlib/source/library/lux/world/program.lux @@ -8,6 +8,7 @@ [control ["." function] ["." io (#+ IO)] + ["." maybe] ["." try (#+ Try)] ["." exception (#+ exception:)] [concurrency @@ -17,7 +18,6 @@ ["." environment (#+ Environment)]]] [data ["." bit ("#\." equivalence)] - ["." maybe] ["." text ["%" format (#+ format)]] [collection @@ -105,8 +105,8 @@ home) (def: directory directory) - (def: (exit code) - (io.io (error! (%.int code))))))) + (def: exit + (|>> %.int panic! io.io))))) ... Do not trust the values of environment variables ... https://wiki.sei.cmu.edu/confluence/display/java/ENV02-J.+Do+not+trust+the+values+of+environment+variables @@ -144,7 +144,7 @@ @.jvm (as_is ) @.js (as_is (def: default_exit! (-> Exit (IO Nothing)) - (|>> %.int error! io.io)) + (|>> %.int panic! io.io)) (import: NodeJs_Process ["#::." @@ -376,7 +376,7 @@ })))) (def: home - (io.run + (io.run! (with_expansions [ (io.io "~") (io.io (maybe.else "" (java/lang/System::getProperty "user.home")))] (for {@.old @@ -399,7 +399,7 @@ )))) (def: directory - (io.run + (io.run! (with_expansions [ "." (io.io (maybe.else "" (java/lang/System::getProperty "user.dir")))] (for {@.old -- cgit v1.2.3