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.
- Analía Amandi, Marcelo Campo, and Alejandro Zunino. 2005. JavaLog: a framework-based integration of Java and Prolog for agent-oriented programming. Computer languages, systems & structures 31, 1 (2005), 17–33.Google Scholar
- Krzysztof Apt, J Brunekreef, V Partinton, and A Schaerf. 1998. Alma-0: An imperative language thet supports declarative programming. ACM transactions on programming languages and systems 20, 5 (1998), 1014–1066.Google Scholar
- Krzysztof R. Apt and Andrea Schaerf. 1997. Search and Imperative Programming. In Proceedings of the 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Paris, France) (POPL ’97). Association for Computing Machinery, New York, NY, USA, 67–79. https://doi.org/10.1145/263699.263709Google ScholarDigital Library
- Krzysztof R. Apt and Andrea Schaerf. 1999. The Alma Project, or How First-Order Logic Can Help Us in Imperative Programming. https://doi.org/10.48550/ARXIV.CS/9907027Google Scholar
- Krzysztof R. Apt and M. H. van Emden. 1982. Contributions to the Theory of Logic Programming. J. ACM 29, 3 (jul 1982), 841–862. https://doi.org/10.1145/322326.322339Google ScholarDigital Library
- M. A. (Max A.) Bramer. 2005. Logic programming with Prolog. Springer, New York.Google Scholar
- T.A Budd. 1991. Blending imperative and relational programming. IEEE software 8, 1 (1991), 58–65.Google ScholarDigital Library
- Wolfgang Dvořák, Georg Gottlob, Reinhard Pichler, and Stefan Woltran. 2009. Alternation as a Programming Paradigm. In Proceedings of the 11th ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (Coimbra, Portugal) (PPDP ’09). Association for Computing Machinery, New York, NY, USA, 61–72. https://doi.org/10.1145/1599410.1599419Google ScholarDigital Library
- Michael Gelfond. 2008. Chapter 7 Answer Sets. In Foundations of Artificial Intelligence. Vol. 3. Elsevier, Amsterdam, 285–316.Google Scholar
- Sergio Greco. 2016 - 2016. Datalog and logic databases. Morgan & Claypool Publishers, San Rafael, California.Google Scholar
- John Harrison. 1996. Optimizing proof search in model elimination. In International Conference on Automated Deduction. Springer, Springer Berlin Heidelberg, Berlin, Heidelberg, 313–327.Google ScholarCross Ref
- Vladimir. Lifschitz. 2019. Answer Set Programming(1st ed. 2019. ed.). Springer International Publishing, Cham.Google Scholar
- P.D. Lincoln and N. Shankar. 1994. Proof search in first-order linear logic and other cut-free sequent calculi. In Proceedings Ninth Annual IEEE Symposium on Logic in Computer Science. IEEE, Paris, France, 282–291. https://doi.org/10.1109/LICS.1994.316061Google ScholarCross Ref
- J. W. (John Wylie) Lloyd. 1987. Foundations of logic programming(2nd, extended ed. ed.). Springer-Verlag, Berlin ;.Google Scholar
- Kim Marriott, Peter J Stuckey, and Mark Wallace. 2006. Constraint Logic Programming. In Foundations of Artificial Intelligence. Vol. 2. Elsevier Science & Technology, Oxford, 409–452.Google Scholar
- Leonardo de Moura and Nikolaj Bjørner. 2008. Z3: An efficient SMT solver. In International conference on Tools and Algorithms for the Construction and Analysis of Systems. Springer, Springer Berlin Heidelberg, Berlin, Heidelberg, 337–340.Google ScholarCross Ref
- Python. 2021. Python 3.9.5 Documentation. https://docs.python.org/3.9/ Accessed: 2021-05-12.Google Scholar
- python constraint. 2021. python-constraint: Constraint Solving Problem resolver for Python. https://github.com/python-constraint/python-constraint Accessed on: Oct. 12, 2021.Google Scholar
- Dimitri Racordon and Didier Buchs. 2020. LogicKit: bringing logic programming to swift. In Conference Companion of the 4th International Conference on art, science, and engineering of programming(20). ACM, New York, NY, USA, 13–16.Google ScholarDigital Library
- A Radensky. 1990. Toward integration of the imperative and logic programming paradigms: Horn-clause programming in the Pascal environment. SIGPLAN notices 25, 2 (1990), 25–34.Google Scholar
- James Smith, Chris Henderson, and Ajay Bansal. 2021. Integrating a General Search Agent into an Imperative Programming Language. In 2021 IEEE Fourth International Conference on Artificial Intelligence and Knowledge Engineering (AIKE). IEEE, 54–61.Google ScholarCross Ref
- Leon. Sterling. 1994. The art of Prolog : advanced programming techniques (2nd ed. ed.). MIT Press, Cambridge, Mass.Google Scholar
- Joost Vennekens. 2016. Lowering the Learning Curve for Declarative Programming: A Python API for the IDP System. In Practical Aspects of Declarative Languages(Lecture Notes in Computer Science). Springer International Publishing, Cham, 86–102.Google Scholar
- Jan Wielemaker, Tom Schrijvers, Markus Triska, and Torbjörn Lager. 2012. SWI-Prolog. Theory and Practice of Logic Programming 12, 1-2 (2012), 67–96.Google ScholarDigital Library
Index Terms
- A Predicate Construct for Declarative Programming in Imperative Languages
Recommendations
Alma-O: an imperative language that supports declarative programming
We describe here an implemented small programming language, called Alma-O, that augments the expressive power of imperative programming by a limited number of features inspired by the logic programming paradigm. These additions encourage declarative ...
Blending Imperative and Relational Programming
When imperative (value- or state-oriented) programming and logical (relation-oriented) programming are combined into a single language, the combination is even more powerful than when either technique is used alone. Leda, a strongly typed compiled ...
General-purpose multiparadigm programming languages: an enabling technology for constructing complex systems
ICECCS '95: Proceedings of the 1st International Conference on Engineering of Complex Computer SystemsMultiparadigm programming languages have been envisioned as a vehicle for constructing large and complex heterogeneous systems, such as a stock market exchange or a telecommunications network. General-purpose multiparadigm languages, as opposed to ...
Comments