Subject: Re: arithmetic exception

From: "Richard A. O'Keefe" <[email-masked]>
Date: Mon, 20 Nov 2000 15:04:12 +1300 (NZDT)

numPos([], 0).
	numPos([Head|Tail], N):-integer(Head), Head>0, X is N-1, numPos(Tail,X).
	numPos([Head|Tail], N):-numPos(Tail,X).

Load that into SWI Prolog and it tells you:
	Warning: Singleton variables: [Head, N, X]

Head is forgivable here, but it is clear that N and X should have been
the same variable.  SICStus Prolog has essentially the same error message,
and so has Quintus Prolog.
	
	| ?- numPos([1,[2],3], 2).

SICStus Prolog says
    {INSTANTIATION ERROR: _78 is _75-1 - arg 2}
which is a little confusing, it means instantiation fault in argument 2 of
is(_78, _75-1), which is spot on correct.
Quintus Prolog words this a little better:
    ! Instantiation error in argument 2 of is/2
    ! goal:  _9649 is _9652-1
Both of these are pointing quite clearly to the X is N-1 subgoal,
telling us that N is unbound.