aboutsummaryrefslogtreecommitdiff
path: root/project/QBarInterpreter/TestQBFile2.qbar
diff options
context:
space:
mode:
authorJoshua Rahm <joshua.rahm@colorado.edu>2015-01-27 18:40:32 -0700
committerJoshua Rahm <joshua.rahm@colorado.edu>2015-01-27 18:40:32 -0700
commit5f3fb9afece2125cbeba79d61a8d88460b7878d7 (patch)
treeb0e1e60bae9927a9449561bf7fe9431a54d12be9 /project/QBarInterpreter/TestQBFile2.qbar
downloadLegacyQBar-5f3fb9afece2125cbeba79d61a8d88460b7878d7.tar.gz
LegacyQBar-5f3fb9afece2125cbeba79d61a8d88460b7878d7.tar.bz2
LegacyQBar-5f3fb9afece2125cbeba79d61a8d88460b7878d7.zip
initial commit
Diffstat (limited to 'project/QBarInterpreter/TestQBFile2.qbar')
-rw-r--r--project/QBarInterpreter/TestQBFile2.qbar60
1 files changed, 60 insertions, 0 deletions
diff --git a/project/QBarInterpreter/TestQBFile2.qbar b/project/QBarInterpreter/TestQBFile2.qbar
new file mode 100644
index 0000000..bbf58ee
--- /dev/null
+++ b/project/QBarInterpreter/TestQBFile2.qbar
@@ -0,0 +1,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() );
+} \ No newline at end of file