More on accumulate_list_lr Example: - All of the functions discussed below are in the DEMO. - accumulate_list_lr_2 uses recursion to construct functions to perform the shared operations of build up a list in some way that involves an accumulation operation, initial value, and an input list. - lambda can be used to represent the return value of a function-generating function, without having to explicitly use define and a name. In this example, the function accumulate_list_lr_3 does the same thing as the second version, but uses a lambda definition instead of defining resultfun. Note the differences in the DEMO. - There is yet another even higher-order method of tackling this problem. Check out generic_accumulate_list_lr in the DEMO. This function takes pretty much everything as arguments, including even the empty_test conditional expression. It uses a recursive call to produce separate functions for successive starting values. - The reverse_list and stringlist->string functions can be defined using just the generic function, but it is a bit more transparent to definite yet another accumulate_list_lr_4 that performs the same as the previous version, but instead implements the generic function. Higher-Order Programming in the PAC: - In Assignment #4 we use a construct similar to the generic_accumulate_lr function discussed above to definite a generic_evaluate_formula function. It takes all information associated with evaluating a formula as arguments, performs the operations shared to every evaluation process, and produces the result of the evaluation. The call to this generic_evaluate_formula gets done in M-evaluate_formula. The operator->formula function defined therein uses an operator lookup table, defined as operator_table. The implementation of this uses the function make_immutable_hash_table, which indexes the formulae associated with an operator by the operator itself. In the language of such objects, the operator is the 'key' and the evaluation function for that operator is the associated 'value' for that key. This implementation is an easier, more sophisticated option to writing a huge condition to handle such a mapping from operator to formula. The entries of the table are retrieved by calling hash_table_get for a specific key, which is in this case an operator.