Re: SWI-Prolog : current_prolog_flag(unknown, fail) is failing.



On 2006-08-30, roschler <robert.oschler@xxxxxxxxx> wrote:
Jan Wielemaker wrote:

It helps a lot if you say what you are doing in the first place.

1 ?- set_prolog_flag(unknown, fail).

Yes
2 ?- call(foobar).

No.

Note:

?- foobar.
ERROR: Undefined procedure: foobar/0

This is the DWIM (Do What I Mean) correction system of the toplevel that
still complains. Whats the point calling something from the toplevel that
doesn't exist?

--- Jan

P.s. Don't change this flag. Its a bit nuisance and it should never
have existed in the first place. In SWI-Prolog in particular as
most of the environment relies on autoloading and you cannot do
that if calling an undefined is not an error. See the dynamic
directive.

If you really have to, for example to test a possible incomplete
program as a logical theory, change the flag in the context of
a module and load the theory into that module.

Jan,

My fault. Jumping between SWI-Prolog and another Prolog and I got
confused between the "prolog_flag" predicates which are slightly
different between the versions. I should have been using
"set_prolog_flag".

As far as I'm aware the behaviour of SWI-Prolog is compliant with the
ISO standard. If not, please tell me.

Re: Don't use it.

Would there be any harm in setting the "unknown" flag to "fail" and
back to "error" before and after the top level goal? I could wrap the
top level goal that way.

Changing flags during a goal is a pretty nasty thing to do. Think of
failure, exceptions, etc. call_cleanup/2 makes the job a bit
easier, but still ...

Next, without this flag it is so easy for buggy programs to simply say
`no', leaving you no clue where to start looking.

Next, you have the nicely insert all required use_module(library(xyz))
calls. Failing causes a simple 'no'.

All you have to do is write

:- dynamic
foo/1,
bar/2.

for all predicates that are modified at runtime. Clear and simple. If
you do not know which they are, load the program and type

?- list_undefined.

Or, a bit more advanced in recent versions

?- gxref.

If you need to call something that may not exist, you can use
current_predicate/2 to test or wrap the call in a catch/3.

Cheers --- Jan
.