timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

RFC: `import std/stdimports`, replaces `include prelude` #388

Open timotheecour opened 4 years ago

timotheecour commented 4 years ago

refs https://github.com/nim-lang/Nim/pull/16135#discussion_r530644051

benefits

# in std/stdimports
template importCommonJs* =
  import jsconsole, ...
template importCommonCollections* =
  import tables, sets, hashes, ...
template importCommonMath* =
  import sums, sets, ...
template importCommonWerbServer =
  import ...
template importCommonRepl* = # can call above
  importCommonCollections()
  importCommonMath()

## usage
# client.nim
import std/stdimports
importCommonCollections()

doesn't need a hierarchy, ie you can have overlapping categories as shown above

[1] docs can be autogenerated instead of duplicating the content (not DRY) as done in https://github.com/nim-lang/Nim/pull/16135:

# in std/stdimports
import macros
template genDocCommentAndBody(body): untyped = ...

genDocCommentAndBody:
  template importCommonJs* =
    import jsconsole, ...
juancarlospaco commented 3 years ago
import macros, strutils

const nimPrelude {.strdefine.} = "os,strutils,times,parseutils,hashes,tables,sets"

macro makeAnImport(modules: static[string])=
  result = newStmtList()
  for module in modules.split ',':
    result.add quote do:
      import `module`

makeAnImport(nimPrelude)

expandMacros:
  makeAnImport(nimPrelude)