GithubHelp home page GithubHelp logo

mlhoutel / compy Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 4.87 MB

transformations on python programs

Home Page: https://mlhoutel.github.io/compy/

License: Mozilla Public License 2.0

Rust 88.48% Python 11.52%
ast-transformations python

compy's People

Contributors

mlhoutel avatar

Stargazers

 avatar  avatar

Watchers

 avatar

compy's Issues

Variable update in loop

test_list = [12, 67, 98, 34]

res = []
for ele in test_list:
    sum = 0
    for digit in str(ele):
        sum += int(digit)
    res.append(sum) # <= here
 
print ("List Integer Summation : " + str(res))

Variable scoping issue for nested loops

for i in range(10):
    while True:
        print(i)
        break

is transformed to

[__INL__STATE := (None, 1), [[__INL__i := i, [__INL__TEMP := (lambda __INL__CORE, __INL__STATE, i, print: __INL__CORE(__INL__CORE, __INL__STATE, __INL__i, print))((lambda __INL__CORE, __INL__STATE, i, print: [__INL__i := __INL__i, __INL__print := print, __INL__COND := True, [__INL__print(__INL__i), __INL__STATE := (None, 2), __INL__CORE(__INL__CORE, __INL__STATE, __INL__i, __INL__print)][-1] if __INL__COND else (__INL__STATE, __INL__i, print)][-1]), __INL__STATE, __INL__i if 'i' in vars() else __builtins__.i if hasattr(__builtins__, 'i') else None, print if 'print' in vars() else __builtins__.print if hasattr(__builtins__, 'print') else None), __INL__STATE := __INL__TEMP[0], __INL__i := __INL__TEMP[1], print := __INL__TEMP[2]], [] if __INL__STATE[1] > 1 else None] for i in range(10)], [] if __INL__STATE[1] > 0 else None]

where there is an issue: UnboundLocalError: local variable '__INL__i' referenced before assignment

Broken state for while recursive lambda

As noticed in #6, the current state of the while statement for oneliner code is borken.

As for the precedent update to fix the flow statements in the while, for it to be correctly implemented, we must add an explicit declaration of the scoped state for the while.

For instance:

 ..., [__INL__STATE := (None, 2), __INL__TEMP := (...)], ...

Problem with flow expressions in recursive while

while True:
    if True:
        break

this function terminates, but onelined

[__INL__STATE := (None, 1), [__INL__TEMP := (lambda __INL__CORE, __INL__STATE: __INL__CORE(__INL__CORE, __INL__STATE))((lambda __INL__CORE, __INL__STATE: [__INL__COND := True, [[__INL__STATE := (None, 2)] if True else None, [] if __INL__STATE[1] > 1 else None, __INL__CORE(__INL__CORE, __INL__STATE)][-1] if __INL__COND else (__INL__STATE, None)][-1]), __INL__STATE), __INL__STATE := __INL__TEMP[0]], [] if __INL__STATE[1] > 0 else None]

This does not because the return only acts by the current rec scoping

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.