mlhoutel / compy Goto Github PK
View Code? Open in Web Editor NEWtransformations on python programs
Home Page: https://mlhoutel.github.io/compy/
License: Mozilla Public License 2.0
transformations on python programs
Home Page: https://mlhoutel.github.io/compy/
License: Mozilla Public License 2.0
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))
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
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 := (...)], ...
For instance,
[:]
will not work
f'''
{code['co_cellvars']}
'''
willm be onelined to
[__INL__STATE := (None, 1), f'\n{code[co_cellvars]}\n']
but code[co_cellvars]
should be code['co_cellvars']
Find a way to implement it for functions traduced to lambdas
For instance,
f"La circonférence d'un cercle de rayon {rayon} est {circonference(rayon)}"
will trigger an error
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
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.