home *** CD-ROM | disk | FTP | other *** search
-
-
- Listing 2
-
- THE EXTENDED INTERPRETER
-
-
- % if a stub is there and it
- % should be used (e.g. no Prolog code
- % for process, use the stub
- do_goal( Goal ) :-
- % is there a stub for the Goal
- has_stub( Goal, Frame ),
- % should the stub be used?
- use_the_stub_q( Frame),
- !,
- % then definitely use the stub
- do_stub( Frame).
-
- % If the goal is user-defined to
- % fail, then make it fail (this
- % lets the user explore the specified
- % system)
- do_goal( Goal ) :-
- call( failing_goal( Goal)),
- !,
- fail.
-
- % If the goal is defined in Prolog
- % source code, then
- % interpret it using the definition
- % of Prolog
- do_goal( Goal) :-
- % Is the goal defined in Prolog code?
- defined_as_prolog_goal( Goal ),
- % display goal purpose from stub
- display_goal_purpose( Goal ),
- % get body of rule defining Goal
- clause( Goal, Body),
- % execute rule body
- do_body( Body).
-
- % Execute goals defined by Prolog system
- % code
- do_goal( Goal) :-
- % Make sure there is no source code
- % definition
- not defined_as_prolog_goal( Goal ),
- % Try the goal using Prolog system
- % procedures
- call( Goal ).
-
-
- /************ do_goal helpers ***********************/
-
- % Is a goal defined as source code?
- defined_as_prolog_goal( Term ) :-
- clause( Term, _),
- !.
-
- % do_body executes Prolog rule bodies
-
- % Is a goal defined as source code?
- do_body( true ) :- !.
-
- % Execute 'ands' of subgoals
- % in rule bodies
- do_body( ( H , Rest) ) :-
- !,
- do_and( H, Rest).
-
- % Execute a single goal, by calling
- % do_goal
- do_body( Term) :-
- do_goal( Term).
-
- % do_and executes 'ands' of goals
- do_and( Head , Rest) :-
- % Try the first goal
- do_goal( Head),
- % Try the other goals
- do_body( Rest).
-
- ---------------- end of listing -----------------------------------