Skip to content

Virtualize def and lazy val in embedded code #58

@LPTK

Description

@LPTK

It would be nice being able to use simple def's (without type parameters) in embedded code, as well as lazy values. For example, it would avoid a workaround mentioned in emmalanguage/emma#369.

This should be doable in the same way it's done with things like if/else, i.e.:

code"if ($cnd) $thn else $els"
// really is equivalent to:
code"squid.lib.IfThenElse($cnd, $thn, $els)"

In the same way, we could have:

code"lazy val $x = $v; $b"
// virtualized as:
code"val $y = squid.utils.Lazy($v); ${b.subs(x) ~> code"$y.value"}"

and:

code"def f(...) = ... ; ..."
// if f is not recursive, as:
code"val f = (...) => ... ; ..."

and for recursive definitions, using a Y combinator with by-name parameters, for example for a recursive definition:

code"def f(...) = ... ; ..."
// if f is recursive, as:
code"val f = Y(f => ...) ; ..."

Finally, it would use an annotation (similar to the one used for implicit bindings) in order to mark virtualized bindings so they can be generated back to their original form when emitting Scala trees.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions