Is it possible to enumerate the procs exported from a library, and has anyone got some example code of anything similar to this?
I have a template/macro that hoists math functions to apply them to seq[seq[]], and was wanting to do this generically for the exported math procs, rather than as hard-wired calls for each exported proc.
If you write the module yourself, the simplest way would be:
macro myMacro(body: typed): typed =
# do things here
#
# do not forget to add the original procs to the output!
myMacro:
proc proc1*() = discard
proc proc2*() = discard
# ...
@Andrea, I was asking, to see if there was a way of avoiding manual enumeration of proc names, like at the bottom of your example.
If a new proc is added to the math lib, then you manually have to add it to your lib :-(
makeUniversal(sqrt)
makeUniversal(cbrt)
makeUniversal(log10)
makeUniversal(log2)
makeUniversal(log)
makeUniversal(exp)
makeUniversal(arccos)
makeUniversal(arcsin)
makeUniversal(arctan)
makeUniversal(cos)
makeUniversal(cosh)
makeUniversal(sin)
makeUniversal(sinh)
makeUniversal(tan)
makeUniversal(tanh)
makeUniversal(erf)
makeUniversal(erfc)
makeUniversal(lgamma)
makeUniversal(tgamma)
makeUniversal(trunc)
makeUniversal(floor)
makeUniversal(ceil)
makeUniversal(degToRad)
makeUniversal(radToDeg)
Ok, I will fess up.
I was really thinking that collections like linked lists, queues, rings, ....
where it would be nice if there was a lib you could import, which hoisted lib procs (applied by iteration thru each element),
something like
import queues, math
import hoisting
hoistLibProcs("queues", "math") # <- this would make procs from math work with queues
var q: Queue
#
# do setup of queue data here
#
let sq = q.sqrt() # this would take the sqrt() for each element of q (because sqrt() has been hoisted)
Advantages:
It appears that only the sets module has a map function.
Sounds like a good improvement to the other collection types :-)
Of course, converting to a seq[] first means the normal map() can be used.