Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow interpolation into @remote calls #53

Open
KronosTheLate opened this issue Jun 19, 2023 · 5 comments
Open

Allow interpolation into @remote calls #53

KronosTheLate opened this issue Jun 19, 2023 · 5 comments

Comments

@KronosTheLate
Copy link
Contributor

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?

@KronosTheLate
Copy link
Contributor Author

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

@c42f
Copy link
Collaborator

c42f commented Jun 23, 2023

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.)

@KronosTheLate
Copy link
Contributor Author

We should definitely do this.

Do you know the appropriate way to do this? I am very inexperienced around macros.

@c42f
Copy link
Collaborator

c42f commented Jul 1, 2023

I know how to do it, I just don't have that much time 😅

We should try something like

  1. After parsing the expression, search it recursively for Expr(:$, ex) expressions
  2. call eval(ex) for each of these
  3. replace the Expr(:$, ex) part of the expression with the result of the eval
  4. Serialize the resulting expression and send it down the pipe to the other end

@KronosTheLate
Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants