(.using [library [lux "*" ["@" target] [abstract [monad {"+" do}]] [control ["[0]" io] [concurrency ["[0]" thread]] ["<>" parser ["<[0]>" code] ["<[0]>" cli]]] [macro {"+" with_symbols} [syntax {"+" syntax:}] ["[0]" code]]]]) (type: Arguments (Variant {#Raw Text} {#Parsed (List Code)})) (def: arguments^ (.Parser Arguments) (<>.or .local_symbol (.tuple (<>.some .any)))) (syntax: .public (program: [args ..arguments^ body .any]) (with_symbols [g!program g!args g!_ g!output g!message] (let [initialization+event_loop (for [@.old body @.jvm body @.js body @.python body] (` ((~! do) (~! io.monad) [(~ g!output) (~ body) (~ g!_) (~! thread.run!)] ((~' in) (~ g!output)))))] (in (list (` ("lux def program" (~ (case args {#Raw args} (` (.function ((~ g!program) (~ (code.symbol ["" args]))) (~ initialization+event_loop))) {#Parsed args} (` (.function ((~ g!program) (~ g!args)) (case ((~! .result) (: (~! (.Parser (io.IO .Any))) ((~! do) (~! <>.monad) [(~+ args) (~ g!_) (~! .end)] ((~' in) (~ initialization+event_loop)))) (~ g!args)) {.#Right (~ g!output)} (~ g!output) {.#Left (~ g!message)} (.panic! (~ g!message))))))))))))))