Subject: Re: [SWIPL] sumlist to arithmetic function

From: Jan Wielemaker <[email-masked]>
Date: Wed, 26 Sep 2001 15:39:39 +0200

On Fri, 24 Aug 2001, Paul Singleton wrote:
>Hans-Ulrich Zimmermann <[email-masked]> writes:
>
>> converting the old sumlist predicate to an arithmetic function
>> will not work:
>
>> :-arithmetic_function(sumlist/1).
>
>> sumlist([],0).
>> sumlist([Kopf|Rumpf], Summe) :- sumlist(Rumpf,Teilsumme), 
>                                Summe is Kopf + Teilsumme.
>
>> Is there any solution?
>
>Empirically, SWI-Prolog accepts this directive:
>
>  :- arithmetic_function(sumlist/1).
>
>but if you call e.g. this goal
>
>  ?- A is sumlist([1,2,3,4,5]).
>
>it raises this error at runtime:
>
>   '.'/2: Type error: `[]' expected, found `[2, 3, 4, 5]'

Point remains that an arithetic function will only be passed
numbers as the arithmetic layer evaluates the arguments first.
Now, "a" is accepted as an expression returning the character code
for the letter 'a'.  As you might know, "a" is .(a, []) and the
above therefore is realised by defining ./2 as a (special) function
that demands the first argument to be a one-character atom and the
second to be an empty list.  Hence the error message.

Possibly it would be nice to allow for functions to be passed
their arguments literally.

	--- Jan