From dmiles@teknowledge.com Wed Sep 26 22:12:09 2001
Received: from helium.teknowledge.com (promethium.teknowledge.com [128.136.192.50])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f8QKC8v13637;
	Wed, 26 Sep 2001 22:12:08 +0200 (MET DST)
Received: by helium.teknowledge.com with Internet Mail Service (5.5.2653.19)
	id <TKD5R1Y4>; Wed, 26 Sep 2001 13:05:09 -0700
Message-ID: <EE25484266A64A47AE06CFC47C64232B403B00@helium.teknowledge.com>
From: "Douglas R. Miles" <dmiles@teknowledge.com>
To: "'zimmermann@h-u-zimmermann.de'" <zimmermann@h-u-zimmermann.de>,
   "'Jan Wielemaker'" <jan@swi.psy.uva.nl>,
   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 13:04:20 -0700
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Content-Type: text/plain;
	charset="iso-8859-1"

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

That would be very nice.  I have an application that could use that kind of
support. 

Although and easy solution is to use a version of is/2 from prolog such as..

:-op(700,xfx,my_is).

my_is(R,E):-catch( R is E,_,fail),!.
my_is(R,(A+B)):-!,
	my_is(RA,A),
	my_is(RB,B),
	my_is(R,RA+RB).
my_is(R,(A-B)):-!,
	my_is(RA,A),
	my_is(RB,B),
	my_is(R,RA-RB).
my_is(R,(A*B)):-!,
	my_is(RA,A),
	my_is(RB,B),
	my_is(R,RA*RB).
my_is(R,(A/B)):-!,
	my_is(RA,A),
	my_is(RB,B),
	my_is(R,RA/RB).
...etc..
my_is(R,E):-
	E =..ECall, 
	append(ECall,[R],Call),!,
	Call.
..

But heh, what if is/2 '<'/2 '>'/2 (etc)  just 'assumed' that any
unknown/unregistered functors was grounds for 'arithmetic_function' and
naively constructed an extra argument on the end and sent it through the
call/1 .. The only issue I see, is it may inspire harder to track down
problems for people or less readable code if when it's not been declared as
arithmetic_function.  


-Douglas

> -----Original Message-----
> From: Jan Wielemaker [mailto:jan@swi.psy.uva.nl]
> Sent: Wednesday, September 26, 2001 6:40 AM
> To: Paul Singleton; SWI Prolog
> Subject: Re: [SWIPL] sumlist to arithmetic function
> 
> 
> 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
> 
> 
> ----------------
> * To UNSUBSCRIBE, please use the HTML form at
> 
>     
> http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist
> 
> or send mail to prolog-request@swi.psy.uva.nl using the 
> Subject: "unsubscribe"
> (without the quotes) and *no* message body.
> 
> ** An ARCHIVE of this list is maintained at
> 
>     http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/
> 
> 
> 

