State variables, loops, and other features of imperative programming languages can bring coding simplification for certain programming idioms that are more cumbersome to express recursively. Because of this, some logic programming systems have incorporated various imperative constructs. FSyntax is a syntactic approach to supporting functional notation in Prolog systems which is based on the use of the syntax and term expansion facilities of the language. Hiord is also a syntactic approach to supporting higher-order in Prolog, building on call/n, and adding other features such as anonymous predicates. Both are used extensively, for example, in the Ciao Prolog system. In this paper, we propose a number of imperative-style constructs based on extending FSyntax and Hiord. These extensions are designed to combine nicely with the basic functional notation and the higher-order facilities, as well as with other extensions, such as constraints. In contrast to other proposals, our approach provides a set of primitives and a higherlevel mechanism that, together, allow users to easily extend the language with features such as array notation, state variables, loops, etc. We illustrate the approach by defining a set of such features and using them to translate idiomatically in imperative style a large collection of small but interesting programs from the Euler Project, for which imperative-style implementations are available in multiple languages. We also show that the approach offers competitive performance.
State variables, loops, and other features of imperative programming languages can bring coding simplification for certain programming idioms that are more cumbersome to express recursively. Because of this, some logic programming systems have incorporated various imperative constructs. FSyntax is a syntactic approach to supporting functional notation in Prolog systems which is based on the use of the syntax and term expansion facilities of the language. Hiord is also a syntactic approach to supporting higher-order in Prolog, building on call/n, and adding other features such as anonymous predicates. Both are used extensively, for example, in the Ciao Prolog system. In this paper, we propose a number of imperative-style constructs based on extending FSyntax and Hiord. These extensions are designed to combine nicely with the basic functional notation and the higher-order facilities, as well as with other extensions, such as constraints. In contrast to other proposals, our approach provides a set of primitives and a higherlevel mechanism that, together, allow users to easily extend the language with features such as array notation, state variables, loops, etc. We illustrate the approach by defining a set of such features and using them to translate idiomatically in imperative style a large collection of small but interesting programs from the Euler Project, for which imperative-style implementations are available in multiple languages. We also show that the approach offers competitive performance. Read More


