Turbo Prolog Bugs

The following bugs have been encountered in version 1.1 of Turbo Prolog. They all seem to have been resolved in version 2.0 of Turbo Prolog and in Visual Prolog, except as indicated below.

Bug 1
/*
 * It seems that [] is unified with [_|_] in the following circumstances:
 * - the first argument of the first clause of a predicate is []
 * - the first argument of the second clause of the predicate is of the
 *     form [H|T]
 * - the predicate is called with [] as the first argument, but fails (due
 *     to another argument)
 *
 * So, for example:
 *    p([], 3) returns True  (which is INCORRECT)
 *    q([], 3) returns False (which is correct)
 *    r(3, []) returns False (which is correct)
 */
domains
  int  = integer
  ints = int*
predicates
  p(ints,int)
  q(ints,int)
  r(int,ints)
goal
  p([],3).
clauses
  p([], 0):-!.
  p([_|_], _):-write("p is unified [_|_] with []\n").

  q([_|_], _):-!.
  q([], 0):-write("q is unified [_|_] with []\n").

  r(0, []):-!.
  r(_, [_|_]):-write("r is unified [_|_] with []\n").
Bug 2

This bug is also present in version 2.0 of Turbo Prolog.

/*
 * The goal p(a,T,1), p(a,T,N) correctly returns N=1.
 * The goal q(a,T,1), q(a,T,N) should also return N=1, but it doesn't.
 * Instead it returns a garbage value.
 */
domains
  d = reference a(symbol,integer)
predicates
  p(symbol,d,integer)
  q(symbol,d,integer)
goal
  p(a,T,1), p(a,T,M), write(M), nl,
  q(a,T,1), q(a,T,N), write(N), nl.
clauses
  p(X, a(X, Y), Y).
  q(X, a(X, Y), Z):-Y=Z.
Bug 3
/* The write predicate displays "garbage"!   */
/* Gives stack overflow if write is removed! */
/***
shorttrace p /* OK if this is present */
***/
nowarnings
domains
  list = reference symbol*
predicates
  nondeterm p(symbol,symbol,symbol)
goal
  trace(off),
  A=[B], /* No bug if this is removed or A=[X]! */
  p(U,I,F),
  p(B,U,F),
  write(U,I,F,' ',B,U,F), nl,
  fail.
clauses
  p(a,c,e).
  p(a,n,d).
  p(a,p,e).
  p(a,t,e).
  p(b,a,d).
  p(s,a,t).
Bug 4
/*
 * During compilation using MS-DOS under Windows 98 we get:
 *   Le programme a tenté d'exécuter une instruction non valide.
 *   Emplacement de l'erreur 0C00:0C00
 * Using PC DOS version 7.00 (not under Windows), it hangs during
 *   compilation requiring Ctrl-Alt-Del
 */
domains
  int    = integer
  ints   = int*
  intss  = ints*
  intsss = intss*
  p      = p(intsss)
  ps     = p*
  chars  = char*
predicates
  cow(ps)
  pig(chars,int) /* Doesn't hang if pig(chars,char) */
clauses

cow(M):-
  A = p([]), B = p([]), C = p([]), D = p([]),
  E = p([]), F = p([]), G = p([]), H = p([]),
  I = p([]), J = p([]), K = p([]), L = p([]),
  M = [A, B, C, D, E, F, G, H, I, J, K, L].

pig([X|_], X).
Bug 5
/* Loops on output to screen and may hang */
domains
  chars = char*
predicates
  write_line(chars)
goal
  write_line(['a','b']).
clauses

write_line([]):-nl.
write_line([X|Xs]):-
  writef("%4", X),
  write_line(Xs).
Bug 6
/* Hangs (page fault?) if STACK=900 */
domains
  ints = integer*
predicates
  x(ints)
clauses

x(Y):-
  Y =
    [82,44,22,67,83,11,35,93,52,11,51,64,71,45,15,31,94,51,66,32,58,93,83,
     15,52,77,94,21,47,96,34,22,71,56,22,63,82,48,23,31,85,73,16,39,72,15,
     11,55,47,96,34,22,71,51,26,91,95,12,16,92,91,19,12,35,71,54,33,23,11,
     96,31,31,73,82,91,33,79,82,34,52,81,78,52,75,31,27,72,93,95,22,57,92,
     93,79,22,59,17,96,35,11,73,51,27,93,96,15,35,37,87,18,54,71,54,14,33,
     92,76,71,16,67,95,71,37,39,95,46,11,93,82,44,29,57,44,71,91,13,15,56,
     23,35,71,14,55,94,66,35,17,54,13,91,71,72,26,39,85,17,58,87,91,18,46,
     84,51,47,17,58,48,96,66,21,47,77,33,33,72,52,27,38,95,71,37,51,46,82,
     33,24,59,31,85,14,53,87,38,33,13,84,53,44,16,66,77,15,57,85,35,11,71,
     94,98,51,83,11,33,91,94,15,27,92,51,27,42,93,65],
  fail.
