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 /revtwice.icl | |
parent | Fix pascal.icl (diff) |
Made reverse, revtwice and sieve compile
Diffstat (limited to 'revtwice.icl')
-rw-r--r-- | revtwice.icl | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/revtwice.icl b/revtwice.icl index e5186d4..31379ec 100644 --- a/revtwice.icl +++ b/revtwice.icl @@ -3,13 +3,33 @@ module revtwice /* Reversing a list a number of times using Twice. -Increase stack size to 1m and heap size to 2m to run this program. +Increase stack size to 1m and heap size to 4m to run this program. A list containing 25 integers is reversed 65536 times by means of four applications of the higher order function Twice. */ -import StdInt, StdEnum +(<) 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 +} + +fromto :: !Int !Int -> [Int] +fromto a b +| b < a = [] +| otherwise = [a:fromto (a+1) b] + +//import StdInt, StdEnum Revv:: [Int] -> [Int] Revv l = Rev l [] @@ -22,5 +42,5 @@ Twice::(x -> x) x -> x Twice f x = f (f x) Start::[Int] -Start = Twice Twice Twice Twice Revv [1..25] +Start = Twice Twice Twice Twice Revv (fromto 1 25) |