(.using [library [lux (.except Definition let def: macro) ["[0]" meta] [abstract ["[0]" monad (.only do)]] [control ["[0]" try (.only Try)] ["[0]" exception (.only exception:)] ["<>" parser (.open: "[1]#[0]" monad) ["<[0]>" code (.only Parser)]]] [data ["[0]" product] [text ["%" format (.only format)]] [collection ["[0]" list (.open: "[1]#[0]" functor)] [dictionary ["[0]" plist (.only PList)]]]] ["[0]" macro (.only) ["[0]" local] ["[0]" code] [syntax (.only syntax:) ["[0]" declaration (.only Declaration)]]]]] ["[0]" //]) (type: Mutual (Record [#declaration Declaration #type Code #body Code])) (.def: mutual (Parser [Declaration Code Code]) (all <>.and declaration.parser .any .any )) (.def: (mutual_definition context g!context [g!name mutual]) (-> (List Code) Code [Code Mutual] Code) (` (function ((~ g!name) (~ g!context)) (.let [[(~+ context)] (~ g!context)] (function (~ (declaration.format (the #declaration mutual))) (~ (the #body mutual))))))) (.def: (macro g!context g!self) (-> Code Code Macro) (<| (as Macro) (is Macro') (function (_ parameters) (at meta.monad in (list (` (((~ g!self) (~ g!context)) (~+ parameters)))))))) (syntax: .public (let [functions (.tuple (<>.some ..mutual)) body .any]) (case functions {.#End} (in (list body)) {.#Item mutual {.#End}} (.let [g!name (|> mutual (the [#declaration declaration.#name]) code.local)] (in (list (` (.let [(~ g!name) (is (~ (the #type mutual)) (function (~ (declaration.format (the #declaration mutual))) (~ (the #body mutual))))] (~ body)))))) _ (macro.with_symbols [g!context g!output] (do [! meta.monad] [here_name meta.current_module_name hidden_names (monad.each ! (//.constant (macro.symbol "mutual_function#")) functions) .let [definitions (list#each (..mutual_definition hidden_names g!context) (list.zipped_2 hidden_names functions)) context_types (list#each (function (_ mutual) (` (-> (~ g!context) (~ (the #type mutual))))) functions) user_names (list#each (|>> (the [#declaration declaration.#name]) code.local) functions)] g!pop (local.push (list#each (function (_ [g!name mutual]) [[here_name (the [#declaration declaration.#name] mutual)] (..macro g!context g!name)]) (list.zipped_2 hidden_names functions)))] (in (list (` (.let [(~ g!context) (is (Rec (~ g!context) [(~+ context_types)]) [(~+ definitions)]) [(~+ user_names)] (.let [[(~+ user_names)] (~ g!context)] [(~+ (list#each (function (_ g!name) (` ((~ g!name) (~ g!context)))) user_names))]) (~ g!output) (~ body)] (exec (~ g!pop) (~ g!output)))))))))) (type: Definition (Record [#export_policy Code #mutual Mutual])) (.def: definition (Parser Definition) (.tuple (<>.either (<>.and .any ..mutual) (<>.and (<>#in (` .private)) ..mutual)))) (syntax: .public (def: [functions (<>.many ..definition)]) (case functions {.#End} (in (list)) {.#Item definition {.#End}} (.let [(open "_[0]") definition (open "_[0]") _#mutual] (in (list (` (.def: (~ _#export_policy) (~ (declaration.format _#declaration)) (~ _#type) (~ _#body)))))) _ (macro.with_symbols [g!context g!output] (do [! meta.monad] [here_name meta.current_module_name hidden_names (monad.each ! (//.constant (macro.symbol "mutual_function#")) functions) .let [definitions (list#each (..mutual_definition hidden_names g!context) (list.zipped_2 hidden_names (list#each (the #mutual) functions))) context_types (list#each (function (_ mutual) (` (-> (~ g!context) (~ (the [#mutual #type] mutual))))) functions) user_names (list#each (|>> (the [#mutual #declaration declaration.#name]) code.local) functions)] g!pop (local.push (list#each (function (_ [g!name mutual]) [[here_name (the [#mutual #declaration declaration.#name] mutual)] (..macro g!context g!name)]) (list.zipped_2 hidden_names functions)))] (in (partial_list (` (.def: (~ g!context) [(~+ (list#each (the [#mutual #type]) functions))] (.let [(~ g!context) (is (Rec (~ g!context) [(~+ context_types)]) [(~+ definitions)]) [(~+ user_names)] (~ g!context)] [(~+ (list#each (function (_ g!name) (` ((~ g!name) (~ g!context)))) user_names))]))) g!pop (list#each (function (_ mutual) (.let [g!name (|> mutual (the [#mutual #declaration declaration.#name]) code.local)] (` (.def: (~ (the #export_policy mutual)) (~ g!name) (~ (the [#mutual #type] mutual)) (.let [[(~+ user_names)] (~ g!context)] (~ g!name)))))) functions)))))))