I still like [my old proposal](https://forum.nim-lang.org/t/3061) for the use 
keyword (instead of from ... import nil). Then import means "import into 
namespace"; use means "use with a prefix".

Both can be used with the from, except, and as keywords:
    
    
    from mymodule import myproc  # put myproc() in global namespace
    from mymodule use myproc     # must use mymodule.myproc()
    
    use mymodule except mybadproc, myotherproc
    use mymodule as m
    
    from mymodule import myproc as mygoodproc
    
    
    
    Run

That last line proposes the ability to specify the name of identifier being 
imported.

Like I just said in [the dir thread](https://forum.nim-lang.org/t/4156), maybe 
Nim needs a stdlib module for compile-time module introspection (similar to 
what nimsuggest does externally).

You could then combine those two features, (dir and from mymodule [use|import] 
X as Y) to write whatever macros you want, like:
    
    
    import macros
    
    macro importWithPrefix*(moduleName, prefix: string): untyped =
      result = newStmtList()
      for id in dir($moduleName):
        let targetId = $prefix & id
        result.add parseStmt("from " & $moduleName & " import " & id & " as " & 
targetId)
    
    
    
    Run

(NOTE: just conceptual pseudocode here...)

Reply via email to