1 Fluents: a Refactoring of Prolog for Uniform Reflection and Interoperation with External Objects /kprolog/Main.html Copyright.

Slides:



Advertisements
Similar presentations
pa 1 Porting BETA to ROTOR ROTOR Projects Presentation Day, June by Peter Andersen.
Advertisements

Programming Languages and Paradigms
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
1 OBJECT-ORIENTED CONCEPTS. 2 What is an object?  An object is a software entity that mirrors the real world in some way.  A software object in OOP.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
Programming Language Paradigms: summary. Object-oriented programming Objects are the fundamental building blocks of a program. Interaction is structured.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Lecture 23: Software Architectures
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Abstract Data Types and Encapsulation Concepts
Object-oriented design CS 345 September 20,2002. Unavoidable Complexity Many software systems are very complex: –Many developers –Ongoing lifespan –Large.
C++ fundamentals.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
1 INTRODUCTION TO OOP Objective: Know the difference between functional programming and OOP Know basic terminology in OOP Know the importance of OOP Know.
Chapter 25 More Design Patterns.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Object Oriented Software Development
CSE 341, S. Tanimoto Concepts 1- 1 Programming Language Concepts Formal Syntax Paradigms Data Types Polymorphism.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Modern Concurrency Abstractions for C# by Nick Benton, Luca Cardelli & C´EDRIC FOURNET Microsoft Research.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Programming Languages and Paradigms Object-Oriented Programming.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Monads Technion – Institute of Technology Software Design (236700) Author: Gal Lalouche - Technion 2015 © 1.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
1 A Logic Programming Based Mobile Agent Infrastructure January 19, 2001 Copyright © 2000, Paul Tarau Paul Tarau University of North Texas & BinNet Corporation.
11 September 2008CIS 340 # 1 Topics To examine the variety of approaches to handle the middle- interaction (continued) 1.RPC-based systems 2.TP monitors.
Jinni: Intelligent Mobile Agent Programming at the Intersection of Java and Prolog Copyright © 1999, BinNet Corp. Paul Tarau University of North Texas.
1 Programming Language History and Evolution In Text: Chapter 2.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
11 CORE Architecture Mauro Bruno, Monica Scannapieco, Carlo Vaccari, Giulia Vaste Antonino Virgillito, Diego Zardetto (Istat)
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
A Logic Programming Based Software Architecture for Reactive Intelligent Mobile Agents - DIPLCL’99 Copyright © 1999, BinNet Corp. Paul Tarau University.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Unit 2 Architectural Styles and Case Studies | Website for Students | VTU NOTES | QUESTION PAPERS | NEWS | RESULTS 1.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
11 CORE Architecture Mauro Bruno, Monica Scannapieco, Carlo Vaccari, Giulia Vaste Antonino Virgillito, Diego Zardetto (Istat)
Abstraction ADTs, Information Hiding and Encapsulation.
1 Object Oriented Logic Programming as an Agent Building Infrastructure Oct 12, 2002 Copyright © 2002, Paul Tarau Paul Tarau University of North Texas.
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
PHP vs. Python. Similarities are interpreted, high level languages with dynamic typing are Open Source are supported by large developer communities are.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
Copyright 2006 Oxford Consulting, Ltd1 January Introduction to C++ Programming is taking A problem Find the area of a rectangle A set of data.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Design Patterns for Multi-Threaded Logic Programming Languages Copyright © 1999, BinNet Corp. Paul Tarau University of North Texas & BinNet Corporation.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Programming Language History and Evolution
Object Oriented Concepts -I
Programming Language History and Evolution
Nondeterministic Evaluation
University of North Texas
Design Patterns A Case Study: Designing a Document Editor
Java Programming Language
IDSS Lab – research directions Sept 6, 2002
Parameter Passing Actual vs formal parameters
ITEC 3220A Using and Designing Database Systems
Exception and Event Handling
Presentation transcript:

