Page 1 of 1

Problem with std::cIterate

Posted: 11 Oct 2015 18:41
by Martin Meyer
Hello Thomas,

please have a look at this code. It does not output anything neither does raise an exception (in build 7501):

Code: Select all

clauses     run() :-         foreach _ = std::cIterate(upperBound(unsigned)) do             stdIo::write("*")         end foreach.
By tracking the execution in the debugger I see, that cIterate/1-> calls fromTo/2->. It picks however the predicate domain variant (integer From, integer To) -> integer I nondeterm while it would better take (unsigned From, unsigned To) -> unsigned I nondeterm.

Many regards
Martin

Posted: 11 Oct 2015 20:38
by Thomas Linder Puls
Yes, that is not good.

It is in accordance with the intension in the type system to choose the first (top most) version of cIterate that solves the "equation". and that is the second one:

Code: Select all

predicates     cIterate : (integer Count) -> integer I nondeterm.     cIterate : (unsigned Count) -> integer I nondeterm.     cIterate : (integer Count) -> unsigned I nondeterm.     cIterate : (unsigned Count) -> unsigned I nondeterm.
That should have resulted in an out-of-range exception when subtracting 1 in:

Code: Select all

clauses     cIterate(Count) = fromTo(0, Count - 1) :-         Count > 0.
But the std package have been equiped with a "/check:off" pragma:

Code: Select all

#options "/check:off"
And therefore the exception is not raised.

It may however make most sense to put that declatration last as it seems to be the "dangerous" one:

Code: Select all

predicates     cIterate : (integer Count) -> integer I nondeterm.     cIterate : (integer Count) -> unsigned I nondeterm.     cIterate : (unsigned Count) -> unsigned I nondeterm.     cIterate : (unsigned Count) -> integer I nondeterm.

Posted: 11 Oct 2015 23:06
by Martin Meyer
Thanx Thomas,

I have put declarations to that order, now it's working fine.

Regards
Martin

Posted: 12 Oct 2015 12:33
by Thomas Linder Puls
:-)