(1) Hi all, I'm just starting out with Nim and - coming from Python - the recommended unqualified importing trips me up. I wonder how can I quickly see where a symbol comes from when I have a few imports in my file. Consider:
import math
import nimdata
echo DF.fromRange(0, 10).collect()
Where does DF comes from? (I know it's defined in nimdata, but the unqualified imports don't tell me...) I'm using Emacs with nim-mode, however I couldn't figure out how nim-mode can tell me where DF comes from.
(2) So I though the best would be qualified imports. I tried
from nimdata import nil
echo nimdata.DF.fromRange(0, 10).collect()
or
echo nimdata.DF.nimdata.fromRange(0, 10).nimdata.collect()
I got in trouble with both versions: The proc fromRange needs to be qualified but cannot be qualifeid as a proc of DF... (I understand that procs in Nim are much looser coupled to an instance then methods in Python).
So I'm a bit at a loss... I'm sure these are typical beginner's troubles and they'll evaporated with more experience, but at the moment I can't see how...
hello, you cannot use UFCS with qualified imports which is why it is not recommended
echo nimdata.collect(nimdata.fromRange(nimdata.DF, 0, 10))
I'm using Emacs with nim-mode, however I couldn't figure out how nim-mode can tell me where DF comes from.
That's a tooling issue (likely nimsuggest related). Contrary to Python, the type system has all the info on the available symbols so we need the tools to expose it.
I.e. declaring types/static typing is a cost when defining a proc but it should also allow you to write less code on use (like ensuring proper typing or finding the importing module). Unfortunately we are still not there yet on tooling sorry :/.
import macros
macro findSym(thing: typed) = echo(thing.getType.lineInfo)
findSym:
echo
:)
According to the nim-mode github page: https://github.com/nim-lang/nim-mode
jump-to-definition (M-., and M-, keys)
find-references (M-? key)
So try one of those bindings?
Hey @aEverr, thanks for this. Super cool.
I was not aware how general in Nim the loose coupling of functions and objects/variables is - and that it is called Uniform Function Call Syntax.