Skip to content

Commit 831348c

Browse files
committed
improve macro docs
1 parent b14e171 commit 831348c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

doc/macros.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ Is this just a set of macros, a language extension, or a compiler for a new lang
21412141

21422142
### The xmas tree combo
21432143

2144-
The macros in ``unpythonic.syntax`` are designed to work together, but some care needs to be taken regarding the order in which they expand.
2144+
The macros in ``unpythonic.syntax`` are designed to work together, but some care needs to be taken regarding the order in which they expand. This complexity unfortunately comes with any pick-and-mix-your-own-language kit, because some features inevitably interact. For example, it is possible to lazify [continuation-enabled](https://en.wikipedia.org/wiki/Continuation-passing_style) code, but running the transformations the other way around produces nonsense.
21452145

21462146
For simplicity, **the block macros make no attempt to prevent invalid combos** (unless there is a specific technical reason to do that for some particular combination). Be careful; e.g. don't nest several ``with tco`` blocks (lexically), that won't work.
21472147

@@ -2170,7 +2170,7 @@ The invocation `with mac` is *lexically on the outside*, thus the macro expander
21702170
2. Explicit recursion by `with mac`. This expands the `with cheese`.
21712171
3. Second pass (inside out) of `with mac`.
21722172

2173-
So, for example, even though `lazify` must *perform its AST editing* after `autocurry`, it is actually a two-pass macro. The first pass (outside in) only performs some preliminary analysis; the actual lazification happens in the second pass (inside out). So the correct invocation comboing these two is `with lazify, autocurry`. See [the dialect examples](../unpythonic/dialects/) for combo invocations that are known to work.
2173+
So, for example, even though `lazify` must *perform its AST editing* after `autocurry`, it is actually a two-pass macro. The first pass (outside in) only performs some preliminary analysis; the actual lazification happens in the second pass (inside out). So the correct invocation comboing these two is `with lazify, autocurry`. Similarly, `with lazify, continuations` is correct, though the CPS transformation must occur first; these are both two-pass macros that perform their edits in the inside-out pass. See [the dialect examples](../unpythonic/dialects/) for combo invocations that are known to work.
21742174

21752175
Example combo in the single-line format:
21762176

unpythonic/syntax/tests/test_lazify.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,16 @@ def f(a, b):
502502
# - cc built by chain_conts is treated as lazy, **itself**; then it's up to
503503
# the continuations chained by it to decide whether to force their args.
504504
# - the default cont ``identity`` is strict, so it will force return values
505+
# - if you want a non-strict identity for use at the entry point to your
506+
# continuation-enabled computation, do this:
507+
#
508+
# from unpythonic import identity
509+
# from unpythonic.lazyutil import passthrough_lazy_args
510+
# lazy_identity = passthrough_lazy_args(identity)
511+
#
512+
# and then explicitly set the kwarg `cc=lazy_identity` when invoking the
513+
# continuation-enabled computation (e.g. in the example below, we could
514+
# `ourpromises = doit(cc=lazy_identity)`).
505515
with testset("integration with continuations"):
506516
with lazify, continuations:
507517
k = None

0 commit comments

Comments
 (0)