RemoteREPL.jl
RemoteREPL.jl copied to clipboard
Allow interpolation into @remote calls
Based on this thread, it is possible to process a macro to allow interpolating of values. My use case is that I want to define something like
function get_ADC(addr, bit)
@remote(pyconvert(Float32, DAQC2.getADC($addr, $bit)))
end
to make it feel like a pure julia function. If I do not interpolate, I get an error from addr and bit not being defined remotely, which makes sense. However, I can not interpolate the arguments into the call to @remote, due to a RemoteException:
ERROR: RemoteException:
ERROR: syntax: "$" expression outside quote
Stacktrace:
[1] top-level scope
@ none:1
[2] eval
@ ./boot.jl:360 [inlined]
Stacktrace:
[1] (::RemoteREPL.var"#47#48"{RemoteREPL.Connection, Expr})()
@ RemoteREPL ~/.julia/packages/RemoteREPL/BFqrB/src/client.jl:391
[2] ensure_connected!(f::RemoteREPL.var"#47#48"{RemoteREPL.Connection, Expr}, conn::RemoteREPL.Connection; retries::Int64)
@ RemoteREPL ~/.julia/packages/RemoteREPL/BFqrB/src/client.jl:178
[3] ensure_connected!
@ ~/.julia/packages/RemoteREPL/BFqrB/src/client.jl:174 [inlined]
[4] remote_eval_and_fetch
@ ~/.julia/packages/RemoteREPL/BFqrB/src/client.jl:380 [inlined]
[5] get_ADC(addr::Int64, bit::Int64)
@ Main ~/Uni/Semester/8. Sem/Independent Study Activity/scripts/test.jl:24
[6] top-level scope
@ ~/Uni/Semester/8. Sem/Independent Study Activity/scripts/test.jl:26
The fix would perhaps be to do something like benchmark-tools, as seen in the linked post, to allow interpolation?
It looks like I can wrap this into an @eval call, and correctly interpolate into that, as a workaround. The following definition works:
function get_ADC(addr, bit)
@eval @remote(pyconvert(Float32, DAQC2.getADC($addr, $bit)))
end
We should definitely do this. I'm surprised I didn't do it already! (If I recall, I did this exact thing in the SQLStrings/SQLREPL packages.)
We should definitely do this.
Do you know the appropriate way to do this? I am very inexperienced around macros.
I know how to do it, I just don't have that much time :sweat_smile:
We should try something like
- After parsing the expression, search it recursively for
Expr(:$, ex)expressions - call
eval(ex)for each of these - replace the
Expr(:$, ex)part of the expression with the result of theeval - Serialize the resulting expression and send it down the pipe to the other end
Sounds good. I am also pressed for time, but I think it is perfectly fine to keep this issue open as a FR. Perhaps adding a temporary paragraph in the docs about the workaround I found, in case this issue remains open for months/years?