Running procs from a list of procs

2024-08-24 Thread stbalbach
Great! I'll probably use the closure method only because I have not upgraded Nim in a long time and my version doesn't support std/tasks (2022?). This works for now, if more verbose: type MyTask = proc () {.closure.} proc hello(a: int) = echo a proc other(s: string) = e

Running procs from a list of procs

2024-08-24 Thread Araq
Easy to do with `std / tasks`. For example: import std / tasks proc hello(a: int) = echo a proc other(s: string) = echo s let myTasks = @[toTask(hello 3), toTask(other "abc)] for t in myTasks: invoke(t) Run

Running procs from a list of procs

2024-08-24 Thread stbalbach
Thank you! You are correct, a few of my procs will need to pass a parameter. I tried something like this: import macros proc test1() = echo "Hello" proc test2(i: int) = echo "World " & $i for p in [test1, test2]: if astToStr(p) == "test2": p(42)

Running procs from a list of procs

2024-08-24 Thread cblake
This works: proc test1 = echo "Hello" proc test2 = echo "World" for p in [test1, test2]: p() Run Note the dropped optional ()s for an empty parameter list. Before you were trying to "call" a "string" which is.. not something most people would expect to work. E

Running procs from a list of procs

2024-08-24 Thread stbalbach
Is it possible to make a list of proc names then loop through the list and run those procs. Perplexity.ai gave this answer which works: import tables proc test1() = echo "Hello" proc test2() = echo "World" let procTable = { "test1": test1