Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.cplire.ru/Lab144/start/e_hello.html
Дата изменения: Mon Sep 24 15:02:27 2007
Дата индексирования: Tue Oct 2 01:44:49 2012
Кодировка:

Поисковые слова: deep sky
Getting Started in Actor Prolog. Hello World.

Hello World!

Actor Prolog is an object-oriented logic language. So, any program written in Actor Prolog consists of classes. Each class has a name. Every class includes some slots and clauses.

Let us consider the first example (see the Hello.A file).

Example. The Hello World program.

-------------------------------------------
-- An example of Actor Prolog program.   --
-- (c) 2002, Alexei A. Morozov, IRE RAS. --
-------------------------------------------

project: (('Hello'))

class 'Hello' specializing 'Console':
[
goal:-
        writeln("Hello World!").
]

This program consists of solely 'Hello' class. The 'Hello' class includes one goal clause. It is only one writeln sub-goal in the clause. According to the semantics of Actor Prolog, during a creation of every instance of a class the goal predicate is called automatically in this instance of the class. Thus, when the instance of the 'Hello' class is created, the goal predicate runs. This predicate writes the "Hello World!" message.

The creation of an instance of a class (the "world") is fulfilled by proving some constructor of the class instance. Constructors are special expressions containing a name of a class, enclosed in the round brackets. The use of the double round brackets designates constructors of processes. An instance of a class, created with the help of a constructor of a process, is a separate process of the program. That is, it will be executed concurrently with the respect to other processes.

A constructor of a process is placed in the first line of the example program. This constructor defines an instance of the 'Hello' class. The instance of the class is declared as the goal statement of the program with the help of the project keyword. Thus, the execution of the program starts with the creation of an instance of the 'Hello' class. In the course of this operation the goal predicate will automatically run. This predicate will write the necessary message on the screen.

Note that the 'Hello' class is declared as a descendant of the 'Console' predefined class containing some useful read/write predicates, with the help of the specializing keyword. One of these predicates is the writeln predicate used in the program.

Expand the panel of the player with the help of the button before the start of the program:



Fig. 1. Reduced panel of the player.

Then press the button and select the Hello.A file in the example directory:



Fig. 2. Load of the program.

Here is the output of the program:



Fig. 3. The output of the program.

The functions of player buttons are the following:

  • : load and run a program.
  • : run the loaded program.
  • : save current state of the program and delay it.
  • : stop the program.
  • : reduce the panel of the player.
  • : expand the panel of the player.
  • : edit the parameters of the player.
  • : show the help.

Note that the player uses the following file extensions:

  • A: a source text written in Actor Prolog.
  • Run: a saved state of a delayed program (in the course of save of program state the player creates three files: Run, Bin, and Sys).
  • Bin: a translated program.
  • IDL: an SADT diagram. A diagram can be loaded and executed as a separate program.

Good luck!

Table of content