130 likes | 266 Views
Java+Prolog: A Land of Opportunities. Derived from talk at PACLP’99 Miguel Calejo. Structure of presentation. Motivation Prolog and Java backgrounds Combination possibilities. Motivation. Prolog did not conquer the world… ...but continues to evolve R&D better spent on LP intrinsics
E N D
Java+Prolog: A Land of Opportunities Derived from talk at PACLP’99 Miguel Calejo
Structure of presentation • Motivation • Prolog and Java backgrounds • Combination possibilities
Motivation • Prolog did not conquer the world… • ...but continues to evolve • R&D better spent on LP intrinsics • … but OOP did • Best interface to the world • Java is clean, dynamic, highly backed • Java strengths complement LP’s • Java+Prolog interfaces are available
Background: Prolog • The promise of declarativity • Prolog = imperative programming + unification + backtracking • CLP = Prolog + constraint solving • etc., …cf. other modules • ISO standard, but hardly a stable platform
Background: Java platform • OOP = imperative programming + message sending • OS independence • Multi-environment • Server, desktop, browser, TV, Consumer Electronics, Cards • Enormous API scope • GUI, 3D, speech, communications, speech, e-commerce, mobile, servers, … • http://java.sun.com • Blessed by most and backed by all
Background: Java GUI • About Swing/JFC • Playing with the Swingset • Principles • GUI objects are objects • User events cause messages to listeners • Listeners can be of any class but must implement simple event interfaces • Model-View/Controller • Letting the framework work for us: a minimal JTable example
Background: Java Reflection • All objects know their class: • Class C = X.getClass(); • Since JDK 1.1, classes provide info about public methods and variables • Method M = C.getMethod(“anyMethod”,Class arg array) • No Prolog meta-call, but close • M.invoke(Target,Object arg array)
Background: “80s” Object Serialization • An easy and natural way to persist an object is to “serialize” its state • Each class knows only how to store its own variables • writeObject(Stream s){ super.writeObject(s); WRITE MY DATA;}
Background: Java Serialization • Cleaner than in previous languages: Reflection allows a system mechanism to introspect any object and serialize it... • Cf. classes ObjectOutputStream, InputObjectStream • ...oos.writeObject(ANYOBJECT); • Object ANY = ios.readObject(); • ...using a public stream format :) • Writes/reads an object graph, including class descriptions, without repeating objects
How to combine Java and Prolog ? • Java (or OOP) in Prolog • LogTalk.org • Prolog in Java • DGKS Prolog, JavaLog, Jinni, MINERVA, Prolog Café, W-Prolog • Java + Prolog • JNI – based • Amzi, InterProlog (XSB), Jasper(Sicstus), JPL(SWI), JIPL (K-Prolog) • Socket-based • InterProlog(XSB, SWI, YAP), Prolog IV • Links for these and more: • http://www.declarativa.pt/interprolog/systems.htm
Prolog+Java • Writing apps in Prolog and Java • Accept the 2 paradigms, side by side • Unification, backtracking, constraints • Message-sending • Reap the benefits of decades of LP research… • …saving the investment already done for Java
Prolog+Java: issues • How to interface • Same OS process ? • Granularity of communication • Who calls who • Restrictions ? • Converting data • Terms and relations vs. objects • Impact on existing systems • Economics, guru independence...