document since (#17048)

* document `since`
* address comment
This commit is contained in:
Timothee Cour 2021-02-16 11:20:01 -08:00 • committed by GitHub
commit b187caeb87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View file

@ -1,3 +1,17 @@
##[
`since` is used to emulate older versions of nim stdlib with `--useVersion`,
see `tuse_version.nim`.
If a symbol `foo` is added in version `(1,3,5)`, use `{.since: (1.3.5).}`, not
`{.since: (1.4).}`, so that it works in devel in between releases.
The emulation cannot be 100% faithful and to avoid adding too much complexity,
`since` is not needed in those cases:
* if a new module is added
* if an overload is added
* if an extra parameter to an existing routine is added
]##
template since*(version: (int, int), body: untyped) {.dirty.} =
## Evaluates `body` if the ``(NimMajor, NimMinor)`` is greater than
## or equal to `version`. Usage:
@ -16,4 +30,4 @@ template since*(version: (int, int, int), body: untyped) {.dirty.} =
## proc fun*() {.since: (1, 3, 1).}
## since (1, 3, 1): fun()
when (NimMajor, NimMinor, NimPatch) >= version:
body
body