x([]).
Bug 7

This bug is also present in version 2.0 of Turbo Prolog.

/* The two calls to write(Ps) give different */
/*   output for what should be the same Ps.  */
/***
trace dog /* OK if this is present */
***/
domains
  int   = integer
  ints  = int*
  intss = ints*
predicates
  pig(ints)
  cow(int,ints)
  dog
goal
  pig(_).
clauses

pig([M|_]):-
  findall(A, cow(_, A), Ps),
  findall(B, cow(B, _), Ms),
  write(Ps), nl,
  Ms = [_,M],
  write(Ps), nl,
  fail.
pig([]).

cow(3, [0]).
cow(1, [2]).

dog.
Bug 8
/* W is output as 94, but it should be 4 */
domains
  cat=integer*
  cow=e(integer,integer)
predicates
  pig(cow,cat,cow,integer)
goal
  pig(e(1,4), [4], E, W),
  write("E=", E), nl,
  write("W=", W), nl.
clauses
  pig(e(U,W), [W], e(U,W), W).
Bug 9

This bug was apparently introduced at version 2.0 of Turbo Prolog. It is also present in versions 5.1 and 5.2 of Visual Prolog.

/* With Turbo Prolog 1.1 compilation is immediate           */
/* With Turbo Prolog 2.0 compilation takes about 12 seconds */
/* Adding P to V probably takes hours!                      */
domains
  int   = integer
  ints  = int*
  intss = ints*
predicates
  pig(intss)
goal
  pig(X), write(X), nl.
clauses

pig(X):-
  A=[2,3,4,6,7,12,15,16,19,20,21,25,27,28,29,30,31,33,35,36,37,38,39,40,42,
     44,45,50],
  B=[9,17,18,28,31,34],
  C=[1,8,17,18,21,27,28,35],
  D=[2,13,14,20,24,33,45,47],
  E=[5,6,7,8,10,11,12,13,14,16,17,18,20,21,22,24,26,29,30,32,33,35,38,39,41,
     43,46,47,48,49],
  F=[15,42],
  G=[12,36,48,49],
  H=[14,20,26,43],
  I=[1,2,4,6,8,9,13,14,18,19,21,22,23,24,25,27,31,32,40,41,44,45,47],
  J=[5,7,28],
  K=[15,25,29,32,44],
  L=[1,4,5,8,16,21,22,23,24,30,33,35,37,38,41,45,46,47,50],
  M=[6,7,16,19,20,22,25,36],
  N=[1,3,4,12,13,15,26,29,31,32,34,40,42,45,46],
  O=[1,9,23,28,34,37,47,48,50],
/***
  P=[11,37,38],
  Q=[6,9,11,15,16,17,18,25,26,29,30,31,34,35,43,48,49,50],
  R=[3,5,7,9,10,12,13,19,23,27,39,41,49],
  S=[10,11,14,39,40,44],
  T=[3,5,8,17,23,30,34,38,50],
  U=[2,10,19,32,43],
  V=[24,26,36,42,46],
***/
  X=[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O/***,P,Q,R,S,T,U,V***/].
Bug 10

This bug is also present in version 2.0 of Turbo Prolog and in versions 5.1 and 5.2 of Visual Prolog.

/* 1.E3 is sometimes, but not always, considered a valid value for a real */
goal
/*str_real(S, 1.E3), /* Compile-time error */*/
  str_real("1.E3", R), write(R). /* OK */
Bug 11

This bug is also present in version 2.0 of Turbo Prolog. If 'database' is replaced by 'database - pig' then this does not correctly execute using versions 5.1 or 5.2 of Visual Prolog either.

/* 
 * The goal fails, but it should succeed. 
 * It does succeed if the clause w([s,o]) is removed,
 *   or if 'database' is replaced by 'predicates'.
 */
domains
  r  = symbol
  rs = reference r*
database
  w(rs)
goal
  w([T,H,A,T]), write(T,H,A,T), nl.  
clauses

w([s,o]).
w([t,h,a,t]).
Bug 12

