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

Problem with std::cIterate

Unread post 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
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post 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.
Regards Thomas Linder Puls
PDC
Martin Meyer
VIP Member
Posts: 328
Joined: 14 Nov 2002 0:01

Unread post by Martin Meyer »

Thanx Thomas,

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

Regards
Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

:-)
Regards Thomas Linder Puls
PDC
Post Reply