Using the functions presented in this section, along with arithmetic, give a one-line rex definitions of the following function:
infix(I, J, L) yields elements I through J of list L, where the first element is counted as element 0. For example,
rex > infix(1, 5, range(0, 10));
[1, 2, 3, 4, 5]
Create the function infix by first clipping off the unnecessary values at the end of list L using the antiprefix function and inputted value J. Then by using the prefix function with inputted values I and J you can clip off the unnecessary values at the beginning of list L, leaving only the specified range of values in between.
rex> infix(I,J,L)=prefix(J-I+1,antiprefix(I,L));
An identity on two functional expressions indicates that the two sides of the expression are equal for all arguments on which one of the two sides is defined. Which of the following identities are correct?
append(L, append(M, N)) == append(append(L, M), N)
Correctreverse(reverse(L)) == L
Correctreverse(append(L, M)) == append(reverse(L), reverse(M))
Incorrectsort(append(L, M)) == append(sort(L), sort(M))
Incorrectreverse(sort(L)) == reverse(L)
Incorrectsort(reverse(L)) == sort(L)
Correct[A | append(L, M)] == append([A | L], M)
Correctreverse([A | L]) == [A | reverse(L)]
Incorrectreverse([A | L]) == [reverse(L) | A]
Incorrectreverse([A | L]) == append(reverse(L), [A])
Correct
Two functions of a single argument are said to commute provided that for every argument value X, we have f(g(X)) == g(f(X)). Which pairs of functions commute?
sort and remove_duplicates
Commutesreverse and remove_duplicates
Does not commutesort and reverse
Does not commute
Return |