From: pimjager Date: Thu, 9 Jun 2016 12:33:20 +0000 (+0200) Subject: Merge branch 'master' of https://github.com/dopefishh/cc1516 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=c5fb28639ae923d9b55f5832e45186911e610991;p=cc1516.git Merge branch 'master' of https://github.com/dopefishh/cc1516 --- c5fb28639ae923d9b55f5832e45186911e610991 diff --cc examples/factorize.spl index 0cecd10,0000000..d45ed1d mode 100644,000000..100644 --- a/examples/factorize.spl +++ b/examples/factorize.spl @@@ -1,63 -1,0 +1,63 @@@ +reverse (list) :: [Int] -> [Int] { + var accu = []; + while (! isEmpty (list)) { + accu = list . hd : accu; + list = list . tl; + } + return accu; +} + +coPrimeWith (elem, list) :: Int -> [Int] -> Bool { + if (isEmpty(list)) { + return True; + } else { + if (elem % list.hd == 0) { + return False; + } else { + return coPrimeWith(elem, list.tl); + } + } +} + +factorize (n) :: Int -> [Int] { + var primes = []; + var i = 2; + while (i < n) { + if (n % i == 0 && coPrimeWith(i, primes)) { + print("Found prime: ", i); + primes = i : primes; + } + i = i + 1; + } - return primes; ++ return primes;q +} + +print_list_inner (list) :: [Int] -> Void { + if (isEmpty(list)) { + return; + } else { + print(list.hd); + if (!isEmpty(list.tl)) { + print(','); + print(' '); + } + return print_list_inner(list.tl); + } +} + +print_list (list) :: [Int] -> Void { + print('['); + print_list_inner(list); + print(']'); + print(' +'); + return; +} + +main (){ + //var number = 692963517; + var number = 12000; + var result = reverse(factorize(number)); + print_list(result); + return; +} diff --cc examples/higher.spl index 75d5d9b,c5bac9e..59bbbf5 --- a/examples/higher.spl +++ b/examples/higher.spl @@@ -34,28 -34,18 +34,32 @@@ intList(x) } } +giveF(){ + return (\x->x+1); +} + - + plus(x, y){ - return x + y; ++ return x + y; + } main(){ var x = 5; - var a = plus(3); - print("3+5=", a(5)); + var f = giveF(); + + var plus = \x y->x+y; + + var g = map(plus, [1,2,3]); + var is = map(\f->f(1), g); + + //print("is.hd", is.hd); + + print("f(4) = ", f(4)); + + print("faculty of 5 is: ", foldr(\x y->x*y, 1, intList(5))); + print("sum of 1..5 is: ", foldr(\x y->x+y, 0, intList(5))); + print("sum of 0..12 but only the evens: ", + foldr(\x y->x+y, 0, filter(\x->x%2 == 0, intList(12)))); ++ + -// print("faculty of 5 is: ", foldr(\x y->x*y, 1, intList(5))); -// print("sum of 1..5 is: ", foldr(\x y->x+y, 0, intList(5))); -// print("sum of 0..12 but only the evens: ", -// foldr(\x y->x+y, 0, filter(\x->x%2 == 0, intList(12)))); }