lindahua / Devectorize.jl

A Julia framework for delayed expression evaluation
MIT License
115 stars 17 forks source link

gensym temporaries clutter the main namespace #19

Open tshort opened 11 years ago

tshort commented 11 years ago

Here's an example. For @devec_transform (issue #18), I got around that using let, but I'm not sure if that'll work here.

julia> x = rand(5)
5-element Float64 Array:
 0.4517  
 0.61006 
 0.928799
 0.965169
 0.817203

julia> y = rand(5)
5-element Float64 Array:
 0.8758  
 0.598536
 0.653074
 0.730567
 0.824384

julia> @devec z = sqr(x) + y
5-element Float64 Array:
 1.07983 
 0.970709
 1.51574 
 1.66212 
 1.49221 

julia> whos()
##len#63                      Int64
##siz#61                      (Int64,)
##tmp#60                      5-element Float64 Array
##ty#62                       BitsKind
Base                          Module
Core                          Module
DataFrames                    Module
Devectorize                   Module
GZip                          Module
Main                          Module
OptionsMod                    Module
d1                            Dict{String,Any}
df                            DataFrame
n                             Int64
x                             5-element Float64 Array
y                             5-element Float64 Array
z                             5-element Float64 Array
lindahua commented 11 years ago

Thanks for pointing this out -- I will look into this later.

lindahua commented 11 years ago

Simply wrapping everything into a let block does not address this issue. For example,

@devec r = a + b

There is a statement that creates the result r. If this is encapsulated into a let-block, the created variable will not be available in the calling scope.

So I may have to review the code-gen, and try to improve it to reduce the leaking of gensym variables.

At current point, try to encapsulate the use of @devec within functions, which may prevent those variables from leaking into main space.