metaprogramming - Is there a fast way of going from a symbol to a function call in Julia? -
this question has answer here:
- julia: invoke function given string 1 answer
i know can call functions using name follows
f = x -> println(x) y = :f eval(:($y("hi")))
but slow since using eval
possible in different way? know it's easy go other direction doing symbol(f)
.
what trying accomplish? needing eval symbol sounds solution in search of problem. in particular, can pass around original function, thereby avoiding issues needing track scope of f
(or, since f
ordinary variable in example, possibility reassigned), , fewer characters type:
f = x -> println(x) g = f g("hi")
i know it's easy go other direction doing
symbol(f)
.
this misleading, since it's not going give f
(that transform non-unique). instead gives string representation function (which might happen f
, sometimes). equivalent calling symbol(string(f))
, since combination common enough useful other purposes.