-
Notifications
You must be signed in to change notification settings - Fork 3
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
Top-down presentation style for definitions #11
Comments
Maybe in the initial implementation:
This should yield a simple implementation that does the most important thing. This could be implemented already in 0.14.2. The final detail are the names. So let's consider some alternatives. As for So maybe this feature will be named |
Meh, maybe better to feature-freeze 0.14.2 now and leave this for the next release. |
Maybe the definitions should apply backwards, to remove the need of nesting with goal:
x = a * b * c
with sfed:
a = f(...)
f = ... being equivalent to with goal:
x = a * b * c
with defs:
a = f(...)
with defs:
f = ... which expands to f = ...
a = f(...)
x = a * b * c For simple use cases, a single Maybe this still needs some more thinking... |
Occasionally a top-down presentation style (like Haskell's
where
) is useful:The benefit of the top-down presentation is the reader will already have seen the overall plan when the detailed definitions start. The program logic reads in the same order it plays out.
This would expand to:
In pure Python, it is of course already possible to delay the match call by thunkifying it:
This works because - while values are populated dynamically - name resolution occurs lexically, so it's indeed pointing to the intended
frobnicate
(and it's fine if a value has been assigned to it by the time the lambda is actually called).However, this introduces a promise, and we have to remember to force it at the end (after the many, many definitions) to actually compute the result. (For a proper evaluate-at-most-once promise, we would use
lazy[]
from MacroPy, and maybe for readability, force it usingunpythonic.force
instead of just calling it.)In use cases like this, the main benefit of inlining lambdas to the
match
call (e.g. in Racket) is the approximately top-down presentation. Thewith topdown
construct introduces this benefit for named functions.Since 0.12.0, we already support top-down presentation for expressions:
The
with topdown
construct would add top-down presentation for statements.The goal is to allow arbitrary statements in the
with definitions
block, although it is recommended to use it only to bind names used by the body (whether bydef
or by assignment, doesn't matter).The top-level explicit
with topdown
is a feature to warn the reader, because top-down style can destroy readability if used globally.The
topdown
macro should apply first in the xmas tree.At this stage the design still needs some thought, e.g.:
with definitions
to always appear in tail position, or allow it in any position?with definitions
blocks?with definitions
blocks?topdown
anddefinitions
?The text was updated successfully, but these errors were encountered: