From 4965597043aca57a05760113f1851e96dad1eaf8 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 14 Mar 2022 06:14:57 -0400 Subject: Leaner syntax for the "for" macro. --- lux-python/source/program.lux | 112 +++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 56 deletions(-) (limited to 'lux-python') diff --git a/lux-python/source/program.lux b/lux-python/source/program.lux index 66adcaa27..e784a834e 100644 --- a/lux-python/source/program.lux +++ b/lux-python/source/program.lux @@ -340,9 +340,9 @@ )) (:as org/python/core/PyObject it)))) )] - (for [@.old (as_is ) - @.jvm (as_is ) - @.python (as_is)])) + (for @.old (as_is ) + @.jvm (as_is ) + @.python (as_is))) (with_expansions [ (as_is (def: (call_macro inputs lux macro) (-> (List Code) Lux org/python/core/PyFunction (Try (Try [Lux (List Code)]))) @@ -380,13 +380,13 @@ {.#None} (exception.except ..cannot_apply_a_non_function [(:as java/lang/Object macro)]))))] - (for [@.old (as_is ) - @.jvm (as_is ) + (for @.old (as_is ) + @.jvm (as_is ) - @.python - (def: (expander macro inputs lux) - Expander - {try.#Success ((:as Macro' macro) inputs lux)})])) + @.python + (def: (expander macro inputs lux) + Expander + {try.#Success ((:as Macro' macro) inputs lux)}))) (with_expansions [ (def: host (IO (Host (_.Expression Any) (_.Statement Any))) @@ -433,47 +433,47 @@ (do try.monad [_ (execute! content)] (evaluate! context [{.#None} (_.var (reference.artifact context))]))))))))] - (for [@.old - @.jvm - - @.python - (as_is (import: (dict [] ffi.Dict)) - (import: (eval [ffi.String ffi.Dict] "try" Any)) - - (def: host - (IO (Host (_.Expression Any) (_.Statement Any))) - (io (: (Host (_.Expression Any) (_.Statement Any)) - (let [globals (..dict []) - evaluate! (: (-> unit.ID (_.Expression Any) (Try Any)) - (function (evaluate! context input) - (..eval [(_.code input) globals]))) - execute! (: (-> (_.Statement Any) (Try Any)) - (function (execute! input) - (ffi.try ("python exec" (_.code input) globals)))) - define! (: (-> unit.ID (_.Expression Any) (Try [Text Any (_.Statement Any)])) - (function (define! context input) - (let [global (reference.artifact context) - @global (_.var global)] - (do try.monad - [.let [definition (_.set (list @global) input)] - _ (execute! definition) - value (evaluate! context @global)] - (in [global value definition])))))] - (implementation - (def: evaluate! evaluate!) - (def: execute! execute!) - (def: define! define!) - - (def: (ingest context content) - (|> content (# utf8.codec decoded) try.trusted (:as (_.Statement Any)))) - - (def: (re_learn context content) - (execute! content)) - - (def: (re_load context content) - (do try.monad - [_ (execute! content)] - (evaluate! context (_.var (reference.artifact context)))))))))))])) + (for @.old + @.jvm + + @.python + (as_is (import: (dict [] ffi.Dict)) + (import: (eval [ffi.String ffi.Dict] "try" Any)) + + (def: host + (IO (Host (_.Expression Any) (_.Statement Any))) + (io (: (Host (_.Expression Any) (_.Statement Any)) + (let [globals (..dict []) + evaluate! (: (-> unit.ID (_.Expression Any) (Try Any)) + (function (evaluate! context input) + (..eval [(_.code input) globals]))) + execute! (: (-> (_.Statement Any) (Try Any)) + (function (execute! input) + (ffi.try ("python exec" (_.code input) globals)))) + define! (: (-> unit.ID (_.Expression Any) (Try [Text Any (_.Statement Any)])) + (function (define! context input) + (let [global (reference.artifact context) + @global (_.var global)] + (do try.monad + [.let [definition (_.set (list @global) input)] + _ (execute! definition) + value (evaluate! context @global)] + (in [global value definition])))))] + (implementation + (def: evaluate! evaluate!) + (def: execute! execute!) + (def: define! define!) + + (def: (ingest context content) + (|> content (# utf8.codec decoded) try.trusted (:as (_.Statement Any)))) + + (def: (re_learn context content) + (execute! content)) + + (def: (re_load context content) + (do try.monad + [_ (execute! content)] + (evaluate! context (_.var (reference.artifact context))))))))))))) (with_expansions [ (as_is (def: (extender phase_wrapper) (-> phase.Wrapper Extender) @@ -499,13 +499,13 @@ (ffi.write! 4 (..to_host state))) handler)] (..read output)))))] - (for [@.old (as_is ) - @.jvm (as_is ) + (for @.old (as_is ) + @.jvm (as_is ) - @.python - (def: (extender phase_wrapper handler) - (-> phase.Wrapper Extender) - (:expected handler))])) + @.python + (def: (extender phase_wrapper handler) + (-> phase.Wrapper Extender) + (:expected handler)))) (def: (phase_wrapper archive) (-> Archive (runtime.Operation phase.Wrapper)) -- cgit v1.2.3