Thank you.
Wouldn't be a good idea to expand internally a convertible type like
_openarray_ before matching? For example, expand **test[T](x: openarray[T])**
as **test[T](x: (seq|array)[T])**
And maybe create also a priority queue to try to match first with non-generic
functions, and then try
> Which chapter was canceled?
Chapter 10 Direct Hardware Control
> I was going to buy it, but the chapter that I wanted is now cancelled.
Sorry to hear that. Good news is that I am planning on writing a condensed
version of it as an article.
I found the problem in the file lib/pure/os,nim and it does not look right to
me. Looking at the implementation there is the defer clause on line 974.
972var d = opendir(dir)
973if d != nil:
974 defer: discard closedir(d)
975 while true:
976
Seems like overload resolution for generic procedures works incorrectly when
generic parameters are limited by the type classes or concepts, or I mistake?
I tried next two variants and they are working as expected:
#proc test[T](x: T) = # this signature doesn't work. Why?!
proc test[T:not(array|seq)](x: T) =
echo x
proc test_impl[T](x: openarray[T]) =
for i in x:
echo i
proc
I wonder why this fails:
type
Iterable = concept c
for i in c: discard
proc test[T](x: T) =
echo x
proc test(x: Iterable) =
for i in x: echo i
test(1)
test([1, 2, 3])
Shouldn't `Iterable` be a better match?
woops! sorry, newb mistake.
the problem was that the path of another installation of MingW was higher up in
the tree than the nim one. used Rapid Env editor to restructure it and now it
works fine. thanks.
Just specialize within one generic function:
proc test[T](x: T) =
when T is seq or T is array:
for i in x:
echo i
else:
echo x
test(1)
test([1, 2, 3])
test(@[4, 5, 6])
Which chapter was canceled?