/* part1.rex (for cs60 hw1, S09) Name: Comments to the graders: */ // Note the /* slash-star ... star-slash */ multi-line comments, used above // Rex also has single-line comments, like this one! // examples: fac (factorial), rev (reverse), and rmv1 (remove one element) // fun: fac( n ) // in: n, a nonnegative integer // out: the factorial of n as a floating-point value undef(fac); // redefines it each time... fac( 0 ) => 1.0; // base caseĀ  fac( n ) => n * fac( n-1 ); // recursive case test( fac(0), 1.0 ); test( fac(5), 120.0 ); // fun: rev( L ) // in: L, a list // out: a list with the same top-level elements in reverse order undef(rev); rev( [] ) => []; // base case rev( [f|R] ) => RR = rev(R), // recursive call, RR is "Reverse of R" append( RR, [f] ); // get f to the end // it would be equivalent to write // rev( [f|R] ) => append( rev(R), [f] ); // either would be OK. test( rev([]), [] ); test( rev([1,2,3]), [3,2,1] ); test( rev([[1,2,3]]), [[1,2,3]] ); // only one element! // fun: rmv1( e, L ) // in: e, an element; L, a list // out: a list like L with the first top-level e removed, if any undef( rmv1 ); rmv1( e, [] ) => []; // base case rmv1( e, [e|R] ) => R; // removing e from [e|R] rmv1( e, [f|R] ) => [f|rmv1(e,R)]; // recursive call, keeping f test( rmv1( 42, [] ), [] ); test( rmv1( 42, [1,2,42,42] ), [1,2,42] ); test( rmv1( 42, [1,2,[42]] ), [1,2,[42]] ); // not if nested // an example start-of-function comment for problem 1 // feel free to copy and alter this for the other functions, as well // pr: #1 // fun: pwr(b,p) // in: b - numeric base, p - nonnegative integer power // out: b**p (floating point!) undef( pwr );