I have an assignment where I need to take a tuple and return another tuple, of the same size, with certain elements changed. The problem is I don't know how to process a tuple of an undefined size. The function needs to be able to process tuples of any size. My idea was to make the tuple into a list that i could process much more easily, by making a recursive helper function to take element #1 of the tuple and cons it to a call to the same function which would give element #2 consed onto the recursion again until there are no elements left, but this just gives an error when i get to #n+1 where n is the total number of items in the tuple. Am I going about this the wrong way? is there a way to find the size of a tuple? is there a way to handle this error? I know about exception handling, but I'm not sure how to apply it to his case, if even possible.
the question is create a function named subst, such that subst (e’,x) e = [e’/x]e i.e. the function subst will replace any free occurrence of the variable x in the expression e' by the expression e. Add the appropriate case for tuples.