Seems like you're on a hiding to nothing. I had these imports, for a short,
simple script:
import nre
import options
import streams
import strfmt
import strutils
import tables
To see if I could avoid implicit importing, I tried changing the imports to:
from nre import re, match, RegexMatch, captures, `[]`
from options import isSome, get
from streams import Stream, readAll, newFileStream
# from strfmt import fmt, ftStr, faDefault, fsMinus, addformat, format
from strutils import splitLines, `%`
from tables import OrderedTableRef, newOrderedTable, contains, `[]=`, `$`
And I still can't get it to compile using `strfmt`, because of the cryptic
compilation error when I uncomment the above `strfmt` import and the line that
uses it, which is just
echo "{0:-12s} {1:s}".fmt(sectname, line)
The cryptic nature of the compilation error message, it seems, may be because
of the use of macros in `strfmt`. The message is:
Error: type mismatch: got (string, string, tuple[typ: FmtType, precision:
int, width: int, fill: nil, align: FmtAlign, sign: FmtSign, baseprefix: bool,
upcase: bool, comma: bool, arysep: nil])
but expected one of:
proc addformat[T](o: var Writer; x: T; fmt: Format = DefaultFmt)
proc addformat[T](o: var Writer; x: T; fmt: string)
proc addformat(s: var string; x: string)
proc addformat(f: File; x: string)
proc addformat[T](f: File; x: T; fmt: Format = DefaultFmt)
proc addformat[T](f: File; x: T; fmt: string)
proc addformat(s: Stream; x: string)
proc addformat[T](s: Stream; x: T; fmt: Format = DefaultFmt)
proc addformat[T](s: Stream; x: T; fmt: string)
I tried updating the import statement to include as many of the types mentioned
in the message:
from strfmt import fmt, ftStr, faDefault, fsMinus, addformat, format,
FmtAlign, FmtSign, FmtType, Format, Writer, DefaultFmt
But the error message remains the same, and is located at the start of
`"{0:-12s} {1:s}".fmt(sectname, line)` which is passed to `echo`.
Note also the need to import lots of operators - this is pretty much a
trial-and-error exercise. I don't think that explicit imports will work for
operators, but without them you will get lots more cryptic messages. Earlier,
before I imported [] from `nre`, I got
Error: type mismatch: got (Captures, string)
but expected one of:
proc `[]`[Idx, T](a: array[Idx, T]; x: Slice[Idx]): seq[T]
proc `[]`(s: string; x: Slice[int]): string
proc `[]`[T](s: seq[T]; x: Slice[int]): seq[T]
proc `[]`[I: Ordinal, T](a: T; i: I): T
proc `[]`[Idx, T](a: array[Idx, T]; x: Slice[int]): seq[T]
and got a clue from that message that I should import [] from `nre`. But
despite now importing `addformat` from `strfmt`, the compilation error remains,
with no obvious answer as to how to remove it.
I think the way Nim does operators means either that import statements are
going to get ugly - with operator imports in the import statements - or code
will get ugly - because operators will need qualifying _in situ_ \- or else you
have to live with implicit imports as they are now, though it definitely hurts
code readability in the wider sense when compared to, say, Python.