Imaging the following situation:
template b(body:untyped):untyped =
proc c() =
body
template a(body:untyped):untyped =
body
a:
b:
echo "Hello"
How can I check in a if b is ever called?
What I would like to do is to define function c as:
proc c() =
discard
when b is not defined in a. i might not be answering your question, because this isn't checking if b is called in a, but whether c exists yet, which is what i think you really want, otherwise e.g. a: proc c = discard would be a double definition error.
template a(body:untyped):untyped =
body
when not declared(c):
proc c = discard
if something like this could happen:
a:
proc c(x:int) = discard
c() #error
you could test for that case:
template a(body:untyped):untyped =
body
when not declared(c):
proc c = discard
else:
when not (typeof(c) is proc()):
proc c = discard
Thanks you all. I will follow this last aproach. Hopefully I won't need something more complex. But good to know my options.
Regards