A Predicate Construct for Declarative Programming in Imperative Languages

James Smith, Xiangyu Guo, Ajay Bansal

Research output: Chapter in Book/Report/Conference proceedingConference contribution

Abstract

Imperative and object-oriented programming languages are among the most common languages for general-purpose programming. These languages work well for handling many common tasks necessary for most applications. However, there are still many hard problems that remain difficult to implement directly in imperative languages. Declarative languages have worked well for solving many of these problems by providing a syntax that allows the user to focus on modeling the problem rather than on designing an algorithm. Logic programming languages, like Prolog, have seen success in constraint satisfaction problems, logical databases, and various NP-Hard problems. Unfortunately, these languages have not seen the same success in general-purpose programming, and most of the problems they solve do not exist in isolation. Furthermore, many imperative programmers are still unfamiliar with and unaware of logic programming. In this work, we aim to integrate a logical predicate, borrowed from logic programming, into an imperative language to facilitate a model-based approach to programming. Rather than attempting to embed Prolog directly into the language, we provide a logic for reasoning over imperative expressions using the common Boolean operators familiar to imperative programmers. While logic programming relies on unification, our predicate relies on variable assignment which is standard in imperative languages. We have implemented the predicate into the syntax of the Python programming language along with a solver built into the runtime for solving queries on the predicate. We demonstrate the use of the construct through solving commonly-known problems, such as graph coloring and the N-Queens problem. To evaluate the viability of our predicate, we compare the performance results of our predicate against current implementations of Prolog. By bringing this predicate construct to imperative languages, it is our hope that we can help to bridge the gap between imperative and logic programming as well as provide an approach to logic programming that is more intuitive for imperative programmers.

Original languageEnglish (US)
Title of host publicationProceedings of the 24th International Symposium on Principles and Practice of Declarative Programming, PPDP 2022 - Co-located with CLAS 2022 (including LOPSTR 2022)
PublisherAssociation for Computing Machinery
ISBN (Electronic)9781450397032
DOIs
StatePublished - Sep 20 2022
Event24th International Symposium on Principles and Practice of Declarative Programming, PPDP 2022 - Virtual, Online, Georgia
Duration: Sep 20 2022Sep 22 2022

Publication series

NameACM International Conference Proceeding Series

Conference

Conference24th International Symposium on Principles and Practice of Declarative Programming, PPDP 2022
Country/TerritoryGeorgia
CityVirtual, Online
Period9/20/229/22/22

Keywords

  • declarative programming
  • imperative programming
  • logic programming
  • predicate

ASJC Scopus subject areas

  • Human-Computer Interaction
  • Computer Networks and Communications
  • Computer Vision and Pattern Recognition
  • Software

Fingerprint

Dive into the research topics of 'A Predicate Construct for Declarative Programming in Imperative Languages'. Together they form a unique fingerprint.

Cite this