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 higher-level 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.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Extending the FSyntax/Hiord Approach with Imperative Notation

  • Paula Corral,
  • Jose F. Morales,
  • Pedro Lopez-Garcia,
  • Manuel V. Hermenegildo

摘要

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 higher-level 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.