Aha, interesting! I think that might work, let me see if it actually works
in my real case... Fyi, in Julia it might look like this:
julia> function f(x)
eval(:(x->x+1))(x)
end
f (generic function with 1 method)
julia> f(3)
4
Coincidentally as I've been digging I think that's the same solution
suggested
here https://github.com/JuliaLang/julia/issues/2386#issuecomment-13966397
Marius
On Tuesday, September 27, 2016 at 2:36:48 PM UTC+2, Jussi Piitulainen wrote:
>
> You might be able to wrap your expression so as to create a function
> instead, and call the function with the values of the variables that the
> actual expression depends on. In Python, because I haven't learned to
> construct expressions in Julia yet and don't have the time to learn it now:
>
> def f(x): return eval("lambda x: x + 1")(x)
>
>
>
> tiistai 27. syyskuuta 2016 12.28.40 UTC+3 Marius Millea kirjoitti:
>>
>> Hi, is there a way to "eval" something in the current scope? My problem
>> is the following, I've written a macro that, inside the returned
>> expression, builds an expression which I need to eval. It looks like this,
>>
>> macro foo()
>> quote
>> ex = ...
>> eval_in_current_scope(ex)
>> end
>> end
>>
>> Now, you might say I'm using macros wrong and I should just be doing,
>>
>> macro foo()
>> ex = ...
>> end
>>
>>
>> but in this case when I build "ex", it needs to occur at runtime since it
>> depends on some things only available then. So is there any way to go about
>> this? Thanks.
>>
>>