Re: how to call a function by name?

2018-03-30 Thread r3d9u11
Thanks for clarification regarding Nim! (but, as I know, "reflection" is a conception relating only for runtime. everything else is something different)

Re: how to call a function by name?

2018-03-29 Thread mikra
Nim is statically typed so only compile-time reflection (see module typetraits for instance) is possible. Runtime reflection like in java is not possible (all metadata stripped away by the backend compiler)

Re: how to call a function by name?

2018-03-29 Thread r3d9u11
But is it possible in Nim to call procedure with parameters who name and parameters will be known at runtime (and get result value)? Does Nim support reflection?

Re: how to call a function by name?

2018-03-29 Thread mratsim
Oh yes of course, you can store the procs in a table. Though you might have issue with type-checking if they don't have the exact same arguments.

Re: how to call a function by name?

2018-03-29 Thread mashingan
@timothee, use `procvar` annotation if you have the proc defined proc echoa() {.procvar.} = echo "proca" proc echob() {.procvar.} = echo "procb" let echos = @[echoa, echob] for f in echos: f() You can use together with enum as matchin

Re: how to call a function by name?

2018-03-28 Thread mratsim
Here are 2 ways ## Sol 1 - if you can get by with identifier input proc fun1() = echo "ok1" proc fun2() = echo "ok2" template callfun(fun: untyped) = fun() ## Sol 2 - if you really need string input ## This also unrolls the loop import macr

how to call a function by name?

2018-03-28 Thread timothee
what would be the idiomatic way to write this D code in nim? it calls a function by name (provided at runtime), trying all possibilities until a match is found. import std.stdio:writeln; void fun1(){writeln("ok1");} void fun2(){writeln("ok2");} void callFun(string f