Problem 4.1.1: Pair Abstraction (150pts)

Define function pair which takes in two elements and returns a function that works as a pair. You will use functions fst and snd to retrieve the values.

def fst(p):
    return p(0)

def snd(p):
    return p(1)

def pair(x, y):
    """Return a function that represents a pair.
    
    >>> p = pair(1, 2)
    >>> fst(p)
    1
    >>> snd(p)
    2
    """

Now defines two functions change_fst and change_snd that modify the pair.

def change_fst(p, v):
    """Change pair p's first element into v and return it.

    >>> p = pair(1, 2)
    >>> fst(p)
    1
    >>> snd(p)
    2
    >>> p = change_fst(p, 3)
    >>> fst(p)
    3
    >>> snd(p)
    2
    """
def change_snd(p, v):
    """Change pair p's second element into v and return it.

    >>> p = pair(1, 2)
    >>> fst(p)
    1
    >>> snd(p)
    2
    >>> p = change_snd(p, 3)
    >>> fst(p)
    1
    >>> snd(p)
    3
    """