mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
remove deprecated procs (#12535)
This commit is contained in:
@@ -357,11 +357,13 @@ iterator items*(pattern: Captures,
|
||||
|
||||
proc toSeq*(pattern: CaptureBounds,
|
||||
default = none(HSlice[int, int])): seq[Option[HSlice[int, int]]] =
|
||||
accumulateResult(pattern.items(default))
|
||||
result = @[]
|
||||
for it in pattern.items(default): result.add it
|
||||
|
||||
proc toSeq*(pattern: Captures,
|
||||
default: Option[string] = none(string)): seq[Option[string]] =
|
||||
accumulateResult(pattern.items(default))
|
||||
result = @[]
|
||||
for it in pattern.items(default): result.add it
|
||||
|
||||
proc `$`*(pattern: RegexMatch): string =
|
||||
return pattern.captures[-1]
|
||||
|
||||
@@ -234,10 +234,6 @@ proc getBiggestInt*(n: JsonNode, default: BiggestInt = 0): BiggestInt =
|
||||
if n.isNil or n.kind != JInt: return default
|
||||
else: return n.num
|
||||
|
||||
proc getNum*(n: JsonNode, default: BiggestInt = 0): BiggestInt {.deprecated:
|
||||
"Deprecated since v0.18.2; use 'getInt' or 'getBiggestInt' instead".} =
|
||||
getBiggestInt(n, default)
|
||||
|
||||
proc getFloat*(n: JsonNode, default: float = 0.0): float =
|
||||
## Retrieves the float value of a `JFloat JsonNode`.
|
||||
##
|
||||
@@ -248,10 +244,6 @@ proc getFloat*(n: JsonNode, default: float = 0.0): float =
|
||||
of JInt: return float(n.num)
|
||||
else: return default
|
||||
|
||||
proc getFNum*(n: JsonNode, default: float = 0.0): float {.deprecated:
|
||||
"Deprecated since v0.18.2; use 'getFloat' instead".} =
|
||||
getFloat(n, default)
|
||||
|
||||
proc getBool*(n: JsonNode, default: bool = false): bool =
|
||||
## Retrieves the bool value of a `JBool JsonNode`.
|
||||
##
|
||||
@@ -259,10 +251,6 @@ proc getBool*(n: JsonNode, default: bool = false): bool =
|
||||
if n.isNil or n.kind != JBool: return default
|
||||
else: return n.bval
|
||||
|
||||
proc getBVal*(n: JsonNode, default: bool = false): bool {.deprecated:
|
||||
"Deprecated since v0.18.2; use 'getBool' instead".} =
|
||||
getBool(n, default)
|
||||
|
||||
proc getFields*(n: JsonNode,
|
||||
default = initOrderedTable[string, JsonNode](4)):
|
||||
OrderedTable[string, JsonNode] =
|
||||
@@ -502,10 +490,6 @@ proc contains*(node: JsonNode, val: JsonNode): bool =
|
||||
assert(node.kind == JArray)
|
||||
find(node.elems, val) >= 0
|
||||
|
||||
proc existsKey*(node: JsonNode, key: string): bool {.
|
||||
deprecated: "use 'hasKey' instead".} =
|
||||
node.hasKey(key)
|
||||
|
||||
proc `{}`*(node: JsonNode, keys: varargs[string]): JsonNode =
|
||||
## Traverses the node and gets the given value. If any of the
|
||||
## keys do not exist, returns ``nil``. Also returns ``nil`` if one of the
|
||||
|
||||
@@ -41,11 +41,6 @@
|
||||
## * `dynlib module <dynlib.html>`_
|
||||
## * `streams module <streams.html>`_
|
||||
|
||||
|
||||
{.deadCodeElim: on.} # dce option deprecated
|
||||
|
||||
{.push debugger: off.}
|
||||
|
||||
include "system/inclrtl"
|
||||
|
||||
import
|
||||
@@ -3131,8 +3126,6 @@ proc getCurrentProcessId*(): int {.noNimScript.} =
|
||||
else:
|
||||
result = getpid()
|
||||
|
||||
{.pop.}
|
||||
|
||||
proc setLastModificationTime*(file: string, t: times.Time) {.noNimScript.} =
|
||||
## Sets the `file`'s last modification time. `OSError` is raised in case of
|
||||
## an error.
|
||||
|
||||
@@ -1154,7 +1154,8 @@ proc findAll*(s: string, pattern: Peg, start = 0): seq[string] {.
|
||||
noSideEffect, rtl, extern: "npegs$1".} =
|
||||
## returns all matching *substrings* of `s` that match `pattern`.
|
||||
## If it does not match, @[] is returned.
|
||||
accumulateResult(findAll(s, pattern, start))
|
||||
result = @[]
|
||||
for it in findAll(s, pattern, start): result.add it
|
||||
|
||||
when not defined(nimhygiene):
|
||||
{.pragma: inject.}
|
||||
@@ -1372,7 +1373,8 @@ iterator split*(s: string, sep: Peg): string =
|
||||
proc split*(s: string, sep: Peg): seq[string] {.
|
||||
noSideEffect, rtl, extern: "npegs$1".} =
|
||||
## Splits the string `s` into substrings.
|
||||
accumulateResult(split(s, sep))
|
||||
result = @[]
|
||||
for it in split(s, sep): result.add it
|
||||
|
||||
# ------------------- scanner -------------------------------------------------
|
||||
|
||||
|
||||
@@ -80,21 +80,8 @@ when defined(nimVmExportFixed):
|
||||
from unicode import toLower, toUpper
|
||||
export toLower, toUpper
|
||||
|
||||
{.deadCodeElim: on.} # dce option deprecated
|
||||
|
||||
{.push debugger: off.} # the user does not want to trace a part
|
||||
# of the standard library!
|
||||
|
||||
include "system/inclrtl"
|
||||
|
||||
{.pop.}
|
||||
|
||||
# Support old split with set[char]
|
||||
when defined(nimOldSplit):
|
||||
{.pragma: deprecatedSplit, deprecated.}
|
||||
else:
|
||||
{.pragma: deprecatedSplit.}
|
||||
|
||||
const
|
||||
Whitespace* = {' ', '\t', '\v', '\r', '\l', '\f'}
|
||||
## All the characters that count as whitespace (space, tab, vertical tab,
|
||||
@@ -2863,110 +2850,6 @@ iterator tokenize*(s: string, seps: set[char] = Whitespace): tuple[
|
||||
break
|
||||
i = j
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Deprecated procs
|
||||
|
||||
{.push warning[Deprecated]: off.}
|
||||
proc editDistance*(a, b: string): int {.noSideEffect,
|
||||
rtl, extern: "nsuEditDistance",
|
||||
deprecated: "use editdistance.editDistanceAscii instead".} =
|
||||
## Returns the edit distance between `a` and `b`.
|
||||
##
|
||||
## This uses the `Levenshtein`:idx: distance algorithm with only a linear
|
||||
## memory overhead.
|
||||
var len1 = a.len
|
||||
var len2 = b.len
|
||||
if len1 > len2:
|
||||
# make `b` the longer string
|
||||
return editDistance(b, a)
|
||||
|
||||
# strip common prefix:
|
||||
var s = 0
|
||||
while s < len1 and a[s] == b[s]:
|
||||
inc(s)
|
||||
dec(len1)
|
||||
dec(len2)
|
||||
# strip common suffix:
|
||||
while len1 > 0 and len2 > 0 and a[s+len1-1] == b[s+len2-1]:
|
||||
dec(len1)
|
||||
dec(len2)
|
||||
# trivial cases:
|
||||
if len1 == 0: return len2
|
||||
if len2 == 0: return len1
|
||||
|
||||
# another special case:
|
||||
if len1 == 1:
|
||||
for j in s..s+len2-1:
|
||||
if a[s] == b[j]: return len2 - 1
|
||||
return len2
|
||||
|
||||
inc(len1)
|
||||
inc(len2)
|
||||
var half = len1 shr 1
|
||||
# initialize first row:
|
||||
#var row = cast[ptr array[0..high(int) div 8, int]](alloc(len2*sizeof(int)))
|
||||
var row: seq[int]
|
||||
newSeq(row, len2)
|
||||
var e = s + len2 - 1 # end marker
|
||||
for i in 1..len2 - half - 1: row[i] = i
|
||||
row[0] = len1 - half - 1
|
||||
for i in 1 .. len1 - 1:
|
||||
var char1 = a[i + s - 1]
|
||||
var char2p: int
|
||||
var diff, x: int
|
||||
var p: int
|
||||
if i >= len1 - half:
|
||||
# skip the upper triangle:
|
||||
var offset = i - len1 + half
|
||||
char2p = offset
|
||||
p = offset
|
||||
var c3 = row[p] + ord(char1 != b[s + char2p])
|
||||
inc(p)
|
||||
inc(char2p)
|
||||
x = row[p] + 1
|
||||
diff = x
|
||||
if x > c3: x = c3
|
||||
row[p] = x
|
||||
inc(p)
|
||||
else:
|
||||
p = 1
|
||||
char2p = 0
|
||||
diff = i
|
||||
x = i
|
||||
if i <= half + 1:
|
||||
# skip the lower triangle:
|
||||
e = len2 + i - half - 2
|
||||
# main:
|
||||
while p <= e:
|
||||
dec(diff)
|
||||
var c3 = diff + ord(char1 != b[char2p + s])
|
||||
inc(char2p)
|
||||
inc(x)
|
||||
if x > c3: x = c3
|
||||
diff = row[p] + 1
|
||||
if x > diff: x = diff
|
||||
row[p] = x
|
||||
inc(p)
|
||||
# lower triangle sentinel:
|
||||
if i <= half:
|
||||
dec(diff)
|
||||
var c3 = diff + ord(char1 != b[char2p + s])
|
||||
inc(x)
|
||||
if x > c3: x = c3
|
||||
row[p] = x
|
||||
result = row[e]
|
||||
{.pop.}
|
||||
|
||||
proc isNilOrEmpty*(s: string): bool {.noSideEffect, procvar, rtl,
|
||||
extern: "nsuIsNilOrEmpty",
|
||||
deprecated: "use 'x.len == 0' instead".} =
|
||||
## Checks if `s` is nil or empty.
|
||||
result = len(s) == 0
|
||||
|
||||
proc isNilOrWhitespace*(s: string): bool {.noSideEffect, procvar, rtl,
|
||||
extern: "nsuIsNilOrWhitespace".} =
|
||||
## Checks if `s` is nil or consists entirely of whitespace characters.
|
||||
@@ -2975,167 +2858,6 @@ proc isNilOrWhitespace*(s: string): bool {.noSideEffect, procvar, rtl,
|
||||
if not c.isSpaceAscii():
|
||||
return false
|
||||
|
||||
template isImpl(call) =
|
||||
if s.len == 0: return false
|
||||
result = true
|
||||
for c in s:
|
||||
if not call(c): return false
|
||||
|
||||
proc isAlphaAscii*(s: string): bool {.noSideEffect, procvar,
|
||||
rtl, extern: "nsuIsAlphaAsciiStr",
|
||||
deprecated: "Deprecated since version 0.20 since its semantics are unclear".} =
|
||||
## Checks whether or not `s` is alphabetical.
|
||||
##
|
||||
## This checks a-z, A-Z ASCII characters only.
|
||||
## Returns true if all characters in `s` are
|
||||
## alphabetic and there is at least one character
|
||||
## in `s`.
|
||||
## Use `Unicode module<unicode.html>`_ for UTF-8 support.
|
||||
runnableExamples:
|
||||
doAssert isAlphaAscii("fooBar") == true
|
||||
doAssert isAlphaAscii("fooBar1") == false
|
||||
doAssert isAlphaAscii("foo Bar") == false
|
||||
isImpl isAlphaAscii
|
||||
|
||||
proc isAlphaNumeric*(s: string): bool {.noSideEffect, procvar,
|
||||
rtl, extern: "nsuIsAlphaNumericStr",
|
||||
deprecated: "Deprecated since version 0.20 since its semantics are unclear".} =
|
||||
## Checks whether or not `s` is alphanumeric.
|
||||
##
|
||||
## This checks a-z, A-Z, 0-9 ASCII characters only.
|
||||
## Returns true if all characters in `s` are
|
||||
## alpanumeric and there is at least one character
|
||||
## in `s`.
|
||||
## Use `Unicode module<unicode.html>`_ for UTF-8 support.
|
||||
runnableExamples:
|
||||
doAssert isAlphaNumeric("fooBar") == true
|
||||
doAssert isAlphaNumeric("fooBar1") == true
|
||||
doAssert isAlphaNumeric("foo Bar") == false
|
||||
isImpl isAlphaNumeric
|
||||
|
||||
proc isDigit*(s: string): bool {.noSideEffect, procvar,
|
||||
rtl, extern: "nsuIsDigitStr",
|
||||
deprecated: "Deprecated since version 0.20 since its semantics are unclear".} =
|
||||
## Checks whether or not `s` is a numeric value.
|
||||
##
|
||||
## This checks 0-9 ASCII characters only.
|
||||
## Returns true if all characters in `s` are
|
||||
## numeric and there is at least one character
|
||||
## in `s`.
|
||||
runnableExamples:
|
||||
doAssert isDigit("1908") == true
|
||||
doAssert isDigit("fooBar1") == false
|
||||
isImpl isDigit
|
||||
|
||||
proc isSpaceAscii*(s: string): bool {.noSideEffect, procvar,
|
||||
rtl, extern: "nsuIsSpaceAsciiStr",
|
||||
deprecated: "Deprecated since version 0.20 since its semantics are unclear".} =
|
||||
## Checks whether or not `s` is completely whitespace.
|
||||
##
|
||||
## Returns true if all characters in `s` are whitespace
|
||||
## characters and there is at least one character in `s`.
|
||||
runnableExamples:
|
||||
doAssert isSpaceAscii(" ") == true
|
||||
doAssert isSpaceAscii("") == false
|
||||
isImpl isSpaceAscii
|
||||
|
||||
template isCaseImpl(s, charProc, skipNonAlpha) =
|
||||
var hasAtleastOneAlphaChar = false
|
||||
if s.len == 0: return false
|
||||
for c in s:
|
||||
if skipNonAlpha:
|
||||
var charIsAlpha = c.isAlphaAscii()
|
||||
if not hasAtleastOneAlphaChar:
|
||||
hasAtleastOneAlphaChar = charIsAlpha
|
||||
if charIsAlpha and (not charProc(c)):
|
||||
return false
|
||||
else:
|
||||
if not charProc(c):
|
||||
return false
|
||||
return if skipNonAlpha: hasAtleastOneAlphaChar else: true
|
||||
|
||||
proc isLowerAscii*(s: string, skipNonAlpha: bool): bool {.
|
||||
deprecated: "Deprecated since version 0.20 since its semantics are unclear".} =
|
||||
## Checks whether ``s`` is lower case.
|
||||
##
|
||||
## This checks ASCII characters only.
|
||||
##
|
||||
## If ``skipNonAlpha`` is true, returns true if all alphabetical
|
||||
## characters in ``s`` are lower case. Returns false if none of the
|
||||
## characters in ``s`` are alphabetical.
|
||||
##
|
||||
## If ``skipNonAlpha`` is false, returns true only if all characters
|
||||
## in ``s`` are alphabetical and lower case.
|
||||
##
|
||||
## For either value of ``skipNonAlpha``, returns false if ``s`` is
|
||||
## an empty string.
|
||||
## Use `Unicode module<unicode.html>`_ for UTF-8 support.
|
||||
runnableExamples:
|
||||
doAssert isLowerAscii("1foobar", false) == false
|
||||
doAssert isLowerAscii("1foobar", true) == true
|
||||
doAssert isLowerAscii("1fooBar", true) == false
|
||||
isCaseImpl(s, isLowerAscii, skipNonAlpha)
|
||||
|
||||
proc isUpperAscii*(s: string, skipNonAlpha: bool): bool {.
|
||||
deprecated: "Deprecated since version 0.20 since its semantics are unclear".} =
|
||||
## Checks whether ``s`` is upper case.
|
||||
##
|
||||
## This checks ASCII characters only.
|
||||
##
|
||||
## If ``skipNonAlpha`` is true, returns true if all alphabetical
|
||||
## characters in ``s`` are upper case. Returns false if none of the
|
||||
## characters in ``s`` are alphabetical.
|
||||
##
|
||||
## If ``skipNonAlpha`` is false, returns true only if all characters
|
||||
## in ``s`` are alphabetical and upper case.
|
||||
##
|
||||
## For either value of ``skipNonAlpha``, returns false if ``s`` is
|
||||
## an empty string.
|
||||
## Use `Unicode module<unicode.html>`_ for UTF-8 support.
|
||||
runnableExamples:
|
||||
doAssert isUpperAscii("1FOO", false) == false
|
||||
doAssert isUpperAscii("1FOO", true) == true
|
||||
doAssert isUpperAscii("1Foo", true) == false
|
||||
isCaseImpl(s, isUpperAscii, skipNonAlpha)
|
||||
|
||||
proc wordWrap*(s: string, maxLineWidth = 80,
|
||||
splitLongWords = true,
|
||||
seps: set[char] = Whitespace,
|
||||
newLine = "\n"): string {.
|
||||
noSideEffect, rtl, extern: "nsuWordWrap",
|
||||
deprecated: "use wrapWords in std/wordwrap instead".} =
|
||||
## Word wraps `s`.
|
||||
result = newStringOfCap(s.len + s.len shr 6)
|
||||
var spaceLeft = maxLineWidth
|
||||
var lastSep = ""
|
||||
for word, isSep in tokenize(s, seps):
|
||||
if isSep:
|
||||
lastSep = word
|
||||
spaceLeft = spaceLeft - len(word)
|
||||
continue
|
||||
if len(word) > spaceLeft:
|
||||
if splitLongWords and len(word) > maxLineWidth:
|
||||
result.add(substr(word, 0, spaceLeft-1))
|
||||
var w = spaceLeft
|
||||
var wordLeft = len(word) - spaceLeft
|
||||
while wordLeft > 0:
|
||||
result.add(newLine)
|
||||
var L = min(maxLineWidth, wordLeft)
|
||||
spaceLeft = maxLineWidth - L
|
||||
result.add(substr(word, w, w+L-1))
|
||||
inc(w, L)
|
||||
dec(wordLeft, L)
|
||||
else:
|
||||
spaceLeft = maxLineWidth - len(word)
|
||||
result.add(newLine)
|
||||
result.add(word)
|
||||
else:
|
||||
spaceLeft = spaceLeft - len(word)
|
||||
result.add(lastSep & word)
|
||||
lastSep.setLen(0)
|
||||
|
||||
|
||||
|
||||
when isMainModule:
|
||||
proc nonStaticTests =
|
||||
doAssert formatBiggestFloat(1234.567, ffDecimal, -1) == "1234.567000"
|
||||
|
||||
@@ -293,3 +293,13 @@ when isMainModule:
|
||||
doAssert editDistanceAscii("", "") == 0
|
||||
doAssert editDistanceAscii("kitten", "sitting") == 3 # from Wikipedia
|
||||
doAssert editDistanceAscii("flaw", "lawn") == 2 # from Wikipedia
|
||||
|
||||
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix") == 14)
|
||||
assert(editDistance("prefix__hallo_suffix", "suffix") == 14)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2)
|
||||
assert(editDistance("main", "malign") == 2)
|
||||
|
||||
@@ -164,9 +164,6 @@ proc declared*(x: untyped): bool {.magic: "Defined", noSideEffect, compileTime.}
|
||||
## # provide our own toUpper proc here, because strutils is
|
||||
## # missing it.
|
||||
|
||||
when defined(useNimRtl):
|
||||
{.deadCodeElim: on.} # dce option deprecated
|
||||
|
||||
proc declaredInScope*(x: untyped): bool {.
|
||||
magic: "DefinedInScope", noSideEffect, compileTime.}
|
||||
## Special compile-time procedure that checks whether `x` is
|
||||
@@ -899,17 +896,6 @@ when defined(nimHasalignOf):
|
||||
when defined(nimtypedescfixed):
|
||||
proc sizeof*(x: typedesc): int {.magic: "SizeOf", noSideEffect.}
|
||||
|
||||
proc `<`*[T](x: Ordinal[T]): T {.magic: "UnaryLt", noSideEffect, deprecated.}
|
||||
## **Deprecated since version 0.18.0**. For the common excluding range
|
||||
## write ``0 ..< 10`` instead of ``0 .. < 10`` (look at the spacing).
|
||||
## For ``<x`` write ``pred(x)``.
|
||||
##
|
||||
## Unary ``<`` that can be used for excluding ranges.
|
||||
## Semantically this is the same as `pred <#pred,T,int>`_.
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
## for i in 0 .. <10: echo i # => 0 1 2 3 4 5 6 7 8 9
|
||||
##
|
||||
|
||||
proc succ*[T: Ordinal](x: T, y = 1): T {.magic: "Succ", noSideEffect.}
|
||||
## Returns the ``y``-th successor (default: 1) of the value ``x``.
|
||||
@@ -2597,19 +2583,6 @@ when not defined(js) and not defined(booting) and defined(nimTrMacros):
|
||||
# unnecessary slow down in this case.
|
||||
swap(cast[ptr pointer](addr arr[a])[], cast[ptr pointer](addr arr[b])[])
|
||||
|
||||
|
||||
# undocumented:
|
||||
proc getRefcount*[T](x: ref T): int {.importc: "getRefcount", noSideEffect,
|
||||
deprecated: "the refcount was never reliable, the GC does not use traditional refcounting".}
|
||||
proc getRefcount*(x: string): int {.importc: "getRefcount", noSideEffect,
|
||||
deprecated: "the refcount was never reliable, the GC does not use traditional refcounting".}
|
||||
proc getRefcount*[T](x: seq[T]): int {.importc: "getRefcount", noSideEffect,
|
||||
deprecated: "the refcount was never reliable, the GC does not use traditional refcounting".}
|
||||
##
|
||||
## Retrieves the reference count of an heap-allocated object. The
|
||||
## value is implementation-dependent.
|
||||
|
||||
|
||||
const
|
||||
Inf* = 0x7FF0000000000000'f64
|
||||
## Contains the IEEE floating point value of positive infinity.
|
||||
@@ -3337,16 +3310,6 @@ when not defined(nimscript) and hasAlloc:
|
||||
{.warning: "GC_getStatistics is a no-op in JavaScript".}
|
||||
""
|
||||
|
||||
template accumulateResult*(iter: untyped) {.deprecated: "use `sequtils.toSeq` instead (more hygienic, sometimes more efficient)".} =
|
||||
## **Deprecated since v0.19.2:** use `sequtils.toSeq
|
||||
## <sequtils.html#toSeq.t,untyped>`_ instead.
|
||||
##
|
||||
## Helps to convert an iterator to a proc.
|
||||
## `sequtils.toSeq <sequtils.html#toSeq.t,untyped>`_ is more hygienic and efficient.
|
||||
##
|
||||
result = @[]
|
||||
for x in iter: add(result, x)
|
||||
|
||||
# we have to compute this here before turning it off in except.nim anyway ...
|
||||
const NimStackTrace = compileOption("stacktrace")
|
||||
|
||||
@@ -3815,19 +3778,6 @@ when not defined(JS): #and not defined(nimscript):
|
||||
var e = getCurrentException()
|
||||
return if e == nil: "" else: e.msg
|
||||
|
||||
proc onRaise*(action: proc(e: ref Exception): bool{.closure.}) {.deprecated.} =
|
||||
## **Deprecated since version 0.18.1**: No good usages of this
|
||||
## feature are known.
|
||||
##
|
||||
## Can be used in a ``try`` statement to setup a Lisp-like
|
||||
## `condition system`:idx:\: This prevents the 'raise' statement to
|
||||
## raise an exception but instead calls ``action``.
|
||||
## If ``action`` returns false, the exception has been handled and
|
||||
## does not propagate further through the call stack.
|
||||
if not isNil(excHandler):
|
||||
excHandler.hasRaiseAction = true
|
||||
excHandler.raiseAction = action
|
||||
|
||||
proc setCurrentException*(exc: ref Exception) {.inline, benign.} =
|
||||
## Sets the current exception.
|
||||
##
|
||||
@@ -4357,34 +4307,6 @@ proc addQuoted*[T](s: var string, x: T) =
|
||||
else:
|
||||
s.add($x)
|
||||
|
||||
when hasAlloc:
|
||||
# XXX: make these the default (or implement the NilObject optimization)
|
||||
proc safeAdd*[T](x: var seq[T], y: T) {.noSideEffect, deprecated.} =
|
||||
## Adds ``y`` to ``x`` unless ``x`` is not yet initialized; in that case,
|
||||
## ``x`` becomes ``@[y]``.
|
||||
when defined(nimNoNilSeqs):
|
||||
x.add(y)
|
||||
else:
|
||||
if x == nil: x = @[y]
|
||||
else: x.add(y)
|
||||
|
||||
proc safeAdd*(x: var string, y: char) {.noSideEffect, deprecated.} =
|
||||
## Adds ``y`` to ``x``. If ``x`` is ``nil`` it is initialized to ``""``.
|
||||
when defined(nimNoNilSeqs):
|
||||
x.add(y)
|
||||
else:
|
||||
if x == nil: x = ""
|
||||
x.add(y)
|
||||
|
||||
proc safeAdd*(x: var string, y: string) {.noSideEffect, deprecated.} =
|
||||
## Adds ``y`` to ``x`` unless ``x`` is not yet initialized; in that
|
||||
## case, ``x`` becomes ``y``.
|
||||
when defined(nimNoNilSeqs):
|
||||
x.add(y)
|
||||
else:
|
||||
if x == nil: x = y
|
||||
else: x.add(y)
|
||||
|
||||
proc locals*(): RootObj {.magic: "Plugin", noSideEffect.} =
|
||||
## Generates a tuple constructor expression listing all the local variables
|
||||
## in the current scope.
|
||||
@@ -4436,18 +4358,6 @@ proc procCall*(x: untyped) {.magic: "ProcCall", compileTime.} =
|
||||
## procCall someMethod(a, b)
|
||||
discard
|
||||
|
||||
proc xlen*(x: string): int {.magic: "XLenStr", noSideEffect,
|
||||
deprecated: "use len() instead".} =
|
||||
## **Deprecated since version 0.18.1**. Use `len()` instead.
|
||||
discard
|
||||
proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect,
|
||||
deprecated: "use len() instead".} =
|
||||
## **Deprecated since version 0.18.1**. Use `len()` instead.
|
||||
##
|
||||
## Returns the length of a sequence or a string without testing for 'nil'.
|
||||
## This is an optimization that rarely makes sense.
|
||||
discard
|
||||
|
||||
|
||||
proc `==`*(x, y: cstring): bool {.magic: "EqCString", noSideEffect,
|
||||
inline.} =
|
||||
|
||||
@@ -322,40 +322,44 @@ proc testNimInAction(r: var TResults, cat: Category, options: string) =
|
||||
"niminaction/Chapter8/sdl/sdl_test"
|
||||
]
|
||||
|
||||
# Verify that the files have not been modified. Death shall fall upon
|
||||
# whoever edits these hashes without dom96's permission, j/k. But please only
|
||||
# edit when making a conscious breaking change, also please try to make your
|
||||
# commit message clear and notify me so I can easily compile an errata later.
|
||||
const refHashes = @[
|
||||
"51afdfa84b3ca3d810809d6c4e5037ba",
|
||||
"30f07e4cd5eaec981f67868d4e91cfcf",
|
||||
"d14e7c032de36d219c9548066a97e846",
|
||||
"b335635562ff26ec0301bdd86356ac0c",
|
||||
"6c4add749fbf50860e2f523f548e6b0e",
|
||||
"76de5833a7cc46f96b006ce51179aeb1",
|
||||
"705eff79844e219b47366bd431658961",
|
||||
"a1e87b881c5eb161553d119be8b52f64",
|
||||
"2d706a6ec68d2973ec7e733e6d5dce50",
|
||||
"c11a013db35e798f44077bc0763cc86d",
|
||||
"3e32e2c5e9a24bd13375e1cd0467079c",
|
||||
"a5452722b2841f0c1db030cf17708955",
|
||||
"dc6c45eb59f8814aaaf7aabdb8962294",
|
||||
"69d208d281a2e7bffd3eaf4bab2309b1",
|
||||
"ec05666cfb60211bedc5e81d4c1caf3d",
|
||||
"da520038c153f4054cb8cc5faa617714",
|
||||
"59906c8cd819cae67476baa90a36b8c1",
|
||||
"9a8fe78c588d08018843b64b57409a02",
|
||||
"8b5d28e985c0542163927d253a3e4fc9",
|
||||
"783299b98179cc725f9c46b5e3b5381f",
|
||||
"1a2b3fba1187c68d6a9bfa66854f3318",
|
||||
"391ff57b38d9ea6f3eeb3fe69ab539d3"
|
||||
]
|
||||
when false:
|
||||
# Verify that the files have not been modified. Death shall fall upon
|
||||
# whoever edits these hashes without dom96's permission, j/k. But please only
|
||||
# edit when making a conscious breaking change, also please try to make your
|
||||
# commit message clear and notify me so I can easily compile an errata later.
|
||||
# ---------------------------------------------------------
|
||||
# Hash-checks are disabled for Nim 1.1 and beyond
|
||||
# since we needed to fix the deprecated unary '<' operator.
|
||||
const refHashes = @[
|
||||
"51afdfa84b3ca3d810809d6c4e5037ba",
|
||||
"30f07e4cd5eaec981f67868d4e91cfcf",
|
||||
"d14e7c032de36d219c9548066a97e846",
|
||||
"b335635562ff26ec0301bdd86356ac0c",
|
||||
"6c4add749fbf50860e2f523f548e6b0e",
|
||||
"76de5833a7cc46f96b006ce51179aeb1",
|
||||
"705eff79844e219b47366bd431658961",
|
||||
"a1e87b881c5eb161553d119be8b52f64",
|
||||
"2d706a6ec68d2973ec7e733e6d5dce50",
|
||||
"c11a013db35e798f44077bc0763cc86d",
|
||||
"3e32e2c5e9a24bd13375e1cd0467079c",
|
||||
"a5452722b2841f0c1db030cf17708955",
|
||||
"dc6c45eb59f8814aaaf7aabdb8962294",
|
||||
"69d208d281a2e7bffd3eaf4bab2309b1",
|
||||
"ec05666cfb60211bedc5e81d4c1caf3d",
|
||||
"da520038c153f4054cb8cc5faa617714",
|
||||
"59906c8cd819cae67476baa90a36b8c1",
|
||||
"9a8fe78c588d08018843b64b57409a02",
|
||||
"8b5d28e985c0542163927d253a3e4fc9",
|
||||
"783299b98179cc725f9c46b5e3b5381f",
|
||||
"1a2b3fba1187c68d6a9bfa66854f3318",
|
||||
"391ff57b38d9ea6f3eeb3fe69ab539d3"
|
||||
]
|
||||
for i, test in tests:
|
||||
let filename = testsDir / test.addFileExt("nim")
|
||||
let testHash = getMD5(readFile(filename).string)
|
||||
doAssert testHash == refHashes[i], "Nim in Action test " & filename &
|
||||
" was changed: " & $(i: i, testHash: testHash, refHash: refHashes[i])
|
||||
|
||||
for i, test in tests:
|
||||
let filename = testsDir / test.addFileExt("nim")
|
||||
let testHash = getMD5(readFile(filename).string)
|
||||
doAssert testHash == refHashes[i], "Nim in Action test " & filename &
|
||||
" was changed: " & $(i: i, testHash: testHash, refHash: refHashes[i])
|
||||
# Run the tests.
|
||||
for testfile in tests:
|
||||
test "tests/" & testfile & ".nim"
|
||||
|
||||
@@ -203,11 +203,11 @@ when defined(windows):
|
||||
add(result, c)
|
||||
|
||||
proc sendMessages(client: AsyncFD) {.async.} =
|
||||
for i in 0 .. <messagesToSend:
|
||||
for i in 0 ..< messagesToSend:
|
||||
await winSend(client, "Message " & $i & "\c\L")
|
||||
|
||||
proc launchSwarm(port: Port) {.async.} =
|
||||
for i in 0 .. <swarmSize:
|
||||
for i in 0 ..< swarmSize:
|
||||
var sock = newNativeSocket()
|
||||
setBlocking(sock, false)
|
||||
|
||||
|
||||
@@ -14,6 +14,6 @@ s.add x
|
||||
s.add s[s.high]
|
||||
|
||||
s.add s[s.len-1]
|
||||
s.add s[s.xlen-1]
|
||||
s.add s[s.len-1]
|
||||
|
||||
echo s # @[5, 5, 0]
|
||||
|
||||
@@ -16,8 +16,8 @@ type
|
||||
AnyTransform3D* = AnyMatrix[4, 4, float]
|
||||
|
||||
proc transposed*(m: AnyMatrix): m.TransposedType =
|
||||
for r in 0 .. <m.R:
|
||||
for c in 0 .. <m.C:
|
||||
for r in 0 ..< m.R:
|
||||
for c in 0 ..< m.C:
|
||||
result[r, c] = m[c, r]
|
||||
|
||||
proc determinant*(m: AnySquareMatrix): int =
|
||||
|
||||
@@ -9,23 +9,27 @@ proc test(foo: Foo[int])
|
||||
required type for foo: Foo[int]
|
||||
but expression 'bar' is of type: Bar[system.int]
|
||||
t3330.nim(63, 8) Hint: Non-matching candidates for add(k, string, T)
|
||||
proc add[T](x: var seq[T]; y: T)
|
||||
first type mismatch at position: 1
|
||||
required type for x: var seq[T]
|
||||
but expression 'k' is of type: Alias
|
||||
proc add(x: var string; y: string)
|
||||
first type mismatch at position: 1
|
||||
required type for x: var string
|
||||
but expression 'k' is of type: Alias
|
||||
proc add[T](x: var seq[T]; y: openArray[T])
|
||||
first type mismatch at position: 1
|
||||
required type for x: var seq[T]
|
||||
but expression 'k' is of type: Alias
|
||||
proc add(result: var string; x: float)
|
||||
first type mismatch at position: 1
|
||||
required type for result: var string
|
||||
but expression 'k' is of type: Alias
|
||||
proc add(x: var string; y: char)
|
||||
proc add[T](x: var seq[T]; y: T)
|
||||
first type mismatch at position: 1
|
||||
required type for x: var seq[T]
|
||||
but expression 'k' is of type: Alias
|
||||
proc add(x: var string; y: cstring)
|
||||
first type mismatch at position: 1
|
||||
required type for x: var string
|
||||
but expression 'k' is of type: Alias
|
||||
proc add(x: var string; y: cstring)
|
||||
proc add(x: var string; y: char)
|
||||
first type mismatch at position: 1
|
||||
required type for x: var string
|
||||
but expression 'k' is of type: Alias
|
||||
@@ -33,10 +37,6 @@ proc add(result: var string; x: int64)
|
||||
first type mismatch at position: 1
|
||||
required type for result: var string
|
||||
but expression 'k' is of type: Alias
|
||||
proc add[T](x: var seq[T]; y: openArray[T])
|
||||
first type mismatch at position: 1
|
||||
required type for x: var seq[T]
|
||||
but expression 'k' is of type: Alias
|
||||
|
||||
t3330.nim(63, 8) template/generic instantiation of `add` from here
|
||||
t3330.nim(70, 6) Foo: 'bar.value' cannot be assigned to
|
||||
|
||||
@@ -410,7 +410,7 @@ macro wrapErrorChecking(f: stmt): stmt {.immediate.} =
|
||||
body = newStmtList glProc
|
||||
returnsSomething = child.params[0].kind != nnkEmpty
|
||||
callParams = newSeq[when defined(nimnode): NimNode else: PNimrodNode]()
|
||||
for param in params[1 .. <params.len]:
|
||||
for param in params[1 ..< params.len]:
|
||||
callParams.add param[0]
|
||||
|
||||
let glCall = newCall(glProc.name, callParams)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
output: '''443 443'''
|
||||
output: '''422 422'''
|
||||
"""
|
||||
|
||||
import strutils, os
|
||||
import strutils, os, std / wordwrap
|
||||
|
||||
import core / allocators
|
||||
import system / ansi_c
|
||||
@@ -76,12 +76,12 @@ proc staticTests =
|
||||
inp = """ this is a long text -- muchlongerthan10chars and here
|
||||
it goes"""
|
||||
outp = " this is a\nlong text\n--\nmuchlongerthan10chars\nand here\nit goes"
|
||||
doAssert wordWrap(inp, 10, false) == outp
|
||||
doAssert wrapWords(inp, 10, false) == outp
|
||||
|
||||
let
|
||||
longInp = """ThisIsOneVeryLongStringWhichWeWillSplitIntoEightSeparatePartsNow"""
|
||||
longOutp = "ThisIsOn\neVeryLon\ngStringW\nhichWeWi\nllSplitI\nntoEight\nSeparate\nPartsNow"
|
||||
doAssert wordWrap(longInp, 8, true) == longOutp
|
||||
doAssert wrapWords(longInp, 8, true) == longOutp
|
||||
|
||||
doAssert "$animal eats $food." % ["animal", "The cat", "food", "fish"] ==
|
||||
"The cat eats fish."
|
||||
|
||||
@@ -22,10 +22,10 @@ proc newFoo*(): ref TFoo =
|
||||
alive_foos.add result.id
|
||||
inc foo_counter
|
||||
|
||||
for i in 0 .. <10:
|
||||
for i in 0 ..< 10:
|
||||
discard newFoo()
|
||||
|
||||
for i in 0 .. <10:
|
||||
for i in 0 ..< 10:
|
||||
let f = newFoo()
|
||||
f.fn = proc =
|
||||
echo f.id
|
||||
|
||||
@@ -40,7 +40,7 @@ when true:
|
||||
@[2, 3]]
|
||||
|
||||
iterator threadUniqs(seq1: seq[seq[int]]): seq[seq[int]] =
|
||||
for i in 0 .. <seq1.len:
|
||||
for i in 0 ..< seq1.len:
|
||||
block:
|
||||
let i = i
|
||||
yield seq1.filter do (x: seq[int]) -> bool: x[0] == seq1[i][0]
|
||||
|
||||
@@ -8,7 +8,7 @@ proc convertReturns(node, retFutureSym: NimNode): NimNode {.compileTime.} =
|
||||
result = newCall(newIdentNode("complete"), retFutureSym, node[0])
|
||||
else:
|
||||
result = node
|
||||
for i in 0 .. <node.len:
|
||||
for i in 0 ..< node.len:
|
||||
result[i] = convertReturns(node[i], retFutureSym)
|
||||
|
||||
macro async2(prc: untyped): untyped =
|
||||
@@ -51,7 +51,7 @@ macro async2(prc: untyped): untyped =
|
||||
result = prc
|
||||
|
||||
# Remove the 'closure' pragma.
|
||||
for i in 0 .. <result[4].len:
|
||||
for i in 0 ..< result[4].len:
|
||||
if result[4][i].ident == !"async":
|
||||
result[4].del(i)
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ proc lobbyInit*() =
|
||||
messageArea.scrollBack -= 1
|
||||
update(messageArea))
|
||||
gui.newButton(text = "Flood msg area", position = vec2f(185, 30), onClick = proc(b: PButton) =
|
||||
for i in 0.. <30:
|
||||
for i in 0..< 30:
|
||||
dispMessage($i))"""
|
||||
dirServer = newServer()
|
||||
dirServer.addHandler HChat, handleChat
|
||||
|
||||
@@ -243,7 +243,7 @@ proc lobbyInit*() =
|
||||
messageArea.scrollBack -= 1
|
||||
update(messageArea))
|
||||
gui.newButton(text = "Flood msg area", position = vec2f(185, 30), onClick = proc(b: PButton) =
|
||||
for i in 0.. <30:
|
||||
for i in 0..< 30:
|
||||
dispMessage($i))
|
||||
|
||||
var i = 0
|
||||
|
||||
@@ -61,7 +61,7 @@ proc newPrimitive*(verts: var seq[TVert],
|
||||
color=white(),
|
||||
z: TZ_range=0): PPrimitive =
|
||||
var indices = newSeq[GLushort](verts.len)
|
||||
for i in 0 .. <verts.len:
|
||||
for i in 0 ..< verts.len:
|
||||
indices[i] = i.GLushort
|
||||
|
||||
new(result)
|
||||
@@ -108,7 +108,7 @@ proc updVerts*(o: PPrimitive, start, `end`: int, f: proc(i: int, vert: var TVert
|
||||
cast[GLvoid](cast[int](o.verts[0].addr) + byteOffset))
|
||||
|
||||
proc updAllVerts(o: PPrimitive, f: proc(i: int, vert: var TVert)) =
|
||||
for i in 0 .. <o.verts.len:
|
||||
for i in 0 ..< o.verts.len:
|
||||
f(i, o.verts[i])
|
||||
|
||||
?glBindBuffer(GLarrayBuffer, o.arrBufId)
|
||||
@@ -132,7 +132,7 @@ proc newVertCircle*(circle: TCircle, nSegs: Natural=0): seq[TVert] =
|
||||
|
||||
result = newSeq[TVert](nSegs)
|
||||
#result[0] = newVert(circle.p, newV2xy(0.5))
|
||||
for i in 1 .. <nSegs:
|
||||
for i in 1 ..< nSegs:
|
||||
let pos = newV2(x + circle.p.x, y + circle.p.y)
|
||||
let texCoord = pos * newV2xy(1.0 / circle.r)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ type
|
||||
# TODO: Change to TVT when compiler issue is resolved.
|
||||
proc `$`*[T](o: TV2[T]): string =
|
||||
result = "("
|
||||
for i in 0 .. <o.len:
|
||||
for i in 0 ..< o.len:
|
||||
result &= $o[0]
|
||||
if i != o.len - 1:
|
||||
result &= ", "
|
||||
@@ -47,7 +47,7 @@ proc `+`*(lhs: TV2[TR], rhs: TV2[TR]): TV2[TR] =
|
||||
# result += a[i] * b[i]
|
||||
|
||||
proc dot[T](a, b: TV2[T]): T =
|
||||
for i in 0 .. <a.len:
|
||||
for i in 0 ..< a.len:
|
||||
result += a[i] * b[i]
|
||||
|
||||
assert dot(newV2(), newV2()) == 0.0
|
||||
|
||||
@@ -61,7 +61,7 @@ proc row*(a: TMatrix; i: int): auto =
|
||||
|
||||
proc col*(a: TMatrix; j: int): auto =
|
||||
result = TVec[TMatrix.N, TMatrix.T]()
|
||||
for idx in 0 .. <TMatrix.N:
|
||||
for idx in 0 ..< TMatrix.N:
|
||||
result.data[idx] = a.data[(TMatrix.N * (idx)) + (j-1)]
|
||||
|
||||
proc mul*(a: TMat4f; b: TMat4f): TMat4f =
|
||||
|
||||
@@ -39,7 +39,7 @@ proc cmpPlatforms(a, b: string): int =
|
||||
|
||||
proc sorted[T](a: openArray[T]): bool =
|
||||
result = true
|
||||
for i in 0 .. < a.high:
|
||||
for i in 0 ..< a.high:
|
||||
if cmpPlatforms(a[i], a[i+1]) > 0:
|
||||
echo "Out of order: ", a[i], " ", a[i+1]
|
||||
result = false
|
||||
|
||||
@@ -24,5 +24,5 @@ write(stdout, ack(5, 4))
|
||||
|
||||
# bug #1442
|
||||
let h=3
|
||||
for x in 0.. <h.int:
|
||||
for x in 0 ..< h.int:
|
||||
echo x
|
||||
|
||||
@@ -19,7 +19,7 @@ proc showNumber(num: int | float) =
|
||||
showNumber(3.14)
|
||||
showNumber(42)
|
||||
|
||||
for i in 0 .. <10:
|
||||
for i in 0 ..< 10:
|
||||
echo(i)
|
||||
|
||||
block: # Block added due to clash.
|
||||
|
||||
@@ -202,7 +202,7 @@ block:
|
||||
|
||||
block:
|
||||
let list = @[4, 8, 15, 16, 23, 42]
|
||||
for i in 0 .. <list.len:
|
||||
for i in 0 ..< list.len:
|
||||
stdout.write($list[i] & " ")
|
||||
|
||||
var collection: set[int16]
|
||||
@@ -366,4 +366,4 @@ block:
|
||||
Color {.pure.} = enum
|
||||
red, green, blue
|
||||
|
||||
let color = Color.red
|
||||
let color = Color.red
|
||||
|
||||
@@ -46,7 +46,7 @@ assert obj["username"].str == "Dominik"
|
||||
|
||||
block:
|
||||
proc count10(): int =
|
||||
for i in 0 .. <10:
|
||||
for i in 0 ..< 10:
|
||||
result.inc
|
||||
assert count10() == 10
|
||||
|
||||
|
||||
@@ -67,9 +67,9 @@ proc readChunks(filename: string, chunksize = 1000000): Stats =
|
||||
# Find where the last line ends
|
||||
chunkLen.dec
|
||||
|
||||
responses.add(spawn parse(buffer[0 .. <chunkLen]))
|
||||
responses.add(spawn parse(buffer[0 ..< chunkLen]))
|
||||
oldBufferLen = readSize - chunkLen
|
||||
buffer[0 .. <oldBufferLen] = buffer[readSize - oldBufferLen .. ^1]
|
||||
buffer[0 ..< oldBufferLen] = buffer[readSize - oldBufferLen .. ^1]
|
||||
|
||||
for resp in responses:
|
||||
let statistic = ^resp
|
||||
|
||||
@@ -51,9 +51,9 @@ proc readChunks(filename: string, chunksize = 1000000): Stats =
|
||||
# Find where the last line ends
|
||||
chunkLen.dec
|
||||
|
||||
responses.add(spawn parse(buffer[0 .. <chunkLen]))
|
||||
responses.add(spawn parse(buffer[0 ..< chunkLen]))
|
||||
oldBufferLen = readSize - chunkLen
|
||||
buffer[0 .. <oldBufferLen] = buffer[readSize - oldBufferLen .. ^1]
|
||||
buffer[0 ..< oldBufferLen] = buffer[readSize - oldBufferLen .. ^1]
|
||||
|
||||
echo("Spawns: ", responses.len)
|
||||
for resp in responses:
|
||||
|
||||
@@ -58,9 +58,9 @@ proc readPageCounts(filename: string, chunkSize = 1_000_000) =
|
||||
while chunkLen >= 0 and buffer[chunkLen - 1] notin NewLines:
|
||||
chunkLen.dec
|
||||
|
||||
responses.add(spawn parseChunk(buffer[0 .. <chunkLen]))
|
||||
responses.add(spawn parseChunk(buffer[0 ..< chunkLen]))
|
||||
oldBufferLen = readSize - chunkLen
|
||||
buffer[0 .. <oldBufferLen] = buffer[readSize - oldBufferLen .. ^1]
|
||||
buffer[0 ..< oldBufferLen] = buffer[readSize - oldBufferLen .. ^1]
|
||||
|
||||
var mostPopular = newStats()
|
||||
for resp in responses:
|
||||
|
||||
@@ -7,7 +7,7 @@ import threadpool
|
||||
var counter = 0
|
||||
|
||||
proc increment(x: int) =
|
||||
for i in 0 .. <x:
|
||||
for i in 0 ..< x:
|
||||
let value = counter + 1
|
||||
counter = value
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ initLock(counterLock)
|
||||
var counter {.guard: counterLock.} = 0
|
||||
|
||||
proc increment(x: int) =
|
||||
for i in 0 .. <x:
|
||||
for i in 0 ..< x:
|
||||
let value = counter + 1
|
||||
counter = value
|
||||
|
||||
|
||||
@@ -79,9 +79,9 @@ proc findMessages*(database: Database, usernames: seq[string],
|
||||
result = @[]
|
||||
if usernames.len == 0: return
|
||||
var whereClause = " WHERE "
|
||||
for i in 0 .. <usernames.len:
|
||||
for i in 0 ..< usernames.len:
|
||||
whereClause.add("username = ? ")
|
||||
if i != <usernames.len:
|
||||
if i != usernames.high:
|
||||
whereClause.add("or ")
|
||||
|
||||
let messages = database.db.getAllRows(
|
||||
|
||||
@@ -26,9 +26,9 @@ proc greet(p:Person) =
|
||||
" friend:", p.friend.name, "(", cast[int](addr p.friend.name),") }"
|
||||
|
||||
proc setup =
|
||||
for i in 0 .. <20:
|
||||
for i in 0 ..< 20:
|
||||
people.add newPerson("Person" & $(i + 1))
|
||||
for i in 0 .. <20:
|
||||
for i in 0 ..< 20:
|
||||
people[i].friend = people[19-i]
|
||||
|
||||
proc update =
|
||||
|
||||
@@ -35,9 +35,9 @@ proc main =
|
||||
parallel:
|
||||
for n in nums: # Error: cannot prove: i <= len(nums) + -1
|
||||
spawn log(n)
|
||||
#for i in 0 .. <nums.len: # Error: cannot prove: i <= len(nums) + -1
|
||||
#for i in 0 ..< nums.len: # Error: cannot prove: i <= len(nums) + -1
|
||||
#for i in 0 .. nums.len-1: # WORKS!
|
||||
#for i in 0 .. <nums.len: # WORKS!
|
||||
#for i in 0 ..< nums.len: # WORKS!
|
||||
# spawn log(nums[i])
|
||||
|
||||
# Array needs explicit size to work, probably related to issue #2287
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
discard """
|
||||
output: "Success"
|
||||
target: "c"
|
||||
"""
|
||||
|
||||
# Note: target: "cpp" fails because we can't yet have `extern "C"` mangling in
|
||||
# `exportc` procs.
|
||||
import math, random, threadPool
|
||||
|
||||
# ---
|
||||
|
||||
type
|
||||
Person = object
|
||||
age: int
|
||||
friend: ref Person
|
||||
|
||||
var
|
||||
people: seq[ref Person] = @[]
|
||||
|
||||
proc newPerson(age:int): ref Person =
|
||||
result.new()
|
||||
result.age = age
|
||||
|
||||
proc greet(p:Person) =
|
||||
#echo p.age, ", ", p.friend.age
|
||||
p.friend.age += 1
|
||||
|
||||
# ---
|
||||
|
||||
proc setup =
|
||||
for i in 0 .. <20:
|
||||
people.add newPerson(i + 1)
|
||||
for i in 0 .. <20:
|
||||
people[i].friend = people[random(20)]
|
||||
|
||||
proc update =
|
||||
var countA: array[20, int]
|
||||
var countB: array[20, int]
|
||||
|
||||
for i, p in people:
|
||||
countA[i] = getRefCount(p)
|
||||
parallel:
|
||||
for i in 0 .. people.high:
|
||||
spawn greet(people[i][])
|
||||
for i, p in people:
|
||||
countB[i] = getRefCount(p)
|
||||
|
||||
for i in 0 .. <20:
|
||||
doAssert countA[i] == countB[i]
|
||||
echo "Success"
|
||||
|
||||
# ---
|
||||
|
||||
when true:
|
||||
setup()
|
||||
update()
|
||||
@@ -47,7 +47,7 @@ proc filter[T](a: openarray[T], predicate: proc (x: T): bool): seq[T] =
|
||||
|
||||
proc map[T, S](a: openarray[T], fn: proc (x: T): S): seq[S] =
|
||||
newSeq(result, a.len)
|
||||
for i in 0 .. <a.len: result[i] = fn(a[i])
|
||||
for i in 0 ..< a.len: result[i] = fn(a[i])
|
||||
|
||||
|
||||
type
|
||||
|
||||
@@ -46,7 +46,7 @@ type
|
||||
Vect[N: static[int], A] = array[N, A]
|
||||
|
||||
proc push[N: static[int], A](a: Vect[N, A], x: A): Vect[N + 1, A] =
|
||||
for n in 0 .. < N:
|
||||
for n in 0 ..< N:
|
||||
result[n] = a[n]
|
||||
result[N] = x
|
||||
|
||||
|
||||
@@ -155,24 +155,6 @@ proc testDelete =
|
||||
delete(s, 0, 0)
|
||||
assert s == "1236789ABCDEFG"
|
||||
|
||||
proc testIsAlphaNumeric =
|
||||
assert isAlphaNumeric("abcdABC1234") == true
|
||||
assert isAlphaNumeric("a") == true
|
||||
assert isAlphaNumeric("abcABC?1234") == false
|
||||
assert isAlphaNumeric("abcABC 1234") == false
|
||||
assert isAlphaNumeric(".") == false
|
||||
|
||||
testIsAlphaNumeric()
|
||||
|
||||
proc testIsDigit =
|
||||
assert isDigit("1") == true
|
||||
assert isDigit("1234") == true
|
||||
assert isDigit("abcABC?1234") == false
|
||||
assert isDigit(".") == false
|
||||
assert isDigit(":") == false
|
||||
|
||||
testIsDigit()
|
||||
|
||||
proc testFind =
|
||||
assert "0123456789ABCDEFGH".find('A') == 10
|
||||
assert "0123456789ABCDEFGH".find('A', 5) == 10
|
||||
@@ -273,15 +255,6 @@ assert(insertSep($232) == "232")
|
||||
assert(insertSep($12345, ',') == "12,345")
|
||||
assert(insertSep($0) == "0")
|
||||
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix") == 14)
|
||||
assert(editDistance("prefix__hallo_suffix", "suffix") == 14)
|
||||
assert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2)
|
||||
assert(editDistance("main", "malign") == 2)
|
||||
|
||||
assert "/1/2/3".rfind('/') == 4
|
||||
assert "/1/2/3".rfind('/', last=1) == 0
|
||||
assert "/1/2/3".rfind('0') == -1
|
||||
@@ -307,7 +280,7 @@ assert "".toHex == ""
|
||||
assert "\x00\xFF\x80".toHex == "00FF80"
|
||||
assert "0123456789abcdef".parseHexStr.toHex == "0123456789ABCDEF"
|
||||
|
||||
assert(' '.repeat(8)== " ")
|
||||
assert(' '.repeat(8) == " ")
|
||||
assert(" ".repeat(8) == " ")
|
||||
assert(spaces(8) == " ")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user