Using the previous definition, a function should consists of three parts. First is the list of formal arguments, which we must bind before we can evaluate the function. The second part is a Q-Expression that represents the body of the function. Finally we require a location to store the values assigned to the formal arguments. Luckily we already have a structure for storing variables, an environment.

    We will store our builtin functions and user defined functions under the same type LVAL_FUN. This means we need a way internally to differentiate between them. To do this we can check if the lbuiltin function pointer is NULL or not. If it is not we know the lval is some builtin function, otherwise we know it is a user function.

    We also need to create a constructor for user defined lval functions. Here we build a new environment for the function, and assign the formals and body values to those passed in.

    As with whenever we change our type we need to update the functions for deletion, copying, and printing to deal with the changes. For evaluation we’ll need to look in greater depth.

    For Copying

    For Printing