From ebc23437292e25dd11b30d8d5dc868050ee4676a Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 17 Feb 2021 17:14:02 -0800 Subject: [PATCH] rename to SomeSparseEnum etc --- changelog.md | 4 ++-- lib/pure/typetraits.nim | 14 +++++++------- lib/std/enumutils.nim | 5 +++-- lib/system/iterators.nim | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index dee7520a79ea0..82968ae96b619 100644 --- a/changelog.md +++ b/changelog.md @@ -43,9 +43,9 @@ - Added `enumutils.genEnumCaseStmt` macro that generates case statement to parse string to enum. -- Added `enumutils.items` for enums with holes +- Added `enumutils.items` for sparse enums. -- Added `typetraits.SomeHolyEnum` for enums with holes +- Added `typetraits.SomeSparseEnum` for sparse enums. - Removed deprecated `iup` module from stdlib, it has already moved to [nimble](https://github.com/nim-lang/iup). diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim index c549a949063c4..250b15855a277 100644 --- a/lib/pure/typetraits.nim +++ b/lib/pure/typetraits.nim @@ -15,24 +15,24 @@ import std/private/since export system.`$` # for backward compatibility -type SomeHolyEnum* = concept x ## Type class for enum's with holes. +type SomeSparseEnum* = concept x ## Type class for enum's with holes. x is enum and x isnot Ordinal #[ xxx `runnableExamples` isn't run if inside: -type SomeHolyEnum* = concept x +type Foo* = concept x runnableExamples: assert false - x is enum and x isnot Ordinal + x is int ]# runnableExamples: type A = enum a0 = 2, a1 = 4, a2 type B = enum b0 = 2, b1, b2 - assert A is SomeHolyEnum - assert B isnot SomeHolyEnum - assert int isnot SomeHolyEnum + assert A is SomeSparseEnum + assert B isnot SomeSparseEnum + assert int isnot SomeSparseEnum type C[T] = enum h0 = 2, h1 = 4 - assert C[float] is SomeHolyEnum + assert C[float] is SomeSparseEnum proc name*(t: typedesc): string {.magic: "TypeTrait".} = ## Returns the name of the given type. diff --git a/lib/std/enumutils.nim b/lib/std/enumutils.nim index 3ba6c1ee106dd..f5b963fca2e92 100644 --- a/lib/std/enumutils.nim +++ b/lib/std/enumutils.nim @@ -63,13 +63,14 @@ macro genEnumCaseStmt*(typ: typedesc, argSym: typed, default: typed, expectKind(default, nnkSym) result.add nnkElse.newTree(default) -macro holyEnumFullRange(a: typed): untyped = result = newNimNode(nnkCurly).add(a.getType[1][1..^1]) +macro sparseEnumFullRange(a: typed): untyped = result = newNimNode(nnkCurly).add(a.getType[1][1..^1]) iterator items*[T: enum and not Ordinal](E: typedesc[T]): T = + ## iterates over a sparse enum runnableExamples: type A = enum a0 = 2, a1 = 4, a2 type B[T] = enum b0 = 2, b1 = 4 from sequtils import toSeq assert A.toSeq == [a0, a1, a2] assert B[float].toSeq == [B[float].b0, B[float].b1] - for a in holyEnumFullRange(E): yield a + for a in sparseEnumFullRange(E): yield a diff --git a/lib/system/iterators.nim b/lib/system/iterators.nim index 7f0076a444652..58a1fdb5cd7e2 100644 --- a/lib/system/iterators.nim +++ b/lib/system/iterators.nim @@ -84,7 +84,7 @@ iterator mitems*(a: var cstring): var char {.inline.} = iterator items*[T: enum and Ordinal](E: typedesc[T]): T = ## Iterates over the values of `E`. - ## See also `enumutils.items` for enums with holes. + ## See also `enumutils.items` for sparse enums. runnableExamples: type Goo = enum g0 = 2, g1, g2 from std/sequtils import toSeq