is there some way to forward declare a proc, then define it's body in another file that imports it? the current method i am using seems clunky and inelegant as it produces errors until compile time.
# greet.nim
proc greeting(name: string)
when not declared(greeting):
proc greeting(name: string) =
echo "hello " & name & "!"
greeting("forum")
# example.nim
include greet
proc greeting(name: string) =
echo "こんにちは " & name & "!"
I don't know if this is applicable to your use case, but it's what i thought of
# greet1.nim
proc greeting(name: string) =
echo "hello ", name, "!"
template greet*() =
mixin greeting
greeting("forum")
when isMainModule:
greet()
# greet2.nim
import greet1
proc greeting(name: string) =
echo "こんにちは ", name, "!"
when isMainModule:
greet()
# greet_a.nim
# Note the export.
proc greeting*(name: string)
proc greeting(name: string) =
echo "hello ", name, "!"
when isMainModule:
greeting("forum")
# greet_b.nim
import greet_a
# Comment this out to use *greetings* from greet_a.nim
proc greeting(name: string) =
echo "こんにちは ", name, "!"
when isMainModule:
greeting("forum")
greet_b.nim will use the 'default implementation' of greeting from greet_a.nim when no specialized version is defined in greet_b.nim itself. Is that what you wanted?