Side effects in Prolog Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.

Slides:



Advertisements
Similar presentations
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 10: Cuts and Negation Theory –Explain how to control Prolog`s backtracking behaviour with.
Advertisements

Chapter 2, Part 2: An interpreter for an object-oriented language Xinming (Simon) Ou CIS 505: Programming Languages Kansas State University Fall
Chapter 5: Abstraction, parameterization, and qualification Xinming (Simon) Ou CIS 505: Programming Languages Kansas State University Fall
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
A pointer is the memory address of a variable. A memory address is a physical location within a system’s memory space. A pointer variable is variable used.
Introduction to Prolog, cont’d Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
3-Valued Logic Analyzer (TVP) Tal Lev-Ami and Mooly Sagiv.
Chapter 2, Part 1: An interpreter architecture for C-like languages Xinming (Simon) Ou CIS 505: Programming Languages Kansas State University Fall 2010.
Chapter 6: From an assignment core to Java Xinming (Simon) Ou CIS 505: Programming Languages Kansas State University Fall
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
INTRODUCTION TO PROLOG. PROLOG BASICS Atoms - most primitive terms that the language manipulates start with lower case letter includes strings (‘inside.
1 Knowledge Based Systems (CM0377) Lecture 8 (Last modified 5th March 2001)
(FO) Inference Methods CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
For Monday Take home exam due Exam 1. For Wednesday Read chapter 10, sections 1-2 Prolog Handout 4.
Pure Prolog vs. Extralogical Prolog Pure Prolog programs can be interpreted as logical statements about what they compute. Pure Prolog programs can be.
Chapter 8: The Logical Paradigm Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Chapter 4B: More Advanced PL/SQL Programming
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
C. Varela1 Logic Programming (PLP 11.3) Prolog Imperative Control Flow: Backtracking Cut, Fail, Not Carlos Varela Rennselaer Polytechnic Institute September.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 28: Prolog’s Lists, Negation and Imperative Control Flow COMP 144 Programming Language.
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
Pointers| SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: September 2006 Slide 1 Pointers by Jumail Bin Taliba Faculty of Computer.
1 About Prolog Lu Han Written at Modified at
CREST Internal Yunho Kim Provable Software Laboratory CS Dept. KAIST.
Computer Architecture Computational Models Ola Flygt V ä xj ö University
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 17 Announcement: next few weeks… 9 nd Feb: Comparative Programming.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
Introduction to Python
Programming Intro Problem Solving: 1)Understand the problem This often involves breaking the problem into manageable pieces 2) Develop a plan May develop.
Introduction to AgentSpeak and Jason for Programming Multi-agent Systems (1) Dr Fuhua (Oscar) Lin SCIS Athabasca University June 19, 2009.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
F28PL1 Programming Languages Lecture 16: Prolog 1.
15/11/04 AIPP Lecture 14: Database Manipulation1 Database Manipulation Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 14 15/11/04.
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
Introduction to Pascal The Basics of Program writing.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
F28PL1 Programming Languages Lecture 18: Prolog 3.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Cs774 (Prasad)L6Backtracking1 Controlling Backtracking : Cuts
Prolog Unification and clause order. The notion of Unification Unification is when two things “become one” Unification is kind of like assignment Unification.
Knowledge Based Information System
For Monday Exam 1 is Monday Takehome due Prolog Handout 3 due.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
For Friday No reading Prolog Handout 2. Homework.
23-Feb-16 Prolog II Unification and clause order.
Answer Extraction To use resolution to answer questions, for example a query of the form  X C(X), we must keep track of the substitutions made during.
1 TP #2: How does Prolog answer questions? n Miscellaneous info; n Last TP exercises solved; n How does Prolog answer questions? n Recursive Prolog programs;
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
From Conventional Languages to Prolog –What we can do in conventional languages but not in Prolog –What we can do in Prolog but not in conventional languages.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
Google C++ Testing Framework Part 2: Assertion. Concepts A test case contains one or many tests. ◦ You should group your tests into test cases that reflect.
C. Varela1 Logic Programming (PLP 11, CTM 9.3) Prolog Imperative Control Flow: Backtracking, Cut, Fail, Not Lists, Append Carlos Varela Rennselaer Polytechnic.
Windows Programming Lecture 03. Pointers and Arrays.
1 Lecture 16: Prolog’s Lists, Negation and Imperative Control Flow (Section 11.3) CSCI 431 Programming Languages Fall 2002 A modification of slides developed.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Carlos Varela Rensselaer Polytechnic Institute November 17, 2017
Programming Languages and Paradigms
CS621 : Artificial Intelligence
C Programming Pointers
Chapter 2: Prolog (Introduction and Basic Concepts)
Carlos Varela Rennselaer Polytechnic Institute November 15, 2016
Presentation transcript:

Side effects in Prolog Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1

Side effect When using Prolog as a programming language, it is often needed to create side effects – e.g. printing to the display, writing to files – Some side effect will influence the Prolog execution environment and execution behaviors 2

Asserting facts Facts can be loaded into the Prolog database. – e.g. ?- load_dyn(‘input.P’). The predicates defined in input.P are called “dynamic predicates”. – They can be added to the database using the load_dyn command, or the “assert” command – e.g. ?- assert(parent(bill, mary)). – They can be removed from the database using the “retract”, or “retractall” command. – E.g. ?- retract(parent(X,Y)). ?- retractall(parent(X,Y)). 3

Printing statements Print a term – e.g. write(‘Hello world’). write(world). write(X). Print a new line – nl. – writeln(‘abc’). – write(‘\n’). 4

Cut The cut command “!” will eliminate all the choice points for the parent goal. – e.g. member(A, [A|_As]) :- !. member(A, [_B|Bs]) :- member(A, Bs). – But this will break the declarative semantics. Try this: ? – member(A, [1,2,3]). 5

Negation in Prolog Negation by failure: – not L succeeds if L fails. – It is equivalent to: not(L) :- L, !, fail. not(L). Negation by failure is not logical negation, when the literal contains variables when the negation is called. 6

Assignment 7 Use Prolog to implement the interpreter in assignment 2. memory and environment implemented using dynamic predicates – env(Name, Type, Location). 7

Memory The memory is a mapping from locations to values. The memory/2 predicate provides the mapping. – memory(Location, Value). – memoryCounter(Length) returns the number of cells in the memory. – memoryAppend(Value) add a new memory cell and put Value into it. – memoryUpdate(Location, Value) updates the memory location with the value. 8

Environment Provides mapping from a variable name to its type and memory location that holds the value. – env(name, type, value) provides the mapping type is either [‘int’] or [‘ptr’, ‘int’] 9