Python and Prolog express different programming paradigms, with different strengths. Python is wildly popular because it is well-structured, easy to use, and mixes well with thousands of scientific and machine learning programs written in C. Prolog's logic-based approach provides powerful reasoning capabilities, especially when combined with constraint evaluation, probabilistic reasoning, well-founded negation, and other advances. Both languages have commonalities as well: both are usually written in C, both are dynamically typed, and both use data structures based on a small number of recursive types. This paper describes the design and implementation of Janus, a system that tightly combines Prolog and Python into a single process. Janus bi-translates data structures and offers performance of many hundreds of thousands of round-trip inter-language calls per second. Although Janus is still new, it has been used in commercial applications including natural language processing, visual query answering and robotic automation. Janus was developed for XSB, but porting Janus code to a second Prolog has been straightforward, indicating that Janus is a tool that other Prologs may easily adopt.
翻译:Python和Prolog表达了不同的编程范式,各有优势。Python因其结构良好、易于使用,并能与数千个用C语言编写的科学和机器学习程序良好结合而广受欢迎。基于逻辑的Prolog方法提供了强大的推理能力,尤其是在结合约束求值、概率推理、良基否定及其他进展时。这两种语言也有共同点:它们通常用C语言编写,都是动态类型语言,并且都使用基于少量递归类型的数据结构。本文描述了Janus系统的设计与实现,该系统将Prolog和Python紧密集成到单个进程中。Janus支持数据结构的双向转换,并提供了每秒数十万次跨语言调用往返的性能。尽管Janus尚属新生,但已被应用于包括自然语言处理、视觉查询回答和机器人自动化在内的商业应用中。Janus起初是为XSB开发的,但将Janus代码移植到第二个Prolog系统时非常直接,这表明Janus是一种易于被其他Prolog系统采纳的工具。