Input / output operations

As in other programming languages, Jess serves a variety of methods to communicate with the user. We can collect and send data on both the output in the form of console and file. By creating more complex systems, take advantage of opportunity to combine facts or rules from other files. This allows you to better manage modifications of expert system.

(printout t "Choose car type " crlf)
(printout t " " crlf)
(printout t "(compact, family, sport) " crlf)
(printout t " " crlf)
(bind ?a (read))
(assert (carType(type ?a)))

The example for Assorted right car. The command printout t prints on the screen the string given in quotation marks. Using crlf to go to the new line. Read command reads the data entered in the console. As you can see, they are immediately assigned to a variable.

(open "results.txt" file "w")

To act on files you must first open it. In example was opened results.txt file with the flag w. Later by performing an operation we have to use the name of the file. Depending on the application we have to choose three flags:

  • r - read only/li>
  • w - write
  • a - append existing file
(printout file "Prefered wax: " crlf)

When our file is opened. We communicate with it just as with the console, but instead of 't' use the name given early, in my case 'file'.

(batch facts.clp)

A good programming practice is to separate code files, each of which is responsible for other operations. In my case, the facts or questions to the user remain in a separate files. Batch command lets you attach files such as in the example.