From: Mart Lubbers Date: Wed, 1 Jun 2016 20:00:26 +0000 (+0200) Subject: updates:) X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=6da7f23e5a09f6237e608ddfa096aa48b4e707ca;p=cc1516.git updates:) --- diff --git a/examples/higher.spl b/examples/higher.spl index 2f91e2e..61413c1 100644 --- a/examples/higher.spl +++ b/examples/higher.spl @@ -1,45 +1,80 @@ -map(f, l){ - if(isEmpty(l)){ - return []; - } else { - return f(l.hd) : map(f, l.tl); - } -} - -foldr(f, acc, l){ - if(isEmpty(l)){ - return acc; - } else { - return foldr(f, f(acc, l.hd), l.tl); - } -} +//map(f, l){ +// if(isEmpty(l)){ +// return []; +// } else { +// return f(l.hd) : map(f, l.tl); +// } +//} +// +//foldr(f, acc, l){ +// if(isEmpty(l)){ +// return acc; +// } else { +// return foldr(f, f(acc, l.hd), l.tl); +// } +//} +// +//filter(f, l){ +// if(isEmpty(l)){ +// return []; +// } else { +// if(f(l.hd)){ +// return filter(f, l.tl); +// } else { +// return l.hd : filter(f, l.tl); +// } +// } +//} +// +//intList(x){ +// if(x <= 1){ +// return [x]; +// } else { +// return x : intList(x-1); +// } +//} -filter(f, l){ - if(isEmpty(l)){ - return []; - } else { - if(f(l.hd)){ - return filter(f, l.tl); - } else { - return l.hd : filter(f, l.tl); - } - } +plus(x, y){ + return x + y; } -intList(x){ - [Int] l = []; - Int a = 1; - while(a <= x){ - l = a : l; - a = a + 1; - } - return l; +apply(f, x){ + return f(x); } main(){ - 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("filter evens from 0..12 is: "); - 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("filter evens from 0..12 is: "); +// print("sum of 0..12 but only the evens: ", +// foldr(\x y->x+y, 0, filter(\x->x%2 == 0, intList(12)))); + + var a = plus(3); + var b = apply(a); + var c = apply(b); + var d = apply(c); + var e = apply(d); + var f = apply(e); + var g = apply(f); + var h = apply(g); + var i = apply(h); + var j = apply(i); + var k = apply(j); + var l = apply(k); + var m = apply(l); + var n = apply(m); + var o = apply(n); + var p = apply(o); + var q = apply(p); + var r = apply(q); + var s = apply(r); + var t = apply(s); + var u = apply(t); + var v = apply(u); + var w = apply(v); + var x = apply(w); + var y = apply(x); + var z = apply(y); + + print("3+5=", z(5)); } diff --git a/examples/peano.spl b/examples/peano.spl index 73916b0..1c2cb78 100644 --- a/examples/peano.spl +++ b/examples/peano.spl @@ -8,13 +8,9 @@ hyper(n, a, b){ } main(){ - var plus = hyper(2); - var times = hyper(3); - var power = hyper(4); - var arrow = hyper(5); - - print("2 + 4 = ", plus(2, 4)); - print("2 * 4 = ", times(2, 4)); - print("2 ^ 4 = ", power(2, 4)); - print("3 | 2 = ", arrow(3, 2)); + print("s(3)=", hyper(0, 3, 3)); + print("3+3=", hyper(1, 3, 3)); + print("3*3=", hyper(2, 3, 3)); + print("3^4=", hyper(3, 3, 4)); + print("2|3=", hyper(4, 2, 3)); } diff --git a/examples/printparse.spl b/examples/printparse.spl index 6ac6199..1712b73 100644 --- a/examples/printparse.spl +++ b/examples/printparse.spl @@ -79,5 +79,5 @@ printInt(x) { main(){ var num = "-1234"; - printList(printInt, 32 : 4 : strToInt(num) : []); + printList(printInt, [32, 4, strToInt(num)]); }