/* There really should be more tests for each of these functions: many cases have been left untested! */ // the grading function... (not built-in) // nor is this complete... undef(gr); gr( p ) => p > .95 ? "A"; gr( p ) => p > .90 ? "A-"; test( gr( .99 ), "A" ); // the factorial function // built-in, it's called "fac" undef(f); f( 0 ) => 1.0; f( x ) => x * f(x-1); test( f(5), 120 ); // the len function // built-in, it's called "length" undef(len); len( [] ) => 0; len( [f|R] ) => 1 + len(R); test( len([1,2,3]), 3 ); test( len([]), 0 ); // the min function // built-in, it's called "min" undef(min); min( [] ) => "Aargh! The empty list has no min!"; min( [e] ) => e; min( [f|R] ) => f < min(R) ? f : min(R); test( min([42]), 42 ); test( min([2,3,1,4]), 1 ); // the rmv1 function: removes only the _first_ e from L's top level // remarkably, remove is not built-in! undef(rmv1); rmv1( e, [] ) => []; rmv1( e, [e|R] ) => R; rmv1( e, [f|R] ) => [f | rmv1(e,R)]; test( rmv1( 1, [2,1,3,1] ), [2,3,1] ); // the app (append) function // append(L,M) _is_ built-in (and very useful!) undef(app); app( [], M ) => M; app( [f|R], M ) => [ f | app(R,M) ]; test( app( [1,2], [3,4] ), [1,2,3,4] ); // the mem (member) function // member(e, L) _is_ built-in (and also very useful!) undef(mem); mem( e, [] ) => 0; mem( e, [e|R] ) => 1; mem( e, [f|R] ) => mem(e,R); test( mem(1,[2,1,3]), 1 ); test( mem(42,[2,1,3]), 0 ); // the rev (reverse) function // reverse( L ) is also built-in (and moderately useful) undef(rev); rev( [] ) => []; rev( [f|R] ) => app( rev(R), [f] ); test( rev( [1,2,3,4] ), [4,3,2,1] );