repositories
/
cc1516.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
hoi
[cc1516.git]
/
examples
/
example.spl
diff --git
a/examples/example.spl
b/examples/example.spl
index
b4efb27
..
0387810
100644
(file)
--- a/
examples/example.spl
+++ b/
examples/example.spl
@@
-2,6
+2,7
@@
Three ways to implement the f acto rial function in SPL.
First the recursive version .
*/
Three ways to implement the f acto rial function in SPL.
First the recursive version .
*/
+
facR(n) :: Int -> Int {
if (n < 2) {
return 1;
facR(n) :: Int -> Int {
if (n < 2) {
return 1;
@@
-10,6
+11,7
@@
facR(n) :: Int -> Int {
}
}
}
}
+
//The iterative version of the factorial function
facl ( n ) :: Int -> Int {
var r = 1;
//The iterative version of the factorial function
facl ( n ) :: Int -> Int {
var r = 1;
@@
-28,12
+30,12
@@
main ( ) :: Void {
var ok = True;
while(n<20) {
facN = facR (n);
var ok = True;
while(n<20) {
facN = facR (n);
- if (facN != factl (n) || fac
n
!= facL (n)){
+ if (facN != factl (n) || fac
N
!= facL (n)){
print (n : facN : facl (n) : facL (n): []);
ok=False;
}
}
print (n : facN : facl (n) : facL (n): []);
ok=False;
}
}
- print(ok);
+
//
print(ok);
}
// A list based factorial function
}
// A list based factorial function
@@
-43,7
+45,7
@@
facL (n) :: Int -> Int {
}
//Generates a list of integers from the first to the last argument
}
//Generates a list of integers from the first to the last argument
-fromTo (from, to) :: Int Int -> [Int] {
+fromTo (from, to) :: Int
->
Int -> [Int] {
if(from <= to){
return from:fromTo(from+1, to);
} else {
if(from <= to){
return from:fromTo(from+1, to);
} else {
@@
-65,15
+67,15
@@
reverse(list):: [t] -> [t] {
abs(n)::Int->Int{if(n<0)return -n; else return n;}
//swap the elements in a tuple
abs(n)::Int->Int{if(n<0)return -n; else return n;}
//swap the elements in a tuple
-swap(tuple) :: (a, a) -> (a, a){
-
var tmp = tuple.fst;
-
tuple.fst = tuple.snd;
-
tuple.snd = tmp;
-
return tuple;
-}
+
//
swap(tuple) :: (a, a) -> (a, a){
+
//
var tmp = tuple.fst;
+
//
tuple.fst = tuple.snd;
+
//
tuple.snd = tmp;
+
//
return tuple;
+
//
}
//list append
//list append
-append(l1, l2) :: [t] [t] -> [t] {
+append(l1, l2) :: [t]
->
[t] -> [t] {
if(isEmpty(l1)){
return l2;
} else {
if(isEmpty(l1)){
return l2;
} else {