From paul.singleton@bcs.org.uk Fri Oct 26 15:40:31 2001
Received: from mail11.svr.pol.co.uk (mail11.svr.pol.co.uk [195.92.193.23])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f9QDeVt18825
	for <prolog@swi.psy.uva.nl>; Fri, 26 Oct 2001 15:40:31 +0200 (MET DST)
Received: from modem-741.arbok.dialup.pol.co.uk ([217.135.18.229] helo=bcs.org.uk)
	by mail11.svr.pol.co.uk with esmtp (Exim 3.13 #0)
	id 15x7Dl-0004zX-00
	for prolog@swi.psy.uva.nl; Fri, 26 Oct 2001 14:40:25 +0100
X-Mozilla-Status: 0801
Message-ID: <3BD95E8E.5040202@bcs.org.uk>
Date: Fri, 26 Oct 2001 14:01:02 +0100
From: Paul Singleton <paul.singleton@bcs.org.uk>
User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-GB; rv:0.9.2) Gecko/20010726 Netscape6/6.1
X-Accept-Language: en-gb
MIME-Version: 1.0
To: prolog@swi.psy.uva.nl
Subject: Re: [SWIPL] Type error vs. silent failure
References: <200110261101.f9QB1Pl12948@gollem.swi.psy.uva.nl>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Jan Wielemaker wrote:

> Only in some really performance-critical situations I sometimes estimate
> whether using catch/3 or checking is more efficient.  Note that catch/3
> is not cheap for many reasons.  The call is a meta-call, you have to
> push the goal, template and recovery onto the stack and if an exception
> happens another expensive unwinding and meta-call must take place.


Please reassure us that the "exception doesn't happen" cost is nothing
to be afraid of :-)

If not, is it inherently expensive, or could it e.g. be compiled as a
special case?

> Next is coding:
> 	
> 	catch(nth1(N, List, E), error(type_error(_), _), fail)
> 
> isn't really pretty, but 
> 
> 	catch(nth1(N, List, E), _, fail).
> 
> May give some undesired results.  Maybe nth1/3 isn't around and your
> goal now fails silently rather then with an error.  Maybe the system
> runs out of stack, but this code will silently fail!


Java pragmatically distinguishes "checked" and "unchecked" exceptions,
then imposes static checking on checked exceptions (must be either
handled or explicitly declared to be possibly thrown).  Is it feasible
to do such static checking on (some practically useful subset of)
ISO or SWI Prolog?

Paul Singleton

PS I am not suggesting that it must be a good idea because Java does 
it, but that software engineering issues like this are essentially
pragmatic, not theological, and that there's been enough experience
with the Java scheme for us to decide whether it was well judged or
misconceived...


