![]() |
![]() |
|

Learning and Storage
Over the past few pages, you have learnt about the essence of Weblog, with programs that can carry on executing after calling submit/2, using getarg/2 to obtain data from web forms, allowing your application to respond to input from web pages. But as you've guessed, there is plenty more that Weblog lets you do!
Along with its pattern matching and backtracking behaviour, one special feature makes Prolog ideal in the world of Artificial Intelligence: applications can modify their own programming at run time, to learn from experience, and store information for later reference. Naturally, Weblog inherits these features.

Persistent Private Storage
In Prolog, if you want to change a program during runtime, or maybe just store a little data for later use, you do so with the "assert/1" predicate or one of its close relatives. And guess what: that is exactly the same in Weblog! Yes sir, that's right: Weblog fully supports assertions, retractions, and pretty much everything else that you would expect in a Prolog program, with no funny tricks to learn.
An important feature of Weblog, is that while your program can do what it likes in terms of assertion, retraction, perhaps even consulting source files and much more, these runtime changes remain completely private, to you and your individual web session. Even if dozens of people are simultaneously running the same Weblog application, whether on a single server, or cluster of servers, your assertions and retractions only affect your personal web session, and theirs, only theirs.
So let's explore this a little further; here is another version of our "Hello World/Bonjour Le Monde" program:
:- dynamic( greeting/2 ). weblog :- ( greeting( Tongue, Phrase ), submit( 'hello_3.htm', [(language,Tongue),(hello,Phrase)] ), getarg( choose, Next ), Next \= `more` -> ( Next = `done` -> submit( 'hello_31.htm', [(hello,`You pressed "DONE": Goodbye!`)] ) ; Next = `teach` -> getarg( language, Language ), getarg( phrase, Wording ), asserta( greeting(Language,Wording) ), submit( 'hello_32.htm', [(hello,`New Phrase Added: Starting Over!`)] ), weblog ) ; submit( 'hello_32.htm', [(hello,`No More Answers: Starting Over!`)] ), weblog ). greeting( `english`, `Hello World!` ). greeting( `french`, `Bonjour le Monde!` ). greeting( `german`, `Hallo Welt!` ). greeting( `italian`, `Ciao Mondo!` ). greeting( `spanish`, `Hola Mundo!` ).
Just as before, the weblog/0 application picks up a language and phrase from the greeting/2 predicate, before displaying a result with submit/2. Notice, though, that this time, greeting/2 has been declared "dynamic", and among the options that can be returned by getarg/2, is a new one, "teach". Here is the HTML web page for this example, "hello_3.htm":
<html> <head> <title>Hello World Example with Backtracking and Assertion</title> </head> <body> <h2>In {:language:}, you say, "{:hello:}"</h2> <p>Please choose your option:</p> <form name="" method="get" action="/weblog/hello_3.exe"> <input type="submit" name="choose" value="more"/> <input type="submit" name="choose" value="done"/><br/> <input type="text" placeholder="Language" name="language" value=""> <input type="text" placeholder="Phrase" name="phrase"> <input type="submit" name="choose" value="teach"/> </form> </body> </html>

Extended Form
Notice that the "<form>" is a little bigger than before, as it includes two "text" fields, into which you can type a new language and phrase, to "teach" Prolog new cases. The program itself runs much as before, but with an additional case, which asserts your new phrase whenever you press the "teach" option:
Just as with the previous example, this version chooses a greeting from the database, and submits it, before waiting for a response. If you choose "done", the program stops, as before, with a polite message shown in a copy of "hello_1.htm", renamed "hello_31.htm"; however, if you press "teach", it calls "getarg/2" to pick up your new language and phrase, which it then asserts, before starting over, displaying an appropriate message in yet another HTML file, "hello_32.htm":
<html> <head> <title>Hello World Example with Backtracking and Assertion</title> </head> <body> <h2>{:hello:}</h2> <p>Click here to start over:</p> <form name="" method="get" action="/weblog/hello_3.exe"> <input type="submit" name="choose" value="OK"/> </form> </body> </html>
Learning and Storage with Weblog
You have now seen all the key features of Weblog, which can be summarised like this:
- Your application program is alled "weblog", and is written directly in Prolog
- You call "sumbit/2" to combine an HTML page with one or more results from your program
- You call "getarg/2" to read values from a web form that has been displayed by submit/2
- You can use "assert/1", "retract/1" and more for persistent storage in your application
On the next page, you will see these ideas adapted still further, to demonstrate some of the flexibility of Weblog output.
Click here to run the "Teach Me" example
Click on the buttons to find out more, or jump directly to any of these links:
![]() |
![]() |
![]() |
Direct Link | Example Name |
---|---|
One Shot Program | "Hello World" |
Input and Backtracking | "Bonjour Le Monde" |
Learning and Storage | "Teach Me" |
Flexible Output | "John Likes Mary" |
Tables and Forms | "Family Tree" |
Photoshop and Images | "Lunar Phase" |
Illustrator and Prolog | "Big Ben Time Check" |
DreamWeaver and VisiRule 2 | "Lawns" |