Obviously this is possible,
julia> function foo()
global foo2
foo2(x) = println(x)
foo2(2)
eval(parse("foo2(1)"))
end
foo (generic function with 1 method)
julia> foo()
2
1
but less desirable.
On Wednesday, July 2, 2014 1:23:11 AM UTC-4, Cameron Smith wrote:
>
> thanks. is there a function other than eval that would enable evaluation
> of a string or symbol to result in a call to a nested function?
>
> On Wednesday, July 2, 2014 1:17:07 AM UTC-4, John Myles White wrote:
>>
>> eval always happens in the global scope
>>
>> — John
>>
>> On Jul 1, 2014, at 10:15 PM, Cameron Smith <[email protected]> wrote:
>>
>> Can anyone explain what I am misunderstanding about scope such that
>>
>> julia> function foo()
>> foo2(x) = println(x)
>> foo2(1); eval(parse("foo2(2)"));
>> end
>> foo (generic function with 1 method)
>>
>>
>> julia> foo()
>> 1
>> ERROR: foo2 not defined
>> in foo at none:3
>>
>> is not the same as
>>
>> julia> function foo()
>> foo2(x) = println(x)
>> foo2(1); foo2(2);
>> end
>> foo (generic function with 1 method)
>>
>>
>> julia> foo()
>> 1
>> 2
>>
>> given, of course, that
>>
>> julia> foo2(x) = println(x)
>> foo2 (generic function with 1 method)
>>
>>
>> julia> eval(parse("foo2(1)"))
>> 1
>>
>>
>>