delete list comprehension (#12392)
The `lc` macro is now part of `graveyard` repository.
This commit is contained in:
parent
c85e266d1d
commit
2acf74d458
3 changed files with 1 additions and 67 deletions
|
|
@ -16,7 +16,7 @@
|
||||||
- `strutils.formatFloat` with `precision = 0` has the same behavior in all
|
- `strutils.formatFloat` with `precision = 0` has the same behavior in all
|
||||||
backends, and it is compatible with Python's behavior,
|
backends, and it is compatible with Python's behavior,
|
||||||
e.g. `formatFloat(3.14159, precision = 0)` is now `3`, not `3.`.
|
e.g. `formatFloat(3.14159, precision = 0)` is now `3`, not `3.`.
|
||||||
|
- Global variable `lc` has been removed from sugar.nim.
|
||||||
|
|
||||||
### Breaking changes in the compiler
|
### Breaking changes in the compiler
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,64 +122,6 @@ macro `->`*(p, b: untyped): untyped =
|
||||||
|
|
||||||
result = createProcType(p, b)
|
result = createProcType(p, b)
|
||||||
|
|
||||||
type ListComprehension = object
|
|
||||||
var lc* {.deprecated.}: ListComprehension
|
|
||||||
|
|
||||||
template `|`*(lc: ListComprehension, comp: untyped): untyped {.deprecated.} = lc
|
|
||||||
|
|
||||||
macro `[]`*(lc: ListComprehension, comp, typ: untyped): untyped {.deprecated.} =
|
|
||||||
## List comprehension, returns a sequence. `comp` is the actual list
|
|
||||||
## comprehension, for example ``x | (x <- 1..10, x mod 2 == 0)``. `typ` is
|
|
||||||
## the type that will be stored inside the result seq.
|
|
||||||
##
|
|
||||||
## .. code-block:: nim
|
|
||||||
##
|
|
||||||
## echo lc[x | (x <- 1..10, x mod 2 == 0), int]
|
|
||||||
##
|
|
||||||
## const n = 20
|
|
||||||
## echo lc[(x,y,z) | (x <- 1..n, y <- x..n, z <- y..n, x*x + y*y == z*z),
|
|
||||||
## tuple[a,b,c: int]]
|
|
||||||
## **Deprecated since version 0.19.9**
|
|
||||||
|
|
||||||
expectLen(comp, 3)
|
|
||||||
expectKind(comp, nnkInfix)
|
|
||||||
assert($comp[0] == "|")
|
|
||||||
|
|
||||||
result = newCall(
|
|
||||||
newDotExpr(
|
|
||||||
newIdentNode("result"),
|
|
||||||
newIdentNode("add")),
|
|
||||||
comp[1])
|
|
||||||
|
|
||||||
for i in countdown(comp[2].len-1, 0):
|
|
||||||
let x = comp[2][i]
|
|
||||||
expectMinLen(x, 1)
|
|
||||||
if x[0].kind == nnkIdent and $x[0].ident == "<-":
|
|
||||||
expectLen(x, 3)
|
|
||||||
result = newNimNode(nnkForStmt).add(x[1], x[2], result)
|
|
||||||
else:
|
|
||||||
result = newIfStmt((x, result))
|
|
||||||
|
|
||||||
result = newNimNode(nnkCall).add(
|
|
||||||
newNimNode(nnkPar).add(
|
|
||||||
newNimNode(nnkLambda).add(
|
|
||||||
newEmptyNode(),
|
|
||||||
newEmptyNode(),
|
|
||||||
newEmptyNode(),
|
|
||||||
newNimNode(nnkFormalParams).add(
|
|
||||||
newNimNode(nnkBracketExpr).add(
|
|
||||||
newIdentNode("seq"),
|
|
||||||
typ)),
|
|
||||||
newEmptyNode(),
|
|
||||||
newEmptyNode(),
|
|
||||||
newStmtList(
|
|
||||||
newAssignment(
|
|
||||||
newIdentNode("result"),
|
|
||||||
newNimNode(nnkPrefix).add(
|
|
||||||
newIdentNode("@"),
|
|
||||||
newNimNode(nnkBracket))),
|
|
||||||
result))))
|
|
||||||
|
|
||||||
macro dump*(x: typed): untyped =
|
macro dump*(x: typed): untyped =
|
||||||
## Dumps the content of an expression, useful for debugging.
|
## Dumps the content of an expression, useful for debugging.
|
||||||
## It accepts any expression and prints a textual representation
|
## It accepts any expression and prints a textual representation
|
||||||
|
|
|
||||||
|
|
@ -92,11 +92,3 @@ proc foldLeft*[T,U](xs: List[T], z: U, f: (U, T) -> U): U =
|
||||||
case xs.isEmpty
|
case xs.isEmpty
|
||||||
of true: z
|
of true: z
|
||||||
else: foldLeft(xs.tail, f(z, xs.head), f)
|
else: foldLeft(xs.tail, f(z, xs.head), f)
|
||||||
|
|
||||||
suite "unittest compilation error":
|
|
||||||
|
|
||||||
test "issue 3313":
|
|
||||||
let lst = lc[$x | (x <- 'a'..'z'), string].asList
|
|
||||||
|
|
||||||
let lstCopy = lst.dup
|
|
||||||
check: lstCopy == lst
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue