GithubHelp home page GithubHelp logo

Comments (7)

LivInTheLookingGlass avatar LivInTheLookingGlass commented on June 16, 2024

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.

LivInTheLookingGlass avatar LivInTheLookingGlass commented on June 16, 2024

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.

LivInTheLookingGlass avatar LivInTheLookingGlass commented on June 16, 2024

So, final verdict, this is deferred because:

  1. It's easier to implement with a syntax transform, which I don't have the infrastructure for yet
  2. I don't know of many use cases for this
  3. It would require a way to detect if for loops can break in the first place (otherwise less efficient)

from overpassify.

LivInTheLookingGlass avatar LivInTheLookingGlass commented on June 16, 2024

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.

LivInTheLookingGlass avatar LivInTheLookingGlass commented on June 16, 2024

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.

LivInTheLookingGlass avatar LivInTheLookingGlass commented on June 16, 2024

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.

LivInTheLookingGlass avatar LivInTheLookingGlass commented on June 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.