Using off-the-shelf pages
A little trick.
In the VIP development environment, you can test your code at any time without having to compile it into an EXE file.
For example, to see the execution results of the VIP built-in predicate filenameext, you can write in a blank. Pro file:
GOAL filenameext ("Prolog.exe", Name,ext), filenameext (NewName, "Prolog.exe", ". Err").
Then click the Menu "Project | Test Goal ", you will see the following results:
Name=prolog, ext=. EXE, Newname=prolog. Err
In addition, the basic characteristics and usage of Prolog include the matching (unity), backtracking, truncation,
Streaming mode, etc., in the Visual Prolog Web expert system (4)
has been introduced in the future, no longer elaborate.
Now get into today's topic and generate Web pages.
The starting point is the statement of the goal segment: Userdefined_startpage ()
Userdefined_startpage ():-d efault_startpage (FILENAME), consult_htm (filename,htmltext),!, gethtmlbody ( Htmltext,bodytext), write (BodyText). Userdefined_startpage ():-kb (KB),!, write ("
Let's take a look at its process control.
The 3 clauses are called clause 1, clause 2, and clause 3 respectively.
1, Clause 1 execution default_startpage (FILENAME) if failed,
Go back to clause 2, if there is a KB (KB) in the fact library,
After you run clause 2, Clause 3 does not have a chance to execute;
2, Kawai sentence 2, the fact that the library does not have KB (KB),
Back to clause 3, program error exits.
3, Clause 1 execution consult_htm (filename,htmltext) Success,
Then execute the complete statement, write the body part of the page,
And truncation occurs, clause 2, Clause 3 does not have the opportunity to retrace the execution;
The following is a look at the several statements in clause 1.
Default_startpage (FILENAME)It is a fact in the fact library Geni, the previous section ("Visual Prolog Web Expert system (4)")
It is from animal.gni,filename = "animal.htm"
Consult_htm (Filename,htmltext)Consult_htm (Filename,htmltekst):-syspath (Exestartuppath,_progname), Filenamepath (Fullname,exestartuppath, FileName), Trap (FILE_STR (Fullname,htmltekst), _,writef ("file% is not found! Correct problem!\n ", FullName)),!. Consult_htm (_, ""):-errorexit.
2 predicates Syspath and Filenamepath, which are described in the previous section.
Trap (FILE_STR (Fullname,htmltekst), _,writef ("file% is not found! Correct problem!\n ", FullName))On my machine, FullName = "d:\\apache2.2\\htdocs\\geni\\animal.htm"
The result of executing the FILE_STR is to put the contents of the file into the variable Htmltekst
The VIP built-in predicate WRITEF is the formatted output. The content is:
File d:\apache2.2\htdocs\geni\animal.htm is not found! Correct problem!
The following is an introduction to the trap.
Built predicate trap (predicatecall, INTEGER ExitCode, Errorpredicate)
Flow mode is (I, o,i)
Used to capture exit, interrupt, and run-time errors for a program.
The predicatecall of the invoked clause leads to the success or failure of the trap.
Errorpredicate is a predicate call for an error.
Write (BodyText)Writes the contents of the body of the Web page to CGI. Today's mission is complete.