Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtualize def and lazy val in embedded code #58

Open
LPTK opened this issue Jun 13, 2018 · 0 comments
Open

Virtualize def and lazy val in embedded code #58

LPTK opened this issue Jun 13, 2018 · 0 comments

Comments

@LPTK
Copy link
Member

LPTK commented Jun 13, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant