Skip to content

Version 3.4.0

Compare
Choose a tag to compare
@Technologicat Technologicat released this 02 May 11:55
· 160 commits to master since this release

3.4.0 (2 May 2021) - Quasiquotes ahoy edition:

New:

  • The unparser now recognizes hygienic captures and destructures them in debug mode. This makes the result much more readable when you unparse an AST that uses a lot of hygienic unquotes.
    • To see it in action, use mcpyrate.debug.step_expansion macro on unpythonic.syntax.tests.test_lazify. See particularly the HasThon test; both the autocurry and the lazifier produce many hygienic captures.

      Without this helpful destructuring, the macro-expanded code is completely unreadable, but with this, it only exhibits mild symptoms of parenthesitis. For example, this snippet:

      filename=callsite_filename()

      becomes, after autocurry and lazification,

      filename=$h[Lazy]((lambda: $h[maybe_force_args]($h[force]($h[currycall]),
                                                      $h[Lazy]((lambda: $h[force]($h[callsite_filename]))))))

      Here each $h[...] is a hygienic capture. That's seven captures for this very simple input! Compare this notation to the actual AST representation of, e.g., $h[Lazy]:

      __import__('mcpyrate.quotes', globals(), None, (), 0).quotes.lookup_value(('Lazy',
          b'\x80\x04\x95 \x00\x00\x00\x00\x00\x00\x00\x8c\x13unpythonic.lazyutil\x94\x8c\x04Lazy\x94\x93\x94.'))

Fixed:

  • The importer now reports the source location if destructuring a macro invocation candidate fails.

    • Some internal functions, including mcpyrate.expander.destructure_candidate, now take a mandatory filename kwarg for this purpose.
  • Fix detection of globally bound macro invocations (hygienic macro captures) in the helper method mcpyrate.expander.ismacrocall.

  • Fix syntax analysis for detecting expr macro invocations in mcpyrate.expander.destructure_candidate. Version 3.3.0 (and only that version) errored out on the AST for f()[...] even if f was not bound as a macro.