@@ -46,7 +46,7 @@ Get a value `val` from a remote `worker`; quoting of `val` works just as with
4646`save_at`. Returns a future with the requested value.
4747"""
4848function get_from (worker, val; mod = Main)
49- remotecall (() -> Base. eval (mod, :( $ val) ), worker)
49+ remotecall (() -> Base. eval (mod, val), worker)
5050end
5151
5252"""
@@ -358,3 +358,41 @@ Decorate the symbol from `dInfo` with prefix and suffix.
358358function tmp_symbol (dInfo:: Dinfo ; prefix = " " , suffix = " _tmp" )
359359 return tmp_symbol (dInfo. val, prefix = prefix, suffix = suffix)
360360end
361+
362+ """
363+ @remote module expr
364+
365+ A version of [`@remote`](@ref) that adds additional choice of the module for
366+ scope.
367+ """
368+ macro remote (mod, x)
369+ :(Base. eval ($ mod, $ (QuoteNode (x))))
370+ end
371+
372+ """
373+ @remote expr
374+
375+ In a function that will get evaluated on a remote worker, this ensures the
376+ evaluation scope of the expression `expr` (usually a variable) is taken on
377+ the remote side, preventing namespace clash with the local session.
378+
379+ This is mainly useful for making the functions from `Distributed` package (such
380+ as `pmap` and `remotecall`) work with the data stored by `DistributedData`
381+ package.
382+
383+ Internally, this is handled by wrapping in `eval`.
384+
385+ # Example
386+ ```
387+ julia> save_at(2, :x, 321)
388+ Future(2, 1, 162, nothing)
389+
390+ julia> let x=123
391+ remotecall_fetch(() -> x + (@remote x), 2)
392+ end
393+ 444
394+ ```
395+ """
396+ macro remote (x)
397+ :(@remote Main $ x)
398+ end
0 commit comments