coconut
coconut copied to clipboard
Add a meta statement
Syntax should be
meta <lhs>:
<body>
<return rhs>
which should have its <body>
run and then compiled to
parse(lhs + " = " + ascii(rhs))
This should allow support for both compile-time optimization like so
meta expensive_func_memo:
return {arg: arg |> expensive_func for arg in common_args_to_expensive_func}
and embedded metaprogramming like so
meta val:
data obj:
def __repr__(self):
return """<code>"""
return obj()
Also added should be a simple in-line meta assignment like
meta concatenated_string = (
"line 1"
"line 2"
"line 3"
)
or from the above example
meta expensive_func_memo = {arg: arg |> expensive_func for arg in common_args_to_expensive_func}
Potentially just add a meta
expression that gets evaluated at compile time and the result inlined. The code
meta(<expr>)
could inline the result of evaluating
() |*> (def () -> <expr>) |> repr