Hi, I wrote a simple program for a silly project I'm working on and this weird error appeared. Here is the code:
import algorithm, sequtils, strutils, tables
proc disorganize(books: seq[string]): seq[string] =
books.mapIt((b: it, t: it.toCountTable)).sortedByIt((
it.t['A'] + it.t['a'],
it.t['E'] + it.t['e'],
it.t['I'] + it.t['i'],
it.t['O'] + it.t['o'],
it.t['U'] + it.t['u'],
it.b.reversed.join
)).mapIt(it.b)
stdout.writeLine stdin.readAll.split("\n").disorganize.join("\n")
For debug re wrote the code, then this got compiled successfully. Wired.
Nim Compiler Version 1.2.0 [Windows: amd64]
import algorithm, sequtils, strutils, tables
proc disorganize(books: seq[string]): seq[string] =
let step1 = books.mapIt((b :it, t: it.toCountTable))
let step2 = step1.sortedByIt((
it.t['A'] + it.t['a'],
it.t['E'] + it.t['e'],
it.t['I'] + it.t['i'],
it.t['O'] + it.t['o'],
it.t['U'] + it.t['u'],
it.b.reversed.join
))
let step3 = step2.mapIt(it.b)
return = step3
stdout.writeLine stdin.readAll.split("\n").disorganize.join("\n")
chaining ...It macros doesn't work https://github.com/nim-lang/Nim/issues/12928/
do have a look at zero_functional it does chaining well, and inlines each link into the same loop
like this:
import zero_functional,sugar
proc disorganize1(books: seq[string]):seq[string] =
result = (books --> map((b: it, t: it.toCountTable)) --> map((b:it.b,t:(
it.t['A'] + it.t['a'],
it.t['E'] + it.t['e'],
it.t['I'] + it.t['i'],
it.t['O'] + it.t['o'],
it.t['U'] + it.t['u'],
it.b.reversed.join
)))).sorted((x,y)=>cmp(x.t,y.t)) --> map(it.b)
tried it on a large chunk of text, was about 10x faster than the sequtils version