From pmoura@noe.ubi.pt Fri Oct 26 16:15:40 2001
Received: from noe.ubi.pt (noe.ubi.pt [193.136.64.94])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f9QEFbt27652;
	Fri, 26 Oct 2001 16:15:37 +0200 (MET DST)
Received: from localhost (delta.ubi.pt [193.136.64.178])
	by noe.ubi.pt (8.9.3/8.9.3) with ESMTP id PAA04643;
	Fri, 26 Oct 2001 15:12:18 GMT
Date: Fri, 26 Oct 2001 15:15:34 +0100
Subject: Re: [SWIPL] Type error vs. silent failure
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Mime-Version: 1.0 (Apple Message framework v472)
Cc: Paulo Moura <pmoura@noe.ubi.pt>, Gernot Salzer <salzer@logic.at>,
   prolog@swi.psy.uva.nl
To: Jan Wielemaker <jan@swi.psy.uva.nl>
From: Paulo Moura <pmoura@noe.ubi.pt>
In-Reply-To: <200110261101.f9QB1Pl12948@gollem.swi.psy.uva.nl>
Message-Id: <EB9FA2B3-CA1B-11D5-8334-00039315BB3A@noe.ubi.pt>
X-Mailer: Apple Mail (2.472)
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by swi.psy.uva.nl id f9QEFbt27652


On Sexta, Outubro 26, 2001, at 12:01 , Jan Wielemaker wrote:

> Gernot,
>
>> [ Sorry, must have been discussed in the past, but couldn't find 
>> anything ]
> ...
> Without a standard, behaviour isn't defined.  Ok, there is some de-facto
> standard that says what nth1 must be doing, but there is little de-facto
> standard on how to handle things for which it wasn't designed
> (get/generate the nth-element).

In Logtalk I try to always generate exceptions that "fit" in the style 
defined in the ISO Standard for built-in predicates. However, is not 
always clear or commonly accepted that a call should fail or instead 
generate an exception. Sometimes people's programs rely on a failure 
where an exception would be the expected result (I remember a discussion 
in a Prolog mailing list with people complaining about an ISO definiton 
for arg/3 generating an exeception for calls like arg(-1, ...)).

> ...
> 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.  So,
> in 99% of the cases checking is more attractive from this perspective.

Always doing argument checking for library predicates is probably 
overkill for many applications. I have been playing around with the idea 
of defining two sets of library objects: one for debugging or critical 
applications containing error-checking code for every predicate and 
another version with that safe belt removed for applications that do not 
need/want error-checking. The two versions of the objects will share the 
same name. The programmer or the application will choose the version to 
load (possibly with some compiler flag).

Paulo


-----------------------------------------------------------
Paulo Jorge Lopes de Moura
Dep. of Informatics                   Office 4.3  Ext. 3257
University of Beira Interior          Phone: +351 275319700
6201-001 Covilhã                      Fax:   +351 275319732
Portugal

mailto:pmoura@noe.ubi.pt
http://www.ci.uc.pt/logtalk/pmoura.html
-----------------------------------------------------------

