15-150: Principles of Functional Programming

Lecture 15: Regular Expressions continued (Combinators)

Today, we discussed rewriting our regular expression matcher using combinators. Combinators help us separate the processing of the regular expression from the actual character matching and continuation-based control flow. This separation facilitates staging: The regular expression pattern matching is in one stage, the character and continuation functions are in another. One can thus produce a matcher for a regular expression without ever seeing any input or continuations.

For a review of staging see Lecture 11.

For the unstaged regular expression matcher see Lecture 14.

Sample Code

At the end of lecture, we returned to the problem of searching a tree for an element satisfying a predicate. We first examined that problem in Lecture 12, implemented as the search function. While implementing code to solve the n-Queens problem in Lecture 13, we observed that passing the failure continuation to the success continuation provided extra expressive power. For instance, a calling function can simply change the success continuation to obtain all solutions as opposed to a single solution.  Here is an illustration of that idea in a simple setting, namely finding an even integer in an  int tree.