coconut icon indicating copy to clipboard operation
coconut copied to clipboard

Add a meta statement

Open evhub opened this issue 9 years ago • 3 comments

Syntax should be

meta <lhs>:
    <body>
    <return rhs>

which should have its <body> run and then compiled to

parse(lhs + " = " + ascii(rhs))

evhub avatar Dec 09 '15 17:12 evhub

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()

evhub avatar Dec 09 '15 18:12 evhub

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}

evhub avatar Dec 09 '15 18:12 evhub

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

evhub avatar Jun 20 '17 03:06 evhub