diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/debug.lux | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/stdlib/source/library/lux/debug.lux b/stdlib/source/library/lux/debug.lux index 45fdba0d2..6039bbcd8 100644 --- a/stdlib/source/library/lux/debug.lux +++ b/stdlib/source/library/lux/debug.lux @@ -141,6 +141,7 @@ (text.enclosed ["[" "]"]))))) (def: .public (inspection value) + {#.doc (example "A best-effort attempt to generate a textual representation of a value, without knowing its type.")} Inspector (with_expansions [<jvm> (let [object (:as java/lang/Object value)] (`` (<| (~~ (template [<class> <processing>] @@ -512,6 +513,7 @@ )))) (def: .public (representation type value) + {#.doc (example "A best-effort attempt to generate a textual representation of a value, while knowing its type.")} (-> Type Any (Try Text)) (case (<type>.result ..representation_parser type) (#try.Success representation) @@ -520,14 +522,21 @@ (#try.Failure _) (exception.except ..cannot_represent_value type))) -(syntax: .public (private {definition <code>.identifier}) +(syntax: .public (private [definition <code>.identifier]) + {#.doc (example "Allows access to un-exported definitions in other modules." + "Module A" + (def: .private (secret_definition input) + (-> ??? ???) + (foo (bar (baz input)))) + "Module B" + ((..private secret_definition) my_input))} (let [[module _] definition] (in (list (` ("lux in-module" (~ (code.text module)) (~ (code.identifier definition)))))))) (def: .public (log! message) - {#.doc "Logs message to standard output."} + {#.doc "Prints/writes a message to standard output."} (-> Text Any) ("lux io log" message)) @@ -536,7 +545,12 @@ ["Location" (%.location location)] ["Type" (%.type type)])) -(syntax: .public (:hole) +(syntax: .public (:hole []) + {#.doc (example "A typed 'hole'." + "Reveals the type expected of the expression that should go in the hole." + (: (-> Nat Text) + (function (_ number) + (:hole))))} (do meta.monad [location meta.location expectedT meta.expected_type] @@ -556,15 +570,38 @@ (exception.report ["Name" (%.text name)])) -(syntax: .public (here {targets (: (<code>.Parser (List Target)) +(syntax: .public (here [targets (: (<code>.Parser (List Target)) (|> ..target <>.some - (<>.else (list))))}) + (<>.else (list))))]) + {#.doc (example "Shows the names and values of local bindings available around the call to 'here'." + (let [foo 123 + bar +456 + baz +789.0] + (: Any + (here))) + "=>" + "foo: +123" + "bar: +456" + "baz: +789.0" + [] + + "Can optionally be given a list of definitions to focus on." + "These definitions to focus on can include custom format to represent the values." + (let [foo 123 + bar +456 + baz +789.0] + (: Any + (here {foo %.nat} baz))) + "=>" + "foo: 123" + "baz: +789.0" + [])} (do {! meta.monad} [location meta.location locals meta.locals .let [environment (|> locals - list.concat + list.joined ... The list is reversed to make sure that, when building the dictionary, ... later bindings overshadow earlier ones if they have the same name. list.reversed |