Given: abstract ABSGene type NuGene <: Genetic.ABSGene fqnn::ANN dcqnn::ANN score::Float32 end
function mutate_copy{T<:ABSGene}(gene::T) all_fields_except_score = filter(x->x != :score, names(T)) all_fields_except_score = map(x->("mutate_copy(*gene* .$x)"),all_fields_except_score) eval(parse("$(T)("*join(all_fields_except_score,",")*")")) end ng = NuGene() mutated_ng = mutate_copy(ng) results in: ERROR: gene not defined in mutate_copy at none:4 If I just look at it as a string (prior to running parse and eval) it looks fine: "NuGene(mutate_copy(gene.fqnn),mutate_copy(gene.dcqnn))" However, eval doesn't seem to know about gene that has been passed into the mutate_copy function. How do I access the gene argument that's been passed into the mutate copy? I tried this: function mutate_copy{T<:ABSGene}(gene::T) all_fields_except_score = filter(x->x != :score, names(T)) all_fields_except_score = map(x->("mutate_copy(*$gene* .$x)"),all_fields_except_score) #eval(parse("$(T)("*join(all_fields_except_score,",")*")")) (("$(T)("*join(all_fields_except_score,",")*")")) end But that expands the gene in the string which is not what I want.