Subject: Re: exception/3

From: "Noord G.J.M. van" <[email-masked]>
Date: Tue, 2 Nov 1999 22:35:18 +0100 (MET)

Jan Wielemaker writes:
 > > why doens't exception work the way it is described in the manual?
 > > (version 3.2.9 on HP-UX 10.20)
 > 
 > Maybe this should be called maintenance problems.  One might also
 > call is improved understanding :-)
 > 
 > Thanks fot noting, but the undefined_predicate interception is no
 > longer called.

well, in some cases it is. Reading my original message, I note I was
not providing the correct example. In some cases exception/3 is fired,
produces a message defined by me, the user. And after that swi 
prints its own message as well.

 > 
 > Undefined predicates are ignored if the unknown/2 flag is active for
 > the implied module (or the predicate is defined using dynamic/1) and
 > otherwise cause an exception in the ISO-sense (i.e. using throw/1).

yes. I read that. I don't like it :-).  I want to be able to specify
only a few predicates for which I want the program to fail silently. For
most predicates, however, I do want an error to be raised. In SICStus
there's unknown_predicate_handler which can be used for this.

 > > Another question, is there a way to `hook' print_message/2 so that
 > > I can provide message printers for my own exceptions?
 > 
 > You can define additional translation to textual representation by
 > adding clauses to prolog:message/3 (a multifile predicate):
 > 
 > :- multifile prolog:message/3.
 > 
 > prolog:message(i_do_not_like(X)) -->
 > 	[ 'I no not like ', X ].
 > 
 > should produce a nice message if I do throw(i_do_not_like(fortran)).
 > 
 > See boot/messages.  At the moment there is no dynamic hook into
 > print_message/2.  If you need it, please let me know.

In this application, errors are represented as fsa_error(Format,Args)
where Format,Arg is a pair of arguments normally accepted by
format/2.
Since I can use sformat and then converse the result back to an
atom I can do:

prolog:message(fsa_error(Format,Args)) -->
    { format_to_chars(Format,Args,Chars),
      atom_chars(Atom,Chars)
    },
    [Atom].

where format_to_chars is:

format_to_chars(Format,Args,Chars) :-
    sformat(String,Format,Args),
    string_to_list(String,Chars).

this prints WARNING: ..; but I'd prefer `ERROR' or some such.
Well I guess for now this suffices.

Another issue, I am having trouble getting the qsave_state/2 predicate 
to work. If I use the stand_alone option, then apparantly the
resulting saved state doesn't seem to contain any of my predicates:

1 ?- [user].
|: x :- format("hallo~n",[]).
|:
user compiled, 0.00 sec, 600 bytes. 

Yes
2 ?- qsave_program(hallo,[stand_alone(true)]).

Yes
3 ?-
[halt]
tyr:Install6 709% ./hallo
Welcome to SWI-Prolog (Version 3.2.9)
Copyright (c) 1993-1999 University of Amsterdam.  All rights reserved.

For help, use ?- help(Topic). or ?- apropos(Word).

1 ?- x.
[WARNING: Undefined predicate: `x/0']

No

Any ideas? (remember this is HP-UX 10.20; compiled with 
--disable-mapped-stacks)

If I use the default settings, then it works for small examples, but
for larger examples I get:

[FATAL ERROR:
        Could not allocate memory: Not enough space]

What can be done about that?

-- 
Gertjan van Noord Alfa-informatica, RUG,  Postbus 716, 9700 AS Groningen
vannoord at let dot rug dot nl            http://www.let.rug.nl/~vannoord/