You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To improve the first impression, provide a runnable demo of an appropriate subset of features right near the start of the main README.
Focus on short and impressive. It does not need to be a complete tour. But it must, quickly, answer the universal first question: why should I bother to read any further?
Things to consider:
Showcase preference, i.e. focus the demo on what?
Features that currently don't exist in other libraries (continuations)?
Features that obviously require a complex implementation?
Features that are "done right", esp. in corner cases (e.g. rackety foldl or scanl with multiple inputs, memoize that caches also exceptions)?
Features that give a lot of added value and are easy to use?
Target audience, i.e. focus the demo for whom?
Applied mathematicians and haskellers may like the rule-inferring lazy math sequence constructor s.
A general programming audience may feel at home with let or continuations.
Complexity balance. The demoed features should be simple enough to explain and use, to facilitate a short code example with a one-liner comment, but complex enough in expected implementation (by a seasoned Python programmer), to communicate that rewriting the same functionality from scratch in five minutes is not realistic.
Holistic perspective. How to communicate that unpythonic is essentially a language framework, where (unless specifically otherwise stated) all of the features are designed to work together?
Automatic TCO works also with lambdas, and analyzes the tail position from expressions. In a logical expression (even when nested) it's always the rightmost item, because short-circuiting depends on values, which are not available at macro expansion time.
fromunpythonic.syntaximportmacros, lazifywithlazify:
defmy_if(p, a, b):
ifp:
returna# b never evaluated in this code pathelse:
returnb# a never evaluated in this code pathassertmy_if(True, 23, 1/0) ==23assertmy_if(False, 1/0, 42) ==42
Continuations (call/cc), also with automatic TCO.
fromunpythonicimportmacros, continuations, call_ccwithcontinuations:
# McCarthy's amb() operatorstack= []
defamb(lst, cc):
ifnotlst:
returnfail()
first, *rest=tuple(lst)
ifrest:
remaining_part_of_computation=ccstack.append(lambda: amb(rest, cc=remaining_part_of_computation))
returnfirstdeffail():
ifstack:
f=stack.pop()
returnf()
# Pythagorean triples using amb()defpt():
z=call_cc[amb(range(1, 21))] # capture continuation, auto-populate cc argy=call_cc[amb(range(1, z+1)))]
x=call_cc[amb(range(1, y+1))]
ifx*x+y*y!=z*z:
returnfail()
returnx, y, zt=pt()
whilet:
print(t)
t=fail() # note pt() has already returned when we call this.
Activity
Technologicat commentedon Oct 30, 2019
At least this snippet should go in:
Automatic TCO works also with lambdas, and analyzes the tail position from expressions. In a logical expression (even when nested) it's always the rightmost item, because short-circuiting depends on values, which are not available at macro expansion time.
Technologicat commentedon Nov 8, 2019
Technologicat commentedon Nov 8, 2019
Unpythonic in 30 seconds - Pure Python
Small, limited-space overview of the overall flavor. Click to expand examples.
Mathematical sequences. Slice syntax for general iterables.
Self-referring lambdas.
Memoizing generators.
Functional updates.
Slicable read-write list view.
Data flow focused function composition.
Technologicat commentedon Nov 8, 2019
Unpythonic in 30 seconds - Macros
Language-level extensions, with MacroPy. Click to expand examples.
Expression-local variables.
Definition-local variables, a.k.a. let-over-lambda for Python.
Imperative code as an expression, with local variables.
Automatic tail call optimization (TCO), with tail-position analysis also for expressions.
Automatic currying, à la Haskell.
Lazy functions, a.k.a. call-by-need.
Continuations (call/cc), also with automatic TCO.
Technologicat commentedon Nov 11, 2019
Now just include a doc link for each item, and merge this into the README...