3535# Long description for package homepage on PyPI
3636#
3737DESC = """We provide missing features for Python, mainly from the list processing
38- tradition, but with some haskellisms mixed in. For the adventurous, we include
39- a set of syntactic macros (using MacroPy) that are designed to work together .
38+ tradition, but with some haskellisms mixed in. We place a special emphasis on
39+ **clear, pythonic syntax** .
4040
41- We place a special emphasis on **clear, pythonic syntax**. Design considerations
42- are simplicity, robustness, and minimal dependencies.
41+ Optionally, we also provide extensions to the Python language as a set of
42+ syntactic macros that are designed to work together. Each macro adds an
43+ orthogonal piece of functionality that can (mostly) be mixed and matched
44+ with the others.
45+
46+ Design considerations are simplicity, robustness, and minimal dependencies.
47+ Currently none required; MacroPy optional, to enable the syntactic macros.
4348
4449**Without macros**, our features include tail call optimization (TCO), TCO'd
4550loops in FP style, call/ec, let & letrec, assign-once, multi-expression lambdas,
4651dynamic assignment (a.k.a. *parameterize*, *special variables*), memoization
4752(also for generators and iterables), currying, function composition,
4853folds and scans (left and right), unfold, lazy partial unpacking of iterables,
49- functional update for sequences, and pythonic lispy linked lists (``cons``).
54+ functional update for sequences, pythonic lispy linked lists (``cons``), and
55+ compact syntax for creating mathematical sequences that support infix math.
5056
5157Our curry modifies Python's reduction rules. It passes any extra arguments
5258through on the right, and calls a callable return value on the remaining
6470macros that essentially extend the Python language, adding features that would
6571be either complicated or impossible to provide (and/or use) otherwise.
6672
67- **With macros**, we add automatic currying, automatic tail-call optimization,
68- continuations (``call/cc`` for Python), ``let-syntax`` (splice code at macro
69- expansion time), lexically scoped ``let`` and ``do`` with lean syntax,
70- implicit return statements, and easy-to-use multi-expression lambdas
71- with local variables.
73+ **With macros**, we add automatic currying, automatic tail-call optimization
74+ (TCO), call-by-need (lazy functions), continuations (``call/cc`` for Python),
75+ ``let-syntax `` (splice code at macro expansion time), lexically scoped
76+ ``let`` and ``do`` with lean syntax, implicit return statements, and
77+ easy-to-use multi-expression lambdas with local variables.
7278
73- The TCO macro has a fairly extensive expression analyzer, so things like ``and``,
74- ``or``, ``a if p else b`` and any uses of the ``do[]`` and ``let[]`` macros are
75- accounted for when performing the tail-call transformation.
79+ The TCO macro has a fairly extensive expression analyzer, so things like
80+ ``and``, `` or``, ``a if p else b`` and any uses of the ``do[]`` and ``let[]``
81+ macros are accounted for when performing the tail-call transformation.
7682
7783The continuation system is based on a semi-automated partial conversion into
7884continuation-passing style (CPS), with continuations represented as closures.
97103 "something else"]
98104 assert answer(42) == "something else"
99105
100- # do: imperative code in expression position
106+ # do: imperative code in any expression position
101107 y = do[local[x << 17],
102108 print(x),
103109 x << 23,
@@ -118,6 +124,14 @@ def add3(a, b, c):
118124 myadd = lambda a, b: a + b
119125 assert mymap(myadd, ll(1, 2, 3), ll(2, 4, 6)) == ll(3, 6, 9)
120126
127+ # lazy functions (call-by-need) like Haskell
128+ with lazify:
129+ def f(a, b):
130+ return a
131+ def g(a, b):
132+ return f(2*a, 3*b)
133+ assert g(21, 1/0) == 42 # the 1/0 is never evaluated
134+
121135 # automatic tail-call optimization (TCO) like Scheme, Racket
122136 with tco:
123137 assert letrec((evenp, lambda x: (x == 0) or oddp(x - 1)),
@@ -173,6 +187,17 @@ def g(x):
173187 (print, (mymap, double, (q, 1, 2, 3)))
174188 assert (mymap, double, (q, 1, 2, 3)) == ll(2, 4, 6)
175189
190+ # the HasThon programming language
191+ with curry, lazify:
192+ def add2first(a, b, c):
193+ return a + b
194+ assert add2first(2)(3)(1/0) == 5
195+
196+ assert letrec[((c, 42),
197+ (d, 1/0),
198+ (e, 2*c)) in
199+ add2first(c)(e)(d)] == 126
200+
176201 # call/cc for Python
177202 with continuations:
178203 stack = []
@@ -203,7 +228,7 @@ def pythagorean_triples(maxn):
203228
204229 # if Python didn't already have generators, we could add them with call/cc:
205230 with continuations:
206- @dlet((k, None))
231+ @dlet((k, None)) # let-over-def decorator
207232 def g():
208233 if k:
209234 return k()
0 commit comments