sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

List comprehension fails with conditions (variable namespace issue) #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Code:
e = [ 0, 2, 4, 6 ]
r = [ 0, 1, 2, 3, 4, 5 ]

def cond(i, e):
    return i in e

x = [ i for i in r if cond(i, e) ]

Last lines are expanded as:
function cond(){
    document.$func_info=["__main__","cond"] 
    try{
        $ns=$MakeArgs("cond",arguments,['i','e'],{},null,null) 
        for($var in $ns){eval("var "+$var+"=$ns[$var]")} 
        document.$line_info=[5,"__main__"] 
        return i.__in__(e)
    }catch(err0){$raise(err0.name,err0.message)} 
}
window.cond=cond
document.$line_info=[7,"__main__"] 
x =$list_comp([["i","r"]],"i","cond(i,e)",['r',r]) 

But console complains with:
ExecutionError: cond is not a function

Same issue if function is named 'expr', 'env'
suggesting some issue with the parameter names of $list_comp()
function $list_comp(loops,expr,cond,env){ ... }

Works fine with function named 'condsomething'...

Original issue reported on code.google.com by pedro.ro...@gmail.com on 5 Jan 2013 at 1:30

GoogleCodeExporter commented 9 years ago
Fixed in rev #340 : you were right about name conflicts

Original comment by pierre.q...@gmail.com on 6 Jan 2013 at 8:08