summaryrefslogtreecommitdiff
path: root/reverse.icl
diff options
context:
space:
mode:
authorCamil Staps2016-11-10 10:54:07 +0000
committerCamil Staps2016-11-10 10:54:07 +0000
commit792a1840b61b2875ec8977eff579f15e23159713 (patch)
tree70ae73d251ba5db4d8d0505089b3658d7a8e357f /reverse.icl
parentFix pascal.icl (diff)
Made reverse, revtwice and sieve compile
Diffstat (limited to 'reverse.icl')
-rw-r--r--reverse.icl28
1 files changed, 26 insertions, 2 deletions
diff --git a/reverse.icl b/reverse.icl
index e2200b5..f3c7082 100644
--- a/reverse.icl
+++ b/reverse.icl
@@ -2,14 +2,38 @@ module reverse
// A list containing n elements will be reversed n times.
-import StdEnv
+//import StdEnv
+
+(<) infix 4 :: !Int !Int -> Bool
+(<) a b = code inline {
+ ltI
+}
+
+(+) infixl 6 :: !Int !Int -> Int
+(+) a b = code inline {
+ addI
+}
+
+(-) infixl 6 :: !Int !Int -> Int
+(-) a b = code inline {
+ subI
+}
+
+last :: [a] -> a
+last [x] = x
+last [_:xs] = last xs
+
+fromto :: !Int !Int -> [Int]
+fromto a b
+| b < a = []
+| otherwise = [a:fromto (a+1) b]
NrOfTimes :== 1000
// Reversing a list of n integers n times.
MyReverse::Int -> Int
-MyReverse n = last (Rev_n n [1..n])
+MyReverse n = last (Rev_n n (fromto 1 n))
where
Rev_n::Int [Int] -> [Int]
Rev_n 1 list = Rev list []