Merge branch 'master' of https://github.com/dopefishh/cc1516
authorpimjager <pim@pimjager.nl>
Thu, 9 Jun 2016 12:33:20 +0000 (14:33 +0200)
committerpimjager <pim@pimjager.nl>
Thu, 9 Jun 2016 12:33:20 +0000 (14:33 +0200)
1  2 
examples/factorize.spl
examples/higher.spl

index 0cecd10,0000000..d45ed1d
mode 100644,000000..100644
--- /dev/null
@@@ -1,63 -1,0 +1,63 @@@
-     return primes;
 +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;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;
 +}
@@@ -34,28 -34,18 +34,32 @@@ intList(x)
        }
  }
  
 +giveF(){
 +    return (\x->x+1);
 +}
 +
 -      return x + y;
+ plus(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))));
  }