This bug is not present in version 2.0 of Turbo Prolog (I don't know about version 1.1). But with version 5.1 of Visual Prolog, using Target Platform DOS and UI Strategy Textmode, "0 257 2" is incorrectly displayed instead of "0 1 2".

domains
  pig = integer           % OK if this line is removed
  cow = reference integer
database - cat
  dog(cow,cow,cow,cow)
goal
  retractall(dog(_,_,_,_)),
  assert(dog(0,1,1,2)),
  dog(A,B,B,C),
  writef("% % %\n",A,B,C),
  write("Press enter\n"),
  readchar(_).
Bug 13

This bug is not present in version 1.1 of Turbo Prolog (where the function trunc() is not implemented), but is present in version 2.0.

/*
 * Gives stack overflow on execution.
 * If readchar(_) is removed from the goal, it hangs on execution.
 * Bypass: Replace "floor(T, Q)" by "floor(T, Q0), Q = Q0".
 */
predicates
  fdiv(real,real,real,real)
  floor(real,integer)
clauses  

fdiv(X, 0, 0, X):-!.
fdiv(X, Y, Q, R):-
  T = X / Y,
  floor(T, Q),
%  floor(T, Q0), Q = Q0, % Bypass
  R = X - Y * Q.

floor(X, Y):-Y = trunc(X), Y <= X, !.
floor(X, Y):-Y = trunc(X) - 1.

goal
  fdiv(7, 3, Q, R),
  writef("Q=% R=%\n", Q, R),
  readchar(_).
Bug 14

This bug is not present in version 1.1 of Turbo Prolog but is present in version 2.0, and also in version 5.1 (but not version 5.2) of Visual Prolog.

check_determ
domains
  chars = char*
predicates
  nondeterm pig(integer,char)
  nondeterm cow(integer,integer,integer)
clauses

pig(N, C):-
  cow(1, N, I),
  J = I + 64,
  char_int(C, J).
  
cow(I, J, I):-I <= J.
cow(I, J, K):-I < J, I1 = I + 1, cow(I1, J, K).

goal
  findall(X, pig(5, X), Xs),
  write(Xs), nl, /* This incorrectly gives [65,66,67,68,69]        */
  pig(5, Y),
  write(Y), nl,  /* This correctly gives A B C D E on backtracking */
  fail
  ;
  write("Failure - press enter\n"),
  readchar(_).
Bug 15

This bug is not present in version 2.0 of Turbo Prolog but, is present in versions 5.1 and 5.2 of Visual Prolog.

predicates
  pig(real)
clauses

pig(N):-writef("%0.0f", N), nl.

goal
  pig(1781104073),   % 1781104073  is displayed
  pig(2781104073.0), % 2781104073  is displayed
  pig(2781104073),   % -1513863223 is displayed !!!
  pig(3781104073),   % -513863223  is displayed !!!
  pig(4781104073),   % 4781104073  is displayed
  readchar(_).
Bug 16

This bug is not present in version 2.0 of Turbo Prolog, but is present in versions 5.1 and 5.2 of Visual Prolog.

domains
  int   = integer
  ints  = int*
  intss = ints*
predicates
  append(intss,intss,intss)
clauses

append([], Ys, Ys).
append([X|Xs], Ys, [X|Zs]):-append(Xs, Ys, Zs).

ifdef ws_win
goal
  trap(
    % With VIP gives EC=1009: General protection fault (access violation)
    append([], [], [[A,B]|_]), 
  EC, writef("EC=%\n", EC)),
  write(A, B), nl,
  write("Press enter\n"),
  readchar(_)
  ;
  write("Failure - press enter\n"),
  readchar(_).
elsedef
goal
  append([], [], [[A,B]|_]), % Correctly fails with Turbo Prolog
  write(A,B), nl,
  write("OK\n")
  ;
  write("Failure\n").
enddef
Bug 17

This bug is present in version 2.0 of Turbo Prolog.

predicates
%  nondeterm pig(integer,integer,real,real) % Hangs with Turbo Prolog version 2
  nondeterm pig(integer,integer,integer,integer) % OK
  nondeterm for(integer,integer,integer)
clauses

pig(D, N, X, Y):-
  for(1, 100, X),
  for(1, 100, Y),
  trap(
    X*X - D*Y*Y = N,
  _, fail).

for(I, J, I):-I <= J.
for(I, J, K):-I < J, I1 = I + 1, for(I1, J, K).

goal
  pig(10, 4, X, Y),        
  writef("X=% Y=%\n", X, Y).

Turbo Prolog Index     Home Page

Valid HTML 4.01 Strict