The SuRE programming framework
We illustrate the use of a declarative programming paradigm based upon three kinds of program clauses: equational, subset, and general relational clauses. The implemented language is called SuRE, which is an acronym for Subsets, Relations, and Equations. (To wit, SuRE is the affirmative answer to the question: Can programming be declarative and practical?) Subset clauses have many uses in the logic programming context: They serve as a declarative alternative to Prolog's mode declarations as well as those uses of assert and retract that correspond to implementations of memo-tables or collection of results from alternative search paths, as in the setof construct. By re-formulating a relation as a set-valued function, one not only specifies mode information declaratively,but also gains the flexibility of operating on the resulting set incrementally (by a membership goal) or collectively (by an equational goal). In the latter case, one further has the flexibility of working lazily or eagerly. We show that lazy enumeration of solutions is the key to declaratively pruning the search space in generate-and-test problems. Subset clauses and, more generally, partial-order clauses are also useful in the deductive database context, especially for defining setof operations, transitive closures and monotonic aggregation—the concepts of subset, aggregation and monotonicity are more naturally expressed in terms of functions than predicates. A central feature in the implementation of SuRE programs is that of a monotonic memo-table, i.e., a memo-table whose entries can monotonically grow or shrink in an appropriate partial order. The implementation of SuRE was developed as an extensionof the well-known Warren Abstract Machine (WAM) for Prolog. Even though SuRE differs substantially from Prolog, few additional instructions, registers, and storage structures are needed and these blend in well with the overall design of the WAM.