Comments (7)
Yeah, I'm going to not do this. Not only can I not think of a way to implement it efficiently (since OverpassQL has no "break" concept), but I can't really think of a use case. I mean, it would need to be refactored to essentially:
unbroken = True
for item in set:
if unbroken:
body()
if not unbroken:
body2()
The problem there is that conditional blocks are very inefficient in the current implementation. So it would actually be more like:
unbroken = True
for item in set:
tmp = Antarctica
tmp = tmp if unbroken else Set()
for _ in tmp:
body()
tmp = Antarctica
tmp = tmp if not unbroken else Set()
for _ in tmp:
body2()
from overpassify.
And it gets even sillier, because you can't store numbers in variables, so the final implementation would need to look like:
unbroken = Antarctica()
for item in set:
tmp = Antarctica
tmp = unbroken if unbroken.count(deriveds=True) else Set()
for _ in tmp:
body()
tmp = unbroken if not unbroken.count(deriveds=True) else Set()
for _ in tmp:
body2()
from overpassify.
So, final verdict, this is deferred because:
It's easier to implement with a syntax transform, which I don't have the infrastructure for yet- I don't know of many use cases for this
- It would require a way to detect if for loops can break in the first place (otherwise less efficient)
from overpassify.
Okay, so this actually made me think about transforming stuff. It turns out it can reduce codebase in a few places. Specifically in conditional blocks anyways.
So I'm going to revive this despite of point (2).
from overpassify.
Oh man... So the syntax I highlighted above definitely won't work. Imagine the following code:
for item in set:
if item['name'] == 'Eiffel Tower':
out(item, geom=True, qt=True, body=True)
break
Seems fairly simple, except that OverpassQL doesn't support if. So we transform to:
for item in set:
tmpif12345r = Antarctica()
tmpif12345 = tmpif12345r if (item['name'] == 'Eiffel Tower') else Set()
for _ in tmpif12345:
out(item, geom=True, qt=True, body=True)
break # remember this is for the loop above
That's not too bad yet. Except we need to have some condition which tracks if break
has been called yet. And since we just discussed it not supporting if, I'll skip an intermediate transform for you.
tmpbreak12345 = Antarctica()
for item in set:
for _ in tmpbreak12345:
tmpif12345r = Antarctica()
for _ in tmpbreak12345:
tmpif12345 = tmpif12345r if (item['name'] == 'Eiffel Tower') else Set()
for _ in tmpbreak12345:
for _ in tmpif12345:
for _ in tmpbreak12345:
out(item, geom=True, qt=True, body=True)
for _ in tmpbreak12345:
tmpbreak12345 = Way.filter(tmpbreak12345) # clears the set
That is going to be horribly inefficient.
from overpassify.
And keep in mind that continue
would need a similar workaround.
An optimization would be to scan through the for loop before transforming it, to see if there's a break statement (not already part of a for loop) anywhere below it.
from overpassify.
In that case, these transforms would probably happen in a different order. So it would look more like:
for item in set:
if item['name'] == 'Eiffel Tower':
out(item, geom=True, qt=True, body=True)
break
to:
tmpbreak12345 = Antarctica()
for item in set
for _ in tmpbreak12345:
if item['name'] == 'Eiffel Tower':
for _ in tmpbreak12345:
out(item, geom=True, qt=True, body=True)
for _ in tmpbreak12345:
tmpbreak12345 = Way.filter(tmpbreak12345) # clears the set
to:
tmpbreak12345 = Antarctica()
for item in set
for _ in tmpbreak12345:
tmpif12345r = Antarctica()
tmpif12345 = tmpif12345r if (item['name'] == 'Eiffel Tower') else Set()
for _ in tmpif12345:
for _ in tmpbreak12345:
out(item, geom=True, qt=True, body=True)
for _ in tmpbreak12345:
tmpbreak12345 = Way.filter(tmpbreak12345) # clears the set
This is slightly more efficient. But all of this still rests upon the untested assumption that OverpassQL will let you change a set you're iterating over.
from overpassify.
Related Issues (20)
- Add TMP_PREFIX constant
- Cannot use nested constructors
- Support OverpassQL's "recurse" features
- Provide a settings function
- Long Term: Restructure to store everything in temporary variables HOT 4
- Transform only works on the top layer
- Support tag lookups
- Find a more efficient way to do conditional filtering HOT 1
- Long term: Support user-defined functions HOT 1
- If statements are now broken HOT 8
- Support while blocks
- Might be able to store custom objects using `make`
- If statement HOT 9
- Add file to describe object model
- Ensure that typing concepts match up HOT 1
- Can't filter by keys like maxspeed:advisory HOT 1
- Does not support key regex HOT 1
- Serialize to new ternery operator
- Add support for ternerys HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from overpassify.