big rename
This commit is contained in:
parent
15a7bcc89f
commit
11b6958755
98 changed files with 2491 additions and 2341 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# Nim's Runtime Library
|
||||
# (c) Copyright 2011 Alex Mitchell
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
|
|
@ -31,7 +31,7 @@ proc concat*[T](seqs: varargs[seq[T]]): seq[T] =
|
|||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let
|
||||
## s1 = @[1, 2, 3]
|
||||
## s2 = @[4, 5]
|
||||
|
|
@ -50,7 +50,7 @@ proc concat*[T](seqs: varargs[seq[T]]): seq[T] =
|
|||
proc deduplicate*[T](seq1: seq[T]): seq[T] =
|
||||
## Returns a new sequence without duplicates.
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let
|
||||
## dup1 = @[1, 1, 3, 4, 2, 2, 8, 1, 4]
|
||||
## dup2 = @["a", "a", "c", "d", "d"]
|
||||
|
|
@ -69,7 +69,7 @@ proc zip*[S, T](seq1: seq[S], seq2: seq[T]): seq[tuple[a: S, b: T]] =
|
|||
## fields `a` and `b`. If one sequence is shorter, the remaining items in the
|
||||
## longer sequence are discarded. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let
|
||||
## short = @[1, 2, 3]
|
||||
## long = @[6, 5, 4, 3, 2, 1]
|
||||
|
|
@ -104,7 +104,7 @@ proc distribute*[T](s: seq[T], num: int, spread = true): seq[seq[T]] =
|
|||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let numbers = @[1, 2, 3, 4, 5, 6, 7]
|
||||
## assert numbers.distribute(3) == @[@[1, 2, 3], @[4, 5], @[6, 7]]
|
||||
## assert numbers.distribute(3, false) == @[@[1, 2, 3], @[4, 5, 6], @[7]]
|
||||
|
|
@ -155,7 +155,7 @@ iterator filter*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): T =
|
|||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let numbers = @[1, 4, 5, 8, 9, 7, 4]
|
||||
## for n in filter(numbers, proc (x: int): bool = x mod 2 == 0):
|
||||
## echo($n)
|
||||
|
|
@ -169,7 +169,7 @@ proc filter*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): seq[T] =
|
|||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let
|
||||
## colors = @["red", "yellow", "black"]
|
||||
## f1 = filter(colors, proc(x: string): bool = x.len < 6)
|
||||
|
|
@ -184,7 +184,7 @@ proc keepIf*[T](seq1: var seq[T], pred: proc(item: T): bool {.closure.}) =
|
|||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## var floats = @[13.0, 12.5, 5.8, 2.0, 6.1, 9.9, 10.1]
|
||||
## keepIf(floats, proc(x: float): bool = x > 10)
|
||||
## assert floats == @[13.0, 12.5, 10.1]
|
||||
|
|
@ -202,7 +202,7 @@ proc delete*[T](s: var seq[T], first=0, last=0) =
|
|||
##
|
||||
## Example:
|
||||
##
|
||||
##.. code-block:: nimrod
|
||||
##.. code-block::
|
||||
## let outcome = @[1,1,1,1,1,1,1,1]
|
||||
## var dest = @[1,1,1,2,2,2,2,2,2,1,1,1,1,1]
|
||||
## dest.delete(3, 8)
|
||||
|
|
@ -223,7 +223,7 @@ proc insert*[T](dest: var seq[T], src: openArray[T], pos=0) =
|
|||
##
|
||||
## Example:
|
||||
##
|
||||
##.. code-block:: nimrod
|
||||
##.. code-block::
|
||||
## var dest = @[1,1,1,1,1,1,1,1]
|
||||
## let
|
||||
## src = @[2,2,2,2,2,2]
|
||||
|
|
@ -254,7 +254,7 @@ template filterIt*(seq1, pred: expr): expr {.immediate.} =
|
|||
## the ``it`` variable for testing, like: ``filterIt("abcxyz", it == 'x')``.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let
|
||||
## temperatures = @[-272.15, -2.0, 24.5, 44.31, 99.9, -113.44]
|
||||
## acceptable = filterIt(temperatures, it < 50 and it > -10)
|
||||
|
|
@ -273,7 +273,7 @@ template keepItIf*(varSeq, pred: expr) =
|
|||
## the ``it`` variable for testing, like: ``keepItIf("abcxyz", it == 'x')``.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## var candidates = @["foo", "bar", "baz", "foobar"]
|
||||
## keepItIf(candidates, it.len == 3 and it[0] == 'b')
|
||||
## assert candidates == @["bar", "baz"]
|
||||
|
|
@ -292,7 +292,7 @@ template toSeq*(iter: expr): expr {.immediate.} =
|
|||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let
|
||||
## numeric = @[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
## odd_numbers = toSeq(filter(numeric) do (x: int) -> bool:
|
||||
|
|
@ -318,18 +318,18 @@ template foldl*(sequence, operation: expr): expr =
|
|||
## the sequence of numbers 1, 2 and 3 will be parenthesized as (((1) - 2) -
|
||||
## 3). Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let
|
||||
## numbers = @[5, 9, 11]
|
||||
## addition = foldl(numbers, a + b)
|
||||
## substraction = foldl(numbers, a - b)
|
||||
## multiplication = foldl(numbers, a * b)
|
||||
## words = @["nim", "rod", "is", "cool"]
|
||||
## words = @["nim", "is", "cool"]
|
||||
## concatenation = foldl(words, a & b)
|
||||
## assert addition == 25, "Addition is (((5)+9)+11)"
|
||||
## assert substraction == -15, "Substraction is (((5)-9)-11)"
|
||||
## assert multiplication == 495, "Multiplication is (((5)*9)*11)"
|
||||
## assert concatenation == "nimrodiscool"
|
||||
## assert concatenation == "nimiscool"
|
||||
assert sequence.len > 0, "Can't fold empty sequences"
|
||||
var result {.gensym.}: type(sequence[0])
|
||||
result = sequence[0]
|
||||
|
|
@ -354,18 +354,18 @@ template foldr*(sequence, operation: expr): expr =
|
|||
## the sequence of numbers 1, 2 and 3 will be parenthesized as (1 - (2 -
|
||||
## (3))). Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let
|
||||
## numbers = @[5, 9, 11]
|
||||
## addition = foldr(numbers, a + b)
|
||||
## substraction = foldr(numbers, a - b)
|
||||
## multiplication = foldr(numbers, a * b)
|
||||
## words = @["nim", "rod", "is", "cool"]
|
||||
## words = @["nim", "is", "cool"]
|
||||
## concatenation = foldr(words, a & b)
|
||||
## assert addition == 25, "Addition is (5+(9+(11)))"
|
||||
## assert substraction == 7, "Substraction is (5-(9-(11)))"
|
||||
## assert multiplication == 495, "Multiplication is (5*(9*(11)))"
|
||||
## assert concatenation == "nimrodiscool"
|
||||
## assert concatenation == "nimiscool"
|
||||
assert sequence.len > 0, "Can't fold empty sequences"
|
||||
var result {.gensym.}: type(sequence[0])
|
||||
result = sequence[sequence.len - 1]
|
||||
|
|
@ -384,7 +384,7 @@ template mapIt*(seq1, typ, pred: expr): expr =
|
|||
## since the new returned sequence can have a different type than the
|
||||
## original. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## let
|
||||
## nums = @[1, 2, 3, 4]
|
||||
## strings = nums.mapIt(string, $(4 * it))
|
||||
|
|
@ -401,7 +401,7 @@ template mapIt*(varSeq, pred: expr) =
|
|||
## expression. The expression has to return the same type as the sequence you
|
||||
## are mutating. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## var nums = @[1, 2, 3, 4]
|
||||
## nums.mapIt(it * 3)
|
||||
## assert nums[0] + nums[3] == 15
|
||||
|
|
@ -412,7 +412,7 @@ template mapIt*(varSeq, pred: expr) =
|
|||
template newSeqWith*(len: int, init: expr): expr =
|
||||
## creates a new sequence, calling `init` to initialize each value. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block::
|
||||
## var seq2D = newSeqWith(20, newSeq[bool](10))
|
||||
## seq2D[0][0] = true
|
||||
## seq2D[1][0] = true
|
||||
|
|
@ -503,12 +503,12 @@ when isMainModule:
|
|||
addition = foldl(numbers, a + b)
|
||||
substraction = foldl(numbers, a - b)
|
||||
multiplication = foldl(numbers, a * b)
|
||||
words = @["nim", "rod", "is", "cool"]
|
||||
words = @["nim", "is", "cool"]
|
||||
concatenation = foldl(words, a & b)
|
||||
assert addition == 25, "Addition is (((5)+9)+11)"
|
||||
assert substraction == -15, "Substraction is (((5)-9)-11)"
|
||||
assert multiplication == 495, "Multiplication is (((5)*9)*11)"
|
||||
assert concatenation == "nimrodiscool"
|
||||
assert concatenation == "nimiscool"
|
||||
|
||||
block: # foldr tests
|
||||
let
|
||||
|
|
@ -516,12 +516,12 @@ when isMainModule:
|
|||
addition = foldr(numbers, a + b)
|
||||
substraction = foldr(numbers, a - b)
|
||||
multiplication = foldr(numbers, a * b)
|
||||
words = @["nim", "rod", "is", "cool"]
|
||||
words = @["nim", "is", "cool"]
|
||||
concatenation = foldr(words, a & b)
|
||||
assert addition == 25, "Addition is (5+(9+(11)))"
|
||||
assert substraction == 7, "Substraction is (5-(9-(11)))"
|
||||
assert multiplication == 495, "Multiplication is (5*(9*(11)))"
|
||||
assert concatenation == "nimrodiscool"
|
||||
assert concatenation == "nimiscool"
|
||||
|
||||
block: # delete tests
|
||||
let outcome = @[1,1,1,1,1,1,1,1]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue