Bridging the Gap Between Object-Oriented and Logic Programming Timothy Koschmann Southern Illinois University Carbondale

Bridging the Gap Between Object-Oriented and Logic Programming Timothy Koschmann Southern Illinois University Carbondale

Southern Illinois University Carbondale OpenSIUC Publications Department of Medical Education 7-1988 Bridging the Gap between Object-oriented and Logic Programming Timothy Koschmann Southern Illinois University Carbondale Martha Walton Evans Illinois Institute of Technology Follow this and additional works at: http://opensiuc.lib.siu.edu/meded_pubs ©1988 IEEE. Published in IEEE Software, Vol. 5, Issue 4 (July 1988) at 10.1109/52.17800 Personal use of this material is permitted. However, permission to reprint/republish this material for advertising or promotional purposes or for creating new collective works for resale or redistribution to servers or lists, or to reuse any copyrighted component of this work in other works must be obtained from the IEEE. This material is presented to ensure timely dissemination of scholarly and technical work. Copyright and all rights therein are retained by authors or by other copyright holders. All persons copying this information are expected to adhere to the terms and constraints invoked by each author's copyright. In most cases, these works may not be reposted without the explicit permission of the copyright holder. Recommended Citation Koschmann, Timothy and Evans, Martha W. "Bridging the Gap between Object-oriented and Logic Programming." (Jul 1988). This Article is brought to you for free and open access by the Department of Medical Education at OpenSIUC. It has been accepted for inclusion in Publications by an authorized administrator of OpenSIUC. For more information, please contact [email protected]. .. ... .. .. -. .. .. .. .. ~~ . .--. LANGUAGE INTERFACE between Logic Programming Timothy Koschmann, Xerox A/ Systems Mardha Walton EvenS. lllinois lnstitute of Technology ajectaiented and n recent years, many programmers chronological backtracking and pattern have begun to experiment with alter- matching viaunification. Prolog'sdeclara- Iogk progkamming native programming styles. Object- tive style provides a natural way to repre- each have dvantqges. oriented and logic programming have at- sent rule-based knowledge. Unfor- tracted growing interest among software tunately, Prolog also has deficiencies: Its lhis interface bridges designers, particularly among those work- declarative style is clumsy for tasks that are the two Wles, ing on knowledge-based applications. implicitly procedural in nature, such as lettingyou take equal Both styles of programming offer real prompting a user for a series of pieces of advantages over traditional programming information. Also, because Prolog isa rela- advan&ge ofboth. methods. tively new language in the US, it does not Object-oriented programming is partic- yet have a library of routines for graphics, ularly useful for problems in which data manipulating windows, creating menus, objects can be categorized hierarchically. or monitoring mouse events. The notions of inheritance and data en- The best solution would seem to be one capsulation encourage astructured imple- where you could use object-oriented and mentation style and enhance the main- logic programming in a common applica- tainability of programs. But object- tion, using each forwhat it does best. This oriented environments lack generalized is the philosophy behind the notion of facilities for deductive retrieval and pat- multiparadigm programming.' The ques tern matching, functions that are basic to tion that must be addressed is how you most knowledge-based applications. combine object-oriented and logic pro On the other hand, logic programming gramming so the best features of each par- languages like Prolog have built-in facili- adigm are preserved. (The box on p. 39 ties for deductive retrieval through describes each style.) 36 074Ck7459/88/0700/0036/!$01 .oO 0 1988 IEEE IEEE Software One strategymight be to implement one outside the Prolog database. cause both sets of microcode are resident paradigm in the other, either by imple- You may use each layer independently. at all times, there is no special overticad as- menting objects in an existing logic en- For example, in some applications, there sociated with decoding Prolog instruc- vironment or by implementing a Prolog- may be no need for clause objects or Pro- tions versus Lisp instructions. To the pro- like search facility in an object-oriented log methods - but the ability to manipu- grammer, Lisp and Prolog appear to be environment. Both approaches have been late Loops objects from the Prolog en- two separate worlds, each with its own tried: vironment may still be valuable. name spaces and syntactical rules. Access There are several ways to implement My colleagues and I at Xerox AI Systems to the Lisp world from Prolog is achieved objects in a logic programming frame- used the interface to implement Rotamer, through built-in predicates that let you in- work. For example, Malpas has described a fairly complex knowledge-based applica- voke Lisp functions while in Prolog and a technique for implementing classes, in- ti~n.~Rotamer uses a truth-maintenance capture the returned results. stances, methods, and inheritance in Pro- system (implemented with Prolog meth- The Xerox Quintus Prolog/I.isp inter- log.? ods) to cache information acquired in the face was readily extensible to provide a The Xerox Palo Alto Research Center course of exploring a large search space. Prolog/Loops interface. The principle of has tried the opposite approach of provid- Our earlyconcernswere that the overhead data encapsulation that underlies object- ing logical variables and backtracking caused by the calling between Lisp and or i e n te d programming d ra rn a t i ca I1 y search in an object-based system: The Prolog would lead to major performance simplified the task ofwriting an interface Common Log system was designed to pre to the Loops system. In Loops, everything vide the features of a Prolog-like language is represented as objects. All communi- implemented on top of the Common Lisp cation to and from Loopsobjects, with the Object Specification. Our earlyconcerns were exception of some low-level data-access There is a third approach: an interface that the ovechead routines, occurs through the message between an existing object-based system between Lisp and Prolog sending mechanism. and a logic-basedsystem. Abbott calls such Therefore, only a little coding i I re- an interface a Boolean bridge.3 There are would cause mdor perfiormance prublems. quired to provide the Prolog progr? mmer two advantages to creating such a bridge: the full range of capabilities to maiipulate First, you can access all the support tools of These fears were the Loopsobjectsavailable to the Lispprtr both environments. Second, there is no gloundless. grammer. A set of predicates is required so degradation of performance due to one the Prolog programmer can retrieve the language being implemented top of contents of an object’s slots, insert new another. values into the slots of a specified object, problems. These fears proved to be This article describes an interface that and send messages to an object. This func- groundless. On the Xerox Lisp Machine, was developed between Loops4and Xerox tionality is provided through three Prolog the cost in machine cycles for a call to a Quintus Prolog. Loops is an extension to procedures: get_value/3, put_value/3, Lisp function from Prolog is only slightly the Xerox AI Environment to support ob and send_message/4. ject-oriented programming; Xerox Quin- more expensive than a simple function Using the Loops access predicates, the tus Prolog is a version of Prolog that runs call in Lisp. Prolog programmer can easily create ob on Xerox Lisp Machines. jects, manipulate the contents of object The interface has three layers. At the AccessingLoopsfrom slots, and execute object methods. For ex- lowest level, a set of Prolog predicatesgives Prolog ample, you could use the following Prolog the Prolog programmer access to Loops Figure 1 shows how Prolog is imple- procedure to perform a slot-value substi- objects. This lowest level is the bridge from mented on the Xerox Lisp Machine. In tution in a Loops object: Prolog to Loops. At the next level, pro- this implementation, Prolog and Lisp gramming tools in the Loops environ- each have their own set ofmicrocode. The substitute-slot-value (Object,Slot, ment letobjectmethodsbedefinedinPro- microcode sets are stored in two different Old-value,New-value) :- get-value (Object,Slot,Old-value), log. At the highest level, the Prolog banksofcontrol-store chips. In asense, the put-valur(Object,Slot,New-value). programmer may treat Prolog clauses as Lisp Machine becomes a Prolog Machine Loops objects that can be manipulated when it is executing Prolog microcode. Be- The first goal checks to see if the value July 1988 37 - - . ... .- - .. .. ... ... .-. interface must allow calls to Prolog proce- that would let the methods he invoked via dures from the Lisp world. the Loops message-sending mechanism. Ideally, it should be transparent to the Prolog procedures as sender whether the method is defined in methods Lisp or Prolog. Loops was initially designed to offer the features of a Smalltalk-likelanguage to the Message-sending mechanism. Xerox Lisp programmer. It provides facilities to Quintus Prolog provided a way through a define classes and methods and to create Lisp function named PROILK to facilitate instances. Loops comes with a generous the creation of Prolog queries from Lisp. collection of system-defined classes and a If a Imops programmer wanted to invoke set of elegant programming tools. These the Prolog procedure foo/3, using the tools include ones that display and function call manipulate class hierarchies. You can in- (PROLOG 'foohdr (IJST 'argl *VALUE* Figure 1. Lisp and Prolog methods. voke most common programming opera- 'arg3)) tions with a mouse. would have the same effect the Prolog In the Loopsenvironment, object meth- as stored in aslot matches the targetvalue. If ods are invoked by sending a message to query this goal succeeds, the second goal will al- the object. The syntax for sending a mes foobx(arg1,X,arg3). ways succeed and will install the new value sage is The interface treats the Prolog proce- in the slot as a side effect.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us