var list1 = cons(1, (cons (3, (cons(5, (cons(7, null))))))); console.assert(1 === car(list1), "car"); console.assert(3 === car(cdr(list1)), "cdr"); console.assert(atom(42) && atom(true) && atom(false) && atom({}) && atom("abc") && atom(NaN) && atom([1, 2]) && atom([]), "atom"); console.assert(!atom(list1) && !atom(null) && !atom(undefined), "not atom"); console.assert(pair(list1), "pair"); console.assert(!pair(42) && !pair(true) && !pair(false) && !pair({}) && !pair("abc") && !pair(NaN) && !pair([1, 2]) && !pair([]), "not pair"); console.assert("(1 3 5 7)" === "" + list1, "toString"); console.assert("(3 5 7)" === "" + cdr(list1), "cdr toString"); var list2 = list(1, 3, 6, 7); console.assert("(1 3 6 7)" === "" + list2, "list"); var times2 = function(x) {return 2 * x;}; console.assert("(2 6 10 14)" === "" + map(times2, list1), "map"); console.assert("hello" == foldl(function(a, b) {return a + b;}, "", list("h", "e", "l", "l", "o")), "foldl"); console.assert(12 == foldr(function(x, y) {return (x + y)/ 2;}, 54, list(12, 4, 10, 6)), "foldr"); var odd = function(n) {return !!(n % 2);}; var even = function(n) {return !(n % 2);}; console.assert("(2 4)" === "" + filter(even, list(1, 2, 3, 4, 5)), "filter"); console.assert("(1 2 3 4)" === "" + append(list(1, 2), list(3, 4)), "append"); console.assert("(7 5 3 1)" === "" + reverse(list1), "reverse"); console.assert(any(even, list2), "any even"); console.assert(!any(even, list1), "not any even"); console.assert(every(odd, list1), "every odd"); console.assert(!every(odd, list2), "not every odd"); var arr1 = asArray(list1); console.assert("[object Array]" === Object.prototype.toString.call(arr1), "asArray type"); console.assert("1,3,5,7" == arr1.toString(), "asArray"); console.assert(pair(asList(arr1)), "asList type"); console.assert("(1 3 5 7)" === "" + asList(arr1), "asList"); console.assert("ba" === flip(function(x, y) {return x + y;})("a", "b"), "flip"); var add = function(x, y) {return x + y}; var sumAll = lPartial(foldl, add, 0); console.assert(15 === sumAll(list(1, 2, 3, 4, 5)), "lPartial"); var mult = function(x, y) {return x * y;}; var firstFive = rPartial(foldl, list(1, 2, 3, 4, 5)); console.assert(15 === firstFive(add, 0) && 120 === firstFive(mult, 1), "rPartial"); console.assert(eq(list(1, 2, 3), list(1, 2, 3)), "eq"); console.assert(!eq(list(1, 2, 3), list(1, 2, 3, 4)), "not eq");