From jan@swi.psy.uva.nl Wed Sep 26 15:45:16 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f8QDjGv22133;
	Wed, 26 Sep 2001 15:45:16 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f8QDjFX18964;
	Wed, 26 Sep 2001 15:45:15 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: Paul Singleton <paul.singleton@bcs.org.uk>,
   SWI Prolog <prolog@swi.psy.uva.nl>
Subject: Re: [SWIPL] sumlist to arithmetic function
Date: Wed, 26 Sep 2001 15:39:39 +0200
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <3B858B51.B759B41@bcs.org.uk>
In-Reply-To: <3B858B51.B759B41@bcs.org.uk>
MIME-Version: 1.0
Message-Id: <0109261545150P.15353@gollem>
Content-Transfer-Encoding: 8bit

On Fri, 24 Aug 2001, Paul Singleton wrote:
>Hans-Ulrich Zimmermann <zimmermann@h-u-zimmermann.de> 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

