Problem with std::cIterate

Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 279
Joined: 14 Nov 2002 0:01

Problem with std::cIterate

Unread post by Martin Meyer » 11 Oct 2015 18:41

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

User avatar
Thomas Linder Puls
VIP Member
Posts: 1159
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 11 Oct 2015 20:38

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.
Regards Thomas Linder Puls
PDC

Martin Meyer
VIP Member
Posts: 279
Joined: 14 Nov 2002 0:01

Unread post by Martin Meyer » 11 Oct 2015 23:06

Thanx Thomas,

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

Regards
Martin

User avatar
Thomas Linder Puls
VIP Member
Posts: 1159
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 12 Oct 2015 12:33

:-)
Regards Thomas Linder Puls
PDC

Post Reply