diff options
author | Camil Staps | 2016-11-10 10:54:07 +0000 |
---|---|---|
committer | Camil Staps | 2016-11-10 10:54:07 +0000 |
commit | 792a1840b61b2875ec8977eff579f15e23159713 (patch) | |
tree | 70ae73d251ba5db4d8d0505089b3658d7a8e357f /reverse.icl | |
parent | Fix pascal.icl (diff) |
Made reverse, revtwice and sieve compile
Diffstat (limited to 'reverse.icl')
-rw-r--r-- | reverse.icl | 28 |
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 [] |