From jan@swi.psy.uva.nl  Thu Sep 28 15:14:59 2000
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id PAA21929;
	Thu, 28 Sep 2000 15:14:58 +0200 (MET DST)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id PAA27495;
	Thu, 28 Sep 2000 15:15:27 +0200
Date: Thu, 28 Sep 2000 15:15:27 +0200
Message-Id: <200009281315.PAA27495@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: SWI-Prolog  feature for foreign libraries
To: "Holmes-Higgin, Paul" <paul.holmes.higgin@documentum.com>,
        "Jan Wielemaker (E-mail)" <jan@swi.psy.uva.nl>
In-Reply-To: Holmes-Higgin, Paul's message of Fri, 15 Sep 2000 17:42:15 +0100
Phone: +31 - 20 - 525 6121
Cc: prolog@gollem.swi.psy.uva.nl

Paul,

[ Sorry for the late response.  Somehow my spambouncer put this mail in the spam
  folder.  I told it to pass mails from documentum.com without checking, so
  that should be fine now.

  Posted to the mailing.
]

> Still tinkering with XPCE (when I find the money or a project I will pay to
> get the full version!) and SWI-Prolog.  I found that on the latest Win
> builds that load_foreign_library was sometimes failing.  I could get it
> everytime that unknown(_,fail) was called before the *first* attempt to load
> the library.  If the unknown(_, fail) comes after the first load, even if I
> unload and then reload, everything is fine.
> 
> I.e.
> 
> load_fails:-
> 	unknown(_, fail),
> 	load_foreign_library('test.dll').
> 
> load_succeeds:-
> 	load_foreign_library('test.dll'),
> 	unload_foreign_library('test.dll'),
> 	unknown(_, fail),
> 	load_foreign_library('test.dll'),
> 	unload_foreign_library('test.dll').

This is normal.  load_foreign_library/1 is defined in the library(shlib), which
is normally auto-loaded.  If you switch trapping unknown producedured to fail,
the auto-loader is not activated and the fact that the predicate is not defined
is not reported.

This behaviour is intended.  The asumption is that unknown(_, fail) causes
fast failure.  Trapping the exception mechanism and autoloader is a rather
expensive process.  Normally this is fine, as it will only happen once per
predicate, either loading the predicate or throwing an error.

My advice is to never turn the unknown flag to fail, or at least to it locally
in a module where you are trying the run Prolog as a simple-minded theorem
prover.  For all other cases get rid of the errors using dynamic, multifile,
current_predicate or catch (depending on the context).

	Regards --- Jan

