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

new genAst as replacement for quote do #17426

Merged
merged 32 commits into from
Apr 2, 2021
Merged

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Mar 20, 2021

continuation of #11722, see previous discussion in that PR. genAst subsumes quote do.

refs #11722 (comment)

closes these issues by providing a suitable replacement:

for #7889, see unittests showing this is fixed (for both quote do and genAst) by using regular call syntax instead of method call syntax; can be therefore closed as dup of #7085

future work

lib/core/macros.nim Outdated Show resolved Hide resolved
lib/std/genasts.nim Outdated Show resolved Hide resolved
@timotheecour
Copy link
Member Author

PTAL

@timotheecour
Copy link
Member Author

@Araq anything else needed for this PR?

@Araq
Copy link
Member

Araq commented Apr 2, 2021

Documentation. It's barely comprehensible. Take this example:

 macro fun(a: bool, b: static bool): untyped =
      let c = false # doesn't override parameter `c`
      var d = 11 # var => gensym'd
      proc localFun(): auto = 12 # proc => inject'd
      genAst(a, b, c = true):
        # echo d # not captured => gives `var not init`
        (a, b, c, localFun())
    assert fun(true, false) == (true, false, true, 12)

This is not an example how to use genAst, it tries to tell me something else, like what kind of bugs have been avoided in genAst's design. Or something else, I am not too sure what it tries to tell me.

You could also write a guest post about this new module, I can imagine lots of design effort went into it avoiding "quote do"s limitations and bugs.

lib/core/macros.nim Outdated Show resolved Hide resolved
@timotheecour
Copy link
Member Author

timotheecour commented Apr 2, 2021

PTAL, I've improved the docs and piggy backed on quote do's own example of simplified unittest.check, but made it better here by showing the lhs+rhs on error. It's intentionally simplified (eg no care taken about multiple evaluation issues or deferred failure, which are out of scope). The resulting code is compact and readable.

I also kept the other example but with more explanations

You could also write a guest post about this new module,

why not, maybe some time after this PR is merged and some initial usage feedback

@Araq Araq merged commit 9abd383 into nim-lang:devel Apr 2, 2021
@ringabout
Copy link
Member

Cool!

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