TY - GEN
T1 - A Predicate Construct for Declarative Programming in Imperative Languages
AU - Smith, James
AU - Guo, Xiangyu
AU - Bansal, Ajay
N1 - Publisher Copyright:
© 2022 ACM.
PY - 2022/9/20
Y1 - 2022/9/20
N2 - 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.
AB - 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.
KW - declarative programming
KW - imperative programming
KW - logic programming
KW - predicate
UR - http://www.scopus.com/inward/record.url?scp=85139596380&partnerID=8YFLogxK
UR - http://www.scopus.com/inward/citedby.url?scp=85139596380&partnerID=8YFLogxK
U2 - 10.1145/3551357.3551379
DO - 10.1145/3551357.3551379
M3 - Conference contribution
AN - SCOPUS:85139596380
T3 - ACM International Conference Proceeding Series
BT - Proceedings of the 24th International Symposium on Principles and Practice of Declarative Programming, PPDP 2022 - Co-located with CLAS 2022 (including LOPSTR 2022)
PB - Association for Computing Machinery
T2 - 24th International Symposium on Principles and Practice of Declarative Programming, PPDP 2022
Y2 - 20 September 2022 through 22 September 2022
ER -