1 Fluents: a Refactoring of Prolog for Uniform Reflection and Interoperation with External Objects /kprolog/Main.html Copyright © 1999, BinNet Corp. Paul Tarau University of North Texas & BinNet Corporation

2 Motivation Kernel Prolog = Horn Clause Interpreters with LD-resolution: Fluents uniform interface for controlling multiple interpreters and external stateful objects redesigning Prolog's system of built-in predicates: OO hierarchy (other Fluents) interoperation with the underlying Java system =>

3 jdialog/2: a Jinni 2000 Visual Component jdialog(Query,Answer):- new_frame('Jinni Dialog',border,F), new_label(F,Query,_), new_panel(F,flow,P), new_button(P,'Cancel', out(bc(P,cancel))), new_button(P,'Ok',out(bc(P,ok))),show(F), in(bc(P,Answer)),destroy(F).

4 What’s wrong with Prolog’s builtins? LP => forever young! old, deprecated builtins - early Fortran, C inspired design - consolidated into “industrial strength” ISO standard :-) Zeppelins vs. air plains => the paradigm consolidation disease (do we have it?) messy flat function set => simple, clean, compositional OO hierarchy

5 What’s wrong with Prolog’s reflection? call(X): control is not reflected properly - for instance backtracking is not a “first order” citizen - not even with AND- continuation passing engines basic things difficult: i.e. source level definition of exception handling general problem: lack of genericity (lists operations => conjunctions?)

6 What are Fluents? simple stateful entities - evolving through an abstract set of stepping operations Files, URLs, client/server interaction streams, GUI event streams Prolog interpreters (and runtime engines): just other Fluents! => a way to map linear recursion to fast iteration

7 Refactoring Prolog: a Fluent based design Kernel Prolog: a collection of Horn Clause Interpreters (Answer Sources) running LD- resolution on a given clause database and calling built-in operations a constructor: goal + answer pattern => answers can be explored one by one the Fluent encapsulating the state of the interpreter is very similar to a file descriptor encapsulating the state of a file reader!

8 Fluent Classes class Fluent extends SystemObject { Fluent(Prog p) {trailMe(p);} protected void trailMe(Prog p) { if(null!=p) p.getTrail().push(this); } public void stop() {} protected void undo() {stop();} }

9 Source Fluents abstract class Source extends Fluent { Source(Prog p) { super(p); } abstract public Term get(); }

10 Sink Fluents abstract class Sink extends Fluent { Sink(Prog p) {super(p);} abstract public int put(Term T); public Term collect() { return null; }

11 Fluent Composers I append_sources/3: creates a new Source with a get/2 operation such that when the first Source is stopped, iteration continues over the elements of the second Source. compose_sources/3: a cartesian product style composition, get/2 returnins pairs of elements of the first and second Source reverse_source/2 builds a new Source such that its get/2 returns in reverse order

12 Fluent Composers II split_source/3 creates two Source objects identical to the Source given as first argument - allows writing programs which iterate over a given Source multiple times join_sinks(S1,S2,S) creates a sink S such that its put operation go to both S1 and S2 discharge(Source,Sink): sends all the elements of the Source to the given Sink

13 Fluent Modifiers Fluent modifiers allow dynamically changing some attributes of a give Fluent set_persistent(Fluent,YesNo) is used to make a Fluent survive failure, by disabling its undo method, which, by default, applies the Fluent's stop method on backtracking

14 Interpreters (and run-time engines) as Fluents Engine = LD Resolution Interpreter with first order control: constructor+iterator answer_source(+Goal, +AnswerPattern, -Handle): creates a new interpreter get(+Handle, -AnswerInstance): returns a new answer the(AnswerInstance) or no if no more answers stop(+Handle): frees resources

15 Building some “built-ins” % returns the(X) or no as first solution of G first_solution(X,G,Answer):- answer_source(X,G,Solver), get(Solver,R), stop(Solver), eq(Answer,R).

16 once/1 and not/1 % binds G to its first solution or fails once(G):- first_solution(G,G,the(G)). % succeeds without binding G, if G fails not(G):- first_solution(_,G,no).

17 If-then-else if(Cond,Then,Else):- first_solution( successful(Cond,Then),Cond,R), select_then_else(R,Cond,Then,Else). select_then_else( the(successful(Cond,Then)), Cond,Then,_):-Then. select_then_else(no,_,_,Else):-Else.

18 Reflective Meta-Interpreters % metacall/1: just reflects backtracking % through element_of/2 metacall(Goal):- answer_source(Goal,Goal,E), element_of(E,Goal).

19 Reflecting backtracking element_of(I,X):- get(I,the(A)), select_from(I,A,X). select_from(_,A,A). select_from(I,_,X):- element_of(I,X).

20 Unfolder Fluents (A0:-A1,A2,...,An) (B0:-B1,...,Bm) = (A0:-B1,...,Bm,A2,...,An) mgu(A1,B0). unfold_solve(Goal):-unfold( ':-'(Goal,Goal), ':-'(Goal,true) ). unfold(Clause,Clause). unfold(Clause,Answer):- unfolder_source(Clause,Unfolder), element_of(Unfolder,NewClause), unfold(NewClause,Answer).

21 findall/3 findall(X,G,Xs):- answer_source(G,X,E), get(E,Answer), collect_all_answers(Answer,E,Xs). collect_all_answers(no,_,[]). collect_all_answers(the(X),E,[X|Xs]):- get(E,Answer), collect_all_answers(Answer,E,Xs).

22 Findall with Source Operations findall(X,G,Xs):- answer_source(X,G,Solver), source_list(Solver,Xs).

23 Copy_term/2 copy_term(X,CX):- first_solution(X,true,the(CX)). % true if X is currently a free variable var(X):-copy_term(X,a),copy_term(X,b).

24 Exceptions: at source level throw(E):-return(exception(E)). catch(Goal,Exception,OnException):- answer_source(answer(Goal),Goal,Source), element_of(Source,Answer), do_catch(Answer,Goal,Exception, OnException,Source).

25 Catch - continued do_catch(exception(E),_,Exception, OnException,Source):- if(E=Exception, call(OnException), % if matching throw(E) % throw again otherwise ), stop(Source). do_catch(the(Goal),Goal,_,_,_).

26 Data Structure Fluents univ(T,FXs):- if(var(T), list_to_fun(FXs,T), fun_to_list(T,FXs)). list_to_fun(FXs,T):- list_source(FXs,I),source_term(I,T). fun_to_list(T,FXs):- term_source(T,I),source_list(I,FXs).

27 Other Fluents: URL reader fluents File, database, socket fluents lazy list fluents

28 Conclusion I a design for the uniform interoperation of Horn Clause Solvers with stateful entities (Fluents) ranging from external procedural and object oriented language services like I/O operations, to other, 'first class citizen' Horn Clause Solvers interoperation with external class libraries a simplified Prolog built-in predicate system

29 Conclusion II the ability to communicate between distinct OR-branches as an practical alternative to the use assert/retract based side effects, in implementing all-solution predicates lazy variants of all solution predicates are provided as a natural extension to Fluent based lazy lists Fluent Composers allow combining component functionality in generic ways

30 Conclusion III collapsing the semantic gap between Horn Clause logic and (most of) the full Prolog language implementation technology for a lightweight Prolog processors the intrinsic elegance hiding behind the core concepts of the logic programming paradigm

31 Jinni a commercial implementation fast (1 million LIPS) pure Java based Prolog to be released next week (a fluent:-)) integrates Kernel Prolog with fast continuation passing BinWAM engine runs also Palm, Handspring (K-machine) blackboards, threads, remote predicate calls agents: generalization of class/object OO