IF Computer > MINERVA > Manual > Reference > Objects

Objects

MINERVA
ifcomputer logo
f
Expert Services on the Web

Object oriented programming is useful to encapsulate internal state in predicates and manipulate the state.

MINERVA allows to define classes and their methods. An object of a class has an internal state that can be accessed like blackboard data, i.e. using bb_* predicates.

Example:

:- class(counter).

Counter :: init :- bb_put(Counter, index, 0).

Counter :: init(InitialValue) :- bb_put(Counter, index, InitialValue).

Counter :: get(Value) :- bb_get(Counter, index, Value).

Counter :: set(Value) :- bb_put(Counter, index, Value).

Counter :: next(Value) :- Counter :: get(OldValue), NewValue is OldValue + 1, Counter :: set(NewValue), Value = NewValue.

:- endclass.

The MINERVA compiler processes these predicates and in addition generates predicates create_CLASS/1/2 to produce a new object.

Resulting predicates are

	Object::Method(Arg1,..,ArgN)
where Object must be produced with create_object/2 and Method must be an atom or compound.

For the example above in classic Prolog:

	create_counter(10,Counter),
	Counter :: next(Index)

For the example above with function notation:

	Counter <- create_counter(10),
	Index <- Counter::next,
	...

document: http://www.ifcomputer.co.jp/MINERVA/Manual/Reference/Objects/print_en.html
published 2008/7/21 update 2003/2/26 (c) 1996-2006 IF Computer Japan
IF Computer 5-28-2 Sendagi, Bunkyo-ku Tel +81-3-5814-3352 info@ifcomputer.com
Customer Support Tokyo 113-0022 Japan   http://www.ifcomputer.com
Back> managed with ubiCMS