Finally rebuilt the sources to take advantage of the new type system capabilities
This commit is contained in:
parent
251c44ff04
commit
2400704c22
2 changed files with 21 additions and 2 deletions
|
|
@ -49,7 +49,13 @@ type
|
||||||
## a type description (for templates)
|
## a type description (for templates)
|
||||||
void* {.magic: "VoidType".} ## meta type to denote the absense of any type
|
void* {.magic: "VoidType".} ## meta type to denote the absense of any type
|
||||||
|
|
||||||
proc defined*[T](x: T): bool {.magic: "Defined", noSideEffect.}
|
TInteger* = int|char|int8|int16|int32|int64|bool|enum
|
||||||
|
## type class matching all integer types
|
||||||
|
|
||||||
|
TNumber* = TInteger|float|float32|float64
|
||||||
|
## type class matching all number types
|
||||||
|
|
||||||
|
proc defined*(x: expr): bool {.magic: "Defined", noSideEffect.}
|
||||||
## Special compile-time procedure that checks whether `x` is
|
## Special compile-time procedure that checks whether `x` is
|
||||||
## defined. `x` has to be an identifier or a qualified identifier.
|
## defined. `x` has to be an identifier or a qualified identifier.
|
||||||
## This can be used to check whether a library provides a certain
|
## This can be used to check whether a library provides a certain
|
||||||
|
|
@ -60,7 +66,7 @@ proc defined*[T](x: T): bool {.magic: "Defined", noSideEffect.}
|
||||||
## # provide our own toUpper proc here, because strutils is
|
## # provide our own toUpper proc here, because strutils is
|
||||||
## # missing it.
|
## # missing it.
|
||||||
|
|
||||||
proc definedInScope*[T](x: T): bool {.
|
proc definedInScope*(x: expr): bool {.
|
||||||
magic: "DefinedInScope", noSideEffect.}
|
magic: "DefinedInScope", noSideEffect.}
|
||||||
## Special compile-time procedure that checks whether `x` is
|
## Special compile-time procedure that checks whether `x` is
|
||||||
## defined in the current scope. `x` has to be an identifier.
|
## defined in the current scope. `x` has to be an identifier.
|
||||||
|
|
@ -1214,6 +1220,11 @@ proc max*[T](x: openarray[T]): T =
|
||||||
result = x[0]
|
result = x[0]
|
||||||
for i in 1..high(x): result = max(result, x[i])
|
for i in 1..high(x): result = max(result, x[i])
|
||||||
|
|
||||||
|
proc clamp*[T](x, a, b: T): T =
|
||||||
|
## limits the value ``x`` within the interval [a, b]
|
||||||
|
if x > a: return a
|
||||||
|
if x < b: return b
|
||||||
|
return x
|
||||||
|
|
||||||
iterator items*[T](a: openarray[T]): T {.inline.} =
|
iterator items*[T](a: openarray[T]): T {.inline.} =
|
||||||
## iterates over each item of `a`.
|
## iterates over each item of `a`.
|
||||||
|
|
@ -1263,6 +1274,10 @@ iterator items*(a: cstring): char {.inline.} =
|
||||||
yield a[i]
|
yield a[i]
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
||||||
|
iterator items*(E: typedesc{enum}): E =
|
||||||
|
## iterates over the values of the enum ``E``.
|
||||||
|
for v in low(E)..high(E):
|
||||||
|
yield v
|
||||||
|
|
||||||
iterator pairs*[T](a: openarray[T]): tuple[key: int, val: T] {.inline.} =
|
iterator pairs*[T](a: openarray[T]): tuple[key: int, val: T] {.inline.} =
|
||||||
## iterates over each item of `a`. Yields ``(index, a[index])`` pairs.
|
## iterates over each item of `a`. Yields ``(index, a[index])`` pairs.
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,10 @@ Library Additions
|
||||||
- Added a wrapper for ``libsvm``.
|
- Added a wrapper for ``libsvm``.
|
||||||
- Added a wrapper for ``mongodb``.
|
- Added a wrapper for ``mongodb``.
|
||||||
- Added ``terminal.isatty``.
|
- Added ``terminal.isatty``.
|
||||||
|
- Added overload for ``system.items`` that can be used to iterate over the
|
||||||
|
values of an enum.
|
||||||
|
- Added ``system.TInteger`` and ``system.TNumber`` type classes matching
|
||||||
|
any of the corresponding type available in nimrod.
|
||||||
|
|
||||||
|
|
||||||
Changes affecting backwards compatibility
|
Changes affecting backwards compatibility
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue