aboutsummaryrefslogtreecommitdiff
path: root/project/QBarInterpreter/TestQBFile2.qbar
blob: bbf58ee603dfe82e8fe1fdc86957fa568c2176d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Incorporate Native com.modulus.qbar.lang.QBSystem;
Import Native java.lang.Math as JavaMath;
-{
	This part of this file is just used to
	test some of the common mathematical series.
}-

Namespace Test {
	let construct = do {
		this.x <- 5;
	}
}

Namespace Series {
	Struct Temp {
		let new Temp() = do {
			this.tmp <- Series.new Temp2();
		}
		
		let new Temp2() = do {
			this.i <- 5;
		}
	}

	let construct = do {

		this.factorial <- [ n | if n <= 1 then 1 else n * this # (n - 1) ];
		
		this.fibonacci <- [ n | if n < 2 then n else this # (n - 1) + this # ( n - 2 ) ];
		
		this.collatz <- [ n | if n <= 1 then 0
						else if n % 2 == 0 then 1 + this # (n div 2)
						else 1 + this # (n * 3 + 1) ];
		
		this.pascalsTriangle <- [ n | if n <= 0 then [ 1 ]
									else if n == 1 then [ 1, 1 ]
									else Series.pascalFromList( this # (n-1) ) ];
	}
	
	let pascal( n ) = this.pascalsTriangle # n;
	
	let pascalFromList( last ) = do {
		tmp <- [ 1 ];
		
		for [ 0 .. last.length - 2 ] -> n {
			tmp +< last # n + last # (n + 1);
		}
		
		tmp +< 1;
		return tmp;
	}
	
	let test = Test.x;
}
Incorporate Series;

let main = do {
	-- printStrLn( "This is the JavaMath.cos(15) call: " ++ JavaMath.cos(15) );
	printStrLn( "Test: " ++ test() );
}