From 2acf74d458accf65d969199a389c8dbc2eedab55 Mon Sep 17 00:00:00 2001 From: Arne Döring Date: Fri, 22 Nov 2019 19:57:43 +0100 Subject: delete list comprehension (#12392) The `lc` macro is now part of `graveyard` repository. --- changelog.md | 2 +- lib/pure/sugar.nim | 58 ----------------------- tests/compiles/trecursive_generic_in_compiles.nim | 8 ---- 3 files changed, 1 insertion(+), 67 deletions(-) diff --git a/changelog.md b/changelog.md index a1b6b6166..d736400f9 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/lib/pure/sugar.nim b/lib/pure/sugar.nim index c811f115c..af32e1546 100644 --- a/lib/pure/sugar.nim +++ b/lib/pure/sugar.nim @@ -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 diff --git a/tests/compiles/trecursive_generic_in_compiles.nim b/tests/compiles/trecursive_generic_in_compiles.nim index c435ebaac..88d3faeed 100644 --- a/tests/compiles/trecursive_generic_in_compiles.nim +++ b/tests/compiles/trecursive_generic_in_compiles.nim @@ -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 -- cgit 1.4.1-2-gfad0