Skip to content

Commit

Permalink
delete list comprehension (nim-lang#12392)
Browse files Browse the repository at this point in the history
The `lc` macro is now part of `graveyard` repository.
  • Loading branch information
krux02 authored and narimiran committed Nov 22, 2019
1 parent c85e266 commit 2acf74d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 67 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- `strutils.formatFloat` with `precision = 0` has the same behavior in all
backends, and it is compatible with Python's behavior,
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

Expand Down
58 changes: 0 additions & 58 deletions lib/pure/sugar.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,64 +122,6 @@ macro `->`*(p, b: untyped): untyped =

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 =
## Dumps the content of an expression, useful for debugging.
## It accepts any expression and prints a textual representation
Expand Down
8 changes: 0 additions & 8 deletions tests/compiles/trecursive_generic_in_compiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,3 @@ proc foldLeft*[T,U](xs: List[T], z: U, f: (U, T) -> U): U =
case xs.isEmpty
of true: z
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

0 comments on commit 2acf74d

Please sign in to comment.