Here
are some samples of source code that current version can compile:
Example
of class declaration
Example
of multiple inheritance
Passing
dynamic and static arrays as function arguments
CGI
chat written in Lemick Basic (download)
Also take
a look at lbpp - Lemick Basic pre-processor written in 100% LB
(Lemick Basic); it's included in source code distribution as lbpp.fbas.
In Making
OOP in Lemick
section there is an example of class implementing complex numbers.
Example
of class declaration:
class house
'starting class declaration
public
'all the members after this are public
dim
name as string, location as string
sub
init()
'contructor declaration
name="unknown":location="nowhere"
end sub
end class
class person
public
dim
name as string, age as int
sub init()
name="unknown":age=20
end sub
sub
rename(nn as string)
name=nn+str(age)
end sub
sub
next_age()
age=age+1
end sub
end class
class housemaid
public
dim
duty as int,level as real
dim
phome as house
dim
pinfo as person
sub init()
duty=0:level=0
end sub
sub init(d
as int) 'first
overloaded contructor declaration
duty=d:level=0
end sub
sub init(d
as int,l as int) 'second
overloaded contructor declaration
duty=d:level=l
end sub
sub
next_level()
level=level+1
end sub
function
len() as long '
overloading built-in function LEN for this class
len=len(phome.name)+len(phome.location)+len(pinfo.name)
end function
function
str() as string '
overloading built-in function STR
str="Home:"+phome.name+";
Name:"+pinfo.name
end function
end class
dim aaa
as housemaid(2,3) 'overloaded
constructor
dim s as
string
print aaa.duty
print aaa.phome.location
print aaa.pinfo.name
s="piccola"
aaa.pinfo.rename("Una
"+s(1)+" ragazza")
print aaa.pinfo.name
aaa.next_level()
aaa.pinfo.next_age()
print len(aaa)
print aaa
'print automatically
call str method of the class
Example
of multiple inheritance:
class proto_x
dim
id as string
public
sub
x_go_he()
print id;", go!"
end sub
sub
x_set_he(n as string)
id=n
end sub
end class
class proto_y
dim
id as string
public
sub
y_go_he()
print id;", go right now!"
end sub
sub
y_set_he(n as string)
id=n
end sub
end class
class proto_z
public
sub
z_go()
print "Z, go!"
end sub
end class
class xxx
extends proto_x,proto_y,proto_z
public
sub
go_go()
print "Go, go!"
end sub
end class
dim a as
xxx
a.x_set_he("Glog")
'calling method from
proto_x class
a.x_go_he
a.y_set_he("Um")
'calling method from
proto_y class
a.y_go_he
a.go_go
Passing
dynamic and static arrays as function argumentsts:
function
sum(test() as long,d as int) as long
for
i=0 to d-1
s=s+test(i)
next
sum=s
end function
function
sum2(dynamic test() as long,d as int) as long
for
i=0 to d-1
s=s+test(i)
next
sum2=s
end function
dim k(100)
as long
x=100
dim kk(x)
as long
for i=0 to
99:k(i)=i+1:next
print sum(k,100)
for i=0 to
99:kk(i)=i+1:next
print sum2(kk,100)
Note:
int and integer are lexically the same keywords in LB but I
prefer to use int for short.
(C)
Copyright 2001 Alex Iliasov
email:alex@users.kyrnet.kg
|