I was just testing if installing gintro works when generator script is compiled with --gc:arc already. (Of course that will be needed only when ARC will become default for Nim.)
First trivial issue is with glib.nim from oldgtk3 generated by old c2nim years ago,
const
# G_VARIANT_TYPE_BOOLEAN* = (cast[GVariantType]("b"))
G_VARIANT_TYPE_BOOLEAN* = (cast[GVariantType]("b".cstring))
issue is that string is not compatible with pointer type, but .cstring fix should work.
But unfortunately combinatorics.nim kindly provided by Mr Behrends years ago does not work with ARC:
/home/stefan/gintrotest/tests/combinatorics.nim(76) main
Error: unhandled exception: index out of bounds, the container is empty [IndexError]
Mr Behrends seems not to use Nim any more, see https://github.com/rbehrends
so his file exists currently at
https://github.com/StefanSalewski/gintro/blob/master/tests/combinatorics.nim
Question: Do we have a substitute? I guess it may exists similar named modules, I did a search for substitutes some years ago already, but did not found a module with exactly the needed iterator combinations(). There is https://github.com/barnybug/nim-combinatorics in nimble directory, but it is 4 years old and has no tests. And in Nim std lib I have not found a combinations() iterator. And writing that from scratch is not trivial, I tried years ago when I started with Nimrod.
Thanks for confirming that a combinations() iterator is not available in std lib yet.
Have just tried to explore Mr Behrends module, but I do not understand the code nor the error messages when compiled with --gc:arc. OK, then I will fix oldgtk3 for now and wait with combinations() iterator.
Indeed it is partly my own bug, I call in generator script gen.nim unintentionally something like
var s = newSeq[int]()
try:
for x in combinations(s, 1):
echo x
except:
discard
Of course makes no sense with empty seq, but works fine with default gc but gives this error with ARC:
Error: unhandled exception: /home/stefan/gintrotest/tests/combinatorics.nim(69, 10) `
0 <= k and
k <= n` [AssertionError]
Error: execution of an external program failed: '/home/stefan/gintrotest/tests/combinatorics '
First when such an error occured in my gen.nim script the error messages was unfortunately useless like
Traceback (most recent call last)
/home/stefan/gintrotest/tests/gen.nim(2595) gen
/home/stefan/gintrotest/tests/gen.nim(2530) launch
/home/stefan/Nim/lib/system/fatal.nim(34) main
/home/stefan/Nim/lib/system/fatal.nim(45) sysFatal
/home/stefan/Nim/lib/system/fatal.nim(33) sysFatal
Error: unhandled exception: index out of bounds, the container is empty [IndexError]
Can someone give me a hint why I get even with default GC:
$ nim c -r combinatorics.nim
/home/stefan/gintrotest/tests/combinatorics.nim(171, 30) Error: attempting to call routine: 'permutations'
found 'combinatorics.permutations(s: openArray[T]) [declared in /home/stefan/gintrotest/tests/combinatorics.nim(19, 10)]' of kind 'iterator'
There must be something wrong in the code after "when is mainModule:" with the testings templates, but I have no idea.
Of course makes no sense with empty seq, but works fine with default gc but gives this error with ARC:
A consequence of early deallocation with --gc:arc. With the "old" GC, the mem layout remains untouched until the GC scans the stack and completes deallocation. So basically, gc:arc did the right thing. By the way, I called the count template with a toSeq. The template didn't accept the plain iterator.
Like this, just for 100% clarity:
assert toSeq(permutations([1,2,3,4,5])).len == fac(5)