repositories
/
cc1516.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mergo
[cc1516.git]
/
examples
/
example.spl
diff --git
a/examples/example.spl
b/examples/example.spl
index
6cebe90
..
4a55e35
100644
(file)
--- a/
examples/example.spl
+++ b/
examples/example.spl
@@
-2,6
+2,10
@@
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 .
*/
+var r = 1;
+var facN = 1;
+var ok = True;
+
facR(n) :: Int -> Int {
if (n < 2) {
return 1;
facR(n) :: Int -> Int {
if (n < 2) {
return 1;
@@
-10,6
+14,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;
@@
-43,7
+48,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 {
@@
-73,7
+78,7
@@
swap(tuple) :: (a, a) -> (a, a){
}
//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 {
@@
-84,7
+89,7
@@
append(l1, l2) :: [t] [t] -> [t] {
//square the odd numbers in a list and remove the even members
squareOddNumbers(list) :: [Int] -> [Int] {
//square the odd numbers in a list and remove the even members
squareOddNumbers(list) :: [Int] -> [Int] {
- while(!isEmpty (list) && list.hd % 2=0){
+ while(!isEmpty (list) && list.hd % 2=
=
0){
list=list.tl;
}
if(!isEmpty(list)){
list=list.tl;
}
if(!isEmpty(list)){