Subject: Re: [SWIPL] Can someone help me?

From: Jan Wielemaker <[email-masked]>
Date: Thu, 10 May 2001 16:08:45 +0200

> Hi, if I have a consult like this ...
> 
> ?- soma([2,4],3).
> 
> and this code ...
> 
> soma(X,Y):-
> 	X = [X1,Y1],
> 	Y = Y2,
> 	S1 is X1+Y2,
> 	S2 is Y1+Y2,
> 	print([S1,S2]).
> 
> ... why it doens't work giving me the error:
> 
> ?- soma([2,4],3).
> [WARNING: '.'/2: Type error: `[]' expected, found `[4]']
>  ^ Exception: (  9) _L123 is[2, 4]+3 ? creep
>    Exception: (  8) soma([2, 4], 3) ? creep
> [WARNING: Unhandled exception]
> 
> Execution Aborted
> 
> Can someone give me a hand ?

It's a bit odd code, but I think you didn't copy it right as the code
above is fine and works fine (SWI-Prolog 4.0.5 on Linux).

The exception itself looks a bit criptic, but results from
the fact that "a" evaluates to the code if the letter `a' (normally 97).
This happens because "a" is read as [97], which is .(97, []) and ./2
is defined as an arithmetic function that expects the 2nd argument to
be [] and the 1st argument to be an integer.

Look at the archives or a good Prolog book to see why you shouldn't
be using lists here in the first place.

	---- Jan