From: Alexander I. Baranovsky
Subject: "Imperative Analog" of LISP. Freeware Interpreter
Date:
Message-ID: <ABen0cvy19@blast.donetsk.ua>
VIRT is a new object-oriented programming language. My main goal was
included in creating of the expressive programming language with the
minimal number of basic concepts. This language can be used as for
numerical calculations and for knowledge processing as well with the
same success. It supply the indivisible language environment for the
wide ranges of the problems.
In the beginnig I considered the VIRT language as improved version of
Clipper. Now I rather think about VIRT as the peculiar "von Neumann
analogy" of the language LISP.
Polymorphic array is one of the built-in data types in the language
VIRT. Array element can be any abstract data type object particularly
the other polymorphic array. This property allows effectively to
construct any complex data structures ( such as multi-dimensional
array, list, binary tree ) without using pointers during run-time. All
OOP paradigmes ( encapsulation, inheritance, polymorphism ) are
represented in the language VIRT. This language has flexible control
structures and supports such concepts as coroutine, lazy evaluation.
However this is a very simple language.
The language VIRT has been implemented by me as interpreter for the
protected mode MS DOS. IDE includes specialized text editor and
debugger. This language has been examined by wide classes of tasks
such as simulation of dynamic data structures, theorem proving, graph
algorithmes, numerical methods of linear algebra, graphics applica-
tions.
The three papers devoted to the language VIRT are available at the
following URL: http://www.botspot.com/virt/. There is freeware version
of VIRT's interpreter with some demos. This interpreter quite suitable
for writing small programs and testing of constructions of the
language.
There are some examples below. With these "bones" you can easily
reconstruct the whole "dinosaur".
------------------------- Demo 1 -------------------------------------
-- Basic concepts : ( polymorphic ) array, lambda-object
-- Subject : recursion, lazy evaluation
uses system -- using file system.w
function Cond( A )
for I:=1 to Card( A ) do
if A[ I, 1 ] then
R := EvalObject( A[ I, 2 ], [] )
goto Fin
end
end
label Fin
return R
-- factorial in LISP-style
function Fact( N )
return Cond( [ [ N = 1, 1 ] , [ N > 1, { || N * Fact( N - 1 ) } ] ] )
writeln( Fact( 5 ) )
return -- Terminate program
The notes.
You can see that syntax is similar to the Modula-2. The expression in
curly brackets is defined a lambda-function ( lambda-object ).
Generally the labmda-object can has some parameters. ( In our case
parameters is absent ). Lambda-object is analog of the code block in
the Clipper language but here it has some additional properties. In
the given example the use of the lambda-object allows to avoid
infinite recursion.
------------------------- Demo 2 ------------------------------------
-- Basic concepts : class, object, constructor
-- Subject : abstract data type construction
class Point
function Init( InitX, InitY ) constructor
function "<"( Z ) -- The function sets definition of the operation "<"
function Draw()
end
class Circle : Point
function Init( InitX, InitY, InitR ) constructor
function "<"( Z ) -- Overlapping the function "<" from the class Point
function Draw() -- Overlapping the function Draw from the class Point
end
implementation Point
local X, Y, shared Num -- object's fields
function Init( InitX, InitY )
X := InitX
Y := InitY
if Null( Num ) then
Num := 0
end -- Num is shared for all objects of class Point
Num := Num + 1
return 0
function Norm() -- This is a private method
return X*X + Y*Y
function "<"( Z )
return Norm() < Z.Norm()
function Draw() external -- The external function hasn't a body
end
implementation Circle
local R
function Init( InitX, InitY, InitR )
Point.Init( InitX, InitY )
R := InitR
return 0
function GetR() inline
return R
function "<"( Z )
return R < Z.GetR()
function Draw() external
end
---- Main program -----
object P : Point -- This is a object's declaration.
P.Init( 3, 5 )
object Q( -4, 17 ) : Point
S := Point( 8, 7 ) -- Implicit constructor call
R := Q -- Assignment is defined by default.
if R < P then -- Using operation "<"
writeln( 'R less then P' )
else
writeln( 'R greate then P' )
end
return
The notes.
The operations ":=", "=", "<>" are defined for any abstract data type
objects by default. The concept of "destructor" is not present in the
language VIRT. ( This concept is not necessary here ).
------------------------- Demo 3 ------------------------------------
-- Basic concepts : array
-- Subject : structured data processing
uses system
-- Creation of a matrix
A := array( N ) -- implicit constructor call
for I:=1 to N do
A[ I ] := array( M )
end
A[ 3][ 5 ] := 3.14
A[ 3, 5 ] := 3.14
-- Creation of a list
L := [ 77, [ 'abc', [ 4.7, * ] ] ]
P == L[ 2 ] -- Identify P with [ 'abc', [ 4.7, * ] ]
P << [ 'cd', << P ] -- Result : L = [ 77, [ 'abc', [ 'cd', [ 4.7, * ] ] ] ]
-- Printing of the list
P == L
while not Null( P ) do
writeln( P[ 1 ] )
P == P[ 2 ]
end
-- Deletion from the list
P == L[2][2]
temp << P[ 2 ]
Destroy( @P )
P << temp -- Result : L = [ 77, [ 'abc', [ 4.7, * ] ] ]
return
The notes.
We can update a list and a tree effectively. We can build and update a
two-way list, a cycled list, balanced tree with the same success. ( See
my paper under URL above ).
------------------------- Demo 4 ------------------------------------
-- Basic concepts : string, functions EvalExpr, EvalLine
-- Subject : string evaluation
uses system
X := 10
Y := EvalExpr( 'X + 1' )
EvalLine( 'Z := X - Y' )
-- Result : Y = 11, Z = -1
return
------------------------- Demo 5 ------------------------------------
-- Basic concepts : corutine
-- Subject : corutine
uses system
class C
function F1()
function F2()
function F3()
end
implementation C
function F1()
writeln( 1 )
resume F2()
writeln( 2 )
resume F2()
return 0
function F2()
repeat
writeln( 'abc' )
resume F3()
until FALSE
return 0
function F3()
writeln( 'xyz' )
resume F1()
return 0
end
--- Main program -------------------
object A : C
writeln( A.F1() )
return
------------------------- Demo 6 ------------------------------------
-- Basic concepts : array, lambda-object, abstract data type ( clause )
-- Subject : knowledge representation
-- Compare with "Chang C.L. and Lee R.C.T.Symbolic Logic and
-- Mechanical Theorem Proving", Academic Press, New York, 1973.
uses system, chang -- using files system.w, chang.w
N := 50
A := array( 50 )
default ==
A[ 1 ] := Clause( { |X| [['+','L',X,['F',X]] ]})
A[ 2 ] := Clause( { |X| [['-','L',X,X] ]})
A[ 3 ] := Clause( { |X,Y| [['-','L',X,Y],['-','L',Y,X] ]})
A[ 4 ] := Clause( { |X,Y| [['-','D',X,['F',Y]],['+','L',Y,X] ]})
A[ 5 ] := Clause( { |X| [['+','P',X],['+','D',['H',X],X] ]})
A[ 6 ] := Clause( { |X| [['+','P',X],['+','P',['H',X]] ]})
A[ 7 ] := Clause( { |X| [['+','P',X],['+','L',['H',X],X] ]})
A[ 8 ] := Clause( { |X| [['-','P',X],['-','L','A',X],['+','L',['F','A'],X] ]})
W := array( N )
for I:=3 to N do
W[ I ] := [ 1, 2 ]
end
writeln( 'Theorem 9 :' )
writeln( 'The set of prime numbers is unlimited' )
TPU( A, W, N, 20 )
return
The benchmarks ( See monography above, Appendix A ) :
interpreter XLISP (sec) interpreter VIRT (sec)
Theorem 1 17.11 6.87
Theorem 2 81.04 69.12
Theorem 3 27.12 15.71
Theorem 4 33.34 10.60
Theorem 5 5.59 3.74
Theorem 6 135.15 8.74
Theorem 7 26.33 19.67
Theorem 8 - -
Theorem 9 17.45 17.20
( computer 386SX-20, real mode MS DOS ).
------------------------- Demo 7 -------------------------------------------
-- Basic concepts : function EvalExpr
-- Subject : knowledge representation, linking with Prolog and Datalog.
uses system, chang
S := 'grandfather(X,Y) :- father(X,Z), mother(Z,Y)'
S1 := GetClause( S ) -- GetClause is written on the VIRT language
-- S1 = '{ |X,Y,Z| [['+','grandfather',X,Y],['-','father',X,Z],['-','mother',Z,Y]] }'
C := Clause( EvalExpr( S1 ) )
return
----------------------------------------------------------------------------
Alexander I. Baranovsky
Flat 265, Constitution's square, 1
Donetsk, Ukraine.
E-mail : ·······@blast.donetsk.ua
Tel. 380622-371978