proc toIter(it: seq[bool]): iterator: bool =
return iterator: bool =
for x in it:
yield x
proc realCountIt(it: iterator: bool, current: int): int =
discard it()
return if finished(it):
current
else:
realCountIt(it, current + 1)
proc count(it: seq[bool]): int = realCountIt(it.toIter, 0)
let arr1 = newSeq[bool](1_000)
let arr2 = newSeq[bool](100_000)
echo arr1.count # this line works file
echo arr2.count # this line Segmentation fault
# due to main.nims, it will run as:
# nim c --stacktrace:off -r main.nim
#
# or if you uncomment the line in main.nims script, it will run as:
# nim c --stacktrace:off -t:-foptimize-sibling-calls -r main.nim
#
# but both of them will cause a Segmentation fault in line 19
#
switch("verbosity", "3")
switch("stacktrace", "off")
# switch("passC", "-foptimize-sibling-calls")