Subject: Re: SWI-Prolog feature for foreign libraries

From: Jan Wielemaker <[email-masked]>
Date: Thu, 28 Sep 2000 15:15:27 +0200

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