From 17e7566be51df5e428a6b10e6469201a8a9468da Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 7 Aug 2021 02:20:09 -0400 Subject: Made the be/de macros for (co)monadic expression extensible. --- stdlib/source/program/scriptum.lux | 64 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'stdlib/source/program/scriptum.lux') diff --git a/stdlib/source/program/scriptum.lux b/stdlib/source/program/scriptum.lux index 941c55087..ba35a2169 100644 --- a/stdlib/source/program/scriptum.lux +++ b/stdlib/source/program/scriptum.lux @@ -66,7 +66,7 @@ (-> Nat Nat Nat) (n.- (n./ 2 id) level)) -(def: (parameter_to_name [type_func_name type_function_arguments] level id) +(def: (parameter_name [type_func_name type_function_arguments] level id) (-> [Text (List Text)] Nat Nat Text) (if (type_arg? id) (let [arg_id (..arg_id level id)] @@ -81,7 +81,7 @@ (sequence.item arg_id)))) type_func_name)) -(def: (level_to_args offset level) +(def: (level_parameters offset level) (-> Nat Nat (List Text)) (if (n.= 0 level) (list) @@ -97,13 +97,13 @@ (list\map (|>> (format prefix))) (text.join_with text.new_line))) -(def: (pprint_type_definition level type_func_info tags module signature? recursive_type? type) +(def: (pprint_type_definition level type_func_info tags module interface? recursive_type? type) (-> Nat [Text (List Text)] (List Name) Text Bit Bit Type Text) (case tags (^ (list [_ single_tag])) - (if signature? - (format "(: " (pprint_type_definition level type_func_info #.None module signature? recursive_type? type) text.new_line " " single_tag ")") - (format "{#" single_tag " " (pprint_type_definition level type_func_info #.None module signature? recursive_type? type) "}")) + (if interface? + (format "(: " (pprint_type_definition level type_func_info #.None module interface? recursive_type? type) text.new_line " " single_tag ")") + (format "{#" single_tag " " (pprint_type_definition level type_func_info #.None module interface? recursive_type? type) "}")) _ (case [recursive_type? type] @@ -113,7 +113,7 @@ (format "(primitive " (%.text name) ")") _ - (format "(primitive " (%.text name) " " (|> params (list\map (pprint_type_definition level type_func_info #.None module signature? recursive_type?)) (text.join_with " ")) ")")) + (format "(primitive " (%.text name) " " (|> params (list\map (pprint_type_definition level type_func_info #.None module interface? recursive_type?)) (text.join_with " ")) ")")) [_ (#.Sum _)] (let [members (type.flat_variant type)] @@ -121,7 +121,7 @@ #.End (format "(Or " (|> members - (list\map (pprint_type_definition level type_func_info #.None module signature? recursive_type?)) + (list\map (pprint_type_definition level type_func_info #.None module interface? recursive_type?)) (text.join_with " ")) ")") @@ -134,41 +134,41 @@ (let [types (type.flat_tuple type)] (format "(#" t_name " " (|> types - (list\map (pprint_type_definition level type_func_info #.None module signature? recursive_type?)) + (list\map (pprint_type_definition level type_func_info #.None module interface? recursive_type?)) (text.join_with " ")) ")")) _ - (format "(#" t_name " " (pprint_type_definition level type_func_info #.None module signature? recursive_type? type) ")")))) + (format "(#" t_name " " (pprint_type_definition level type_func_info #.None module interface? recursive_type? type) ")")))) (text.join_with text.new_line)))) [_ (#.Product _)] (let [members (type.flat_tuple type)] (case tags #.End - (format "[" (|> members (list\map (pprint_type_definition level type_func_info #.None module signature? recursive_type?)) (text.join_with " ")) "]") + (format "[" (|> members (list\map (pprint_type_definition level type_func_info #.None module interface? recursive_type?)) (text.join_with " ")) "]") _ (let [member_docs (|> members (list.zipped/2 tags) (list\map (function (_ [[_ t_name] type]) - (if signature? - (format "(: " (pprint_type_definition level type_func_info #.None module signature? recursive_type? type) text.new_line " " t_name ")") - (format "#" t_name " " (pprint_type_definition level type_func_info #.None module signature? recursive_type? type))))) + (if interface? + (format "(: " (pprint_type_definition level type_func_info #.None module interface? recursive_type? type) text.new_line " " t_name ")") + (format "#" t_name " " (pprint_type_definition level type_func_info #.None module interface? recursive_type? type))))) (text.join_with (format text.new_line " ")))] - (if signature? + (if interface? member_docs (format "{" member_docs "}"))))) [_ (#.Function input output)] (let [[ins out] (type.flat_function type)] - (format "(-> " (|> ins (list\map (pprint_type_definition level type_func_info #.None module signature? recursive_type?)) (text.join_with " ")) + (format "(-> " (|> ins (list\map (pprint_type_definition level type_func_info #.None module interface? recursive_type?)) (text.join_with " ")) " " - (pprint_type_definition level type_func_info #.None module signature? recursive_type? out) + (pprint_type_definition level type_func_info #.None module interface? recursive_type? out) ")")) [_ (#.Parameter idx)] - (parameter_to_name type_func_info level idx) + (parameter_name type_func_info level idx) (^template [
 ]
         [[_ ( id)]
@@ -179,8 +179,8 @@
       (^template [  ]
         [[_ ( _)]
          (let [[level' body] ( type)
-               args (level_to_args level level')
-               body_doc (pprint_type_definition (n.+ level level') type_func_info tags module signature? recursive_type? body)]
+               args (level_parameters level level')
+               body_doc (pprint_type_definition (n.+ level level') type_func_info tags module interface? recursive_type? body)]
            (format "("  " " "[" (text.join_with " " args) "]"
                    (case tags
                      #.End
@@ -197,7 +197,7 @@
 
       [_ (#.Apply param fun)]
       (let [[type_func type_arguments] (type.flat_application type)]
-        (format  "(" (pprint_type_definition level type_func_info tags module signature? recursive_type? type_func) " " (|> type_arguments (list\map (pprint_type_definition level type_func_info #.None module signature? recursive_type?)) (text.join_with " ")) ")"))
+        (format  "(" (pprint_type_definition level type_func_info tags module interface? recursive_type? type_func) " " (|> type_arguments (list\map (pprint_type_definition level type_func_info #.None module interface? recursive_type?)) (text.join_with " ")) ")"))
 
       [_ (#.Named [_module _name] type)]
       (if (text\= module _module)
@@ -233,7 +233,7 @@
                ")"))
 
     (#.Parameter idx)
-    (parameter_to_name [type_func_name (list)] level idx)
+    (parameter_name [type_func_name (list)] level idx)
 
     (^template [ 
 ]
       [( id)
@@ -244,7 +244,7 @@
     (^template [  ]
       [( _)
        (let [[level' body] ( type)
-             args (level_to_args level level')
+             args (level_parameters level level')
              body_doc (pprint_type (n.+ level level') type_func_name module body)]
          (format "("  " " "[" (|> args (list.interpose " ") (text.join_with "")) "]"
                  (format " " body_doc)
@@ -354,10 +354,10 @@
     (#.Named type_name type)
     (do meta.monad
       [tags (meta.tags_of type_name)
-       #let [[_ _name] type_name
+       .let [[_ _name] type_name
              recursive_type? (annotation.recursive_type? def_annotations)
              type_arguments (annotation.type_arguments def_annotations)
-             signature? (annotation.signature? def_annotations)
+             interface? (annotation.interface? def_annotations)
              usage (case type_arguments
                      #.End
                      _name
@@ -365,13 +365,13 @@
                      _
                      (format "(" (text.join_with " " (list& _name type_arguments)) ")"))
              nesting (list.size type_arguments)]]
-      (in (md.code (format (if signature? "(interface: " "(type: ")
+      (in (md.code (format (if interface? "(interface: " "(type: ")
                            (if recursive_type? "#rec " "")
                            usage text.new_line
                            (|> type
                                (unravel_type_func nesting)
                                (when> [(new> recursive_type? [])] [unrecurse_type])
-                               (pprint_type_definition (dec nesting) [_name type_arguments] (maybe.else (list) tags) module signature? recursive_type?)
+                               (pprint_type_definition (dec nesting) [_name type_arguments] (maybe.else (list) tags) module interface? recursive_type?)
                                (text.split_all_with text.new_line)
                                (list\map (|>> (format "  ")))
                                (text.join_with text.new_line))
@@ -387,7 +387,7 @@
                           (: (-> Value (Meta (Markdown Block)))
                              (function (_ [name def_annotations type])
                                (do meta.monad
-                                 [#let [?doc (annotation.documentation def_annotations)]
+                                 [.let [?doc (annotation.documentation def_annotations)]
                                   type_code (document_type module type def_annotations)]
                                  (in ($_ md.then
                                          (md.heading/3 name)
@@ -460,7 +460,7 @@
 (def: (document_module [[module_name module] organization])
   (-> [[Text Module] Organization] (Meta [Text (Markdown Block)]))
   (do meta.monad
-    [#let [(^slots [#types #macros #implementations #values]) organization
+    [.let [(^slots [#types #macros #implementations #values]) organization
            annotations (|> module
                            (get@ #.module_annotations)
                            (maybe.else (' {}))
@@ -475,7 +475,7 @@
      types_documentation (if (list.empty? types)
                            (in empty_block)
                            (document_types module_name types))
-     #let [documentation ($_ md.then
+     .let [documentation ($_ md.then
                              types_documentation
                              (if (list.empty? macros) empty_block (document_macros module_name macros))
                              (if (list.empty? implementations) empty_block (document_implementations module_name implementations))
@@ -504,7 +504,7 @@
 (macro: (gen_documentation! _)
   (do {! meta.monad}
     [all_modules meta.modules
-     #let [lux_modules (|> all_modules
+     .let [lux_modules (|> all_modules
                            (list.only (function.compose lux_module? product.left))
                            (list.sort name_sort))]
      lux_exports (monad.map ! (function.compose meta.exports product.left)
@@ -512,7 +512,7 @@
      module_documentation (|> (list\map organize_definitions lux_exports)
                               (list.zipped/2 lux_modules)
                               (monad.map ! document_module))
-     #let [_ (io.run (monad.map io.monad save_documentation! module_documentation))]]
+     .let [_ (io.run (monad.map io.monad save_documentation! module_documentation))]]
     (in (list))))
 
 (gen_documentation!)
-- 
cgit v1.2.3