internetimagery / do-not Goto Github PK
View Code? Open in Web Editor NEWMonaic do notation with python for comprehensions
License: MIT License
Monaic do notation with python for comprehensions
License: MIT License
do(
v1 + v2
for v1 in Just(10)
if (v2 := v1 + 10) # This assignment works in regular list expressions but if it resides within the "guard" function, which only returns a boolean. How shold this value be propagated?
)
Currently this will not work as the variable is created within the scope of the filter function. Which itself only returns a boolean.
Certainly it could be rearranged.
do(
v1 + v2
for v1 in Just(10)
for v2 in Just(v1 + 10)
if v2
)
But I"m sure there are some more useful examples than this toy one, that are only expressible in this form.
One small edge case remains unsolved.
v2 = 123
do(
v1+v2
for v1 in Just(123)
for v2 in Just(v2)
)
When an outside variable is shadowed, treated as a nonlocal. It is not included in the closure as is standard. So when this is converted into a function, this variable is long out of scope. Thankfully the error message is helpful so it's not the end of the world (and this is poor coding design). But it would be good to have this fixed if a way can be found.
One inconsistency is that the first expression will always be fine, since it's evaluated before any adjustments are made.
v1 = 123
do(
v1
for v1 in Just(v1) # Fine, as it's in the first expression...
)
Note that this also works as the variable is non-shadowed:
v3 = 123
do(
v1+v2
for v1 in Just(123)
for v2 in Just(v3)
)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.