1 Visual Prolog Programs LabLecture # 3 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami.

Slides:



Advertisements
Similar presentations
Constants and Data Types Constants Data Types Reading for this class: L&L,
Advertisements

Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to a Programming Environment
Chapter 2: Introduction to C++.
JavaScript, Third Edition
1 Lecture 3  Lexical elements  Some operators:  /, %, =, +=, ++, --  precedence and associativity  #define  Readings: Chapter 2 Section 1 to 10.
Data Types.
Computer Science 101 Introduction to Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Seventh.
Formal Models of Computation Part II The Logic Model
Computer Science 101 Introduction to Programming.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 3: Objects, Types, and Values 1 Based on slides.
Input, Output, and Processing
Introduction to Scheme Lectures on The Scheme Programming Language, 2 nd Ed. R. Kent Dybvig.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CPS120: Introduction to Computer Science
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
Getting Started with Visual Prolog
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Characters and tokens Characters are the basic building blocks in C program, equivalent to ‘letters’ in English language Includes every printable character.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
VARIABLES AND DATA TYPES Chapter2:part1 1. Objectives: By the end of this section you should: Understand what the variables are and why they are used.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects.
Lab Lecture#4 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
ISBN Chapter 16 Logic Programming Languages.
CPS120: Introduction to Computer Science Variables and Constants.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
CMSC 202 Java Primer 1. July 24, 2007 Copyright © 2008 Pearson Addison-Wesley 2 A Sample Java Application.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
A Sample Program #include using namespace std; int main(void) { cout
REEM ALMOTIRI Information Technology Department Majmaah University.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter 6 JavaScript: Introduction to Scripting
Chapter 2: Introduction to C++
2.1 Parts of a C++ Program.
Variables in C Topics Naming Variables Declaring Variables
TA : Mubarakah Otbi, Duaa al Ofi , Huda al Hakami
Variables in C Declaring , Naming, and Using Variables.
Chapter 2: Introduction to C++.
Topics Introduction to Functions Defining and Calling a Function
Lexical Elements & Operators
Variables in C Topics Naming Variables Declaring Variables
Chapter 1 c++ structure C++ Input / Output
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

1 Visual Prolog Programs LabLecture # 3 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami

2 In this lecture|: Visual Prolog's Basic Program Sections –The Clauses Section –The Predicates Section –The Domains Section –The Goal Section A Closer Look at Declarations and Rules Other Program Sections –The Facts Section –The Constants Section –The Global Sections

3 Visual Prolog Programs: Introduction The syntax of Visual Prolog is designed to express knowledge about properties and relationships. You've already seen the basics of how this is done; in LabLecture2 you learned about clauses (facts and rules), predicates, variables, and goals. Visual Prolog is a typed Prolog compiler; you declare the types of the objects that each predicate applies to. The type declarations allow Visual Prolog programs to be compiled right down to native machine code, giving execution speeds similar to those of compiled C and pascal.

4 Visual Prolog's Basic Program Sections Visual Prolog program includes four basic program sections: The clauses section The predicates section The domains section The goal section.

5 A Visual Prolog program has the following basic structure: DOMAINS /*... domain declarations... */ PREDICATES /*... predicate declarations... */ CLAUSES /*... clauses (rules and facts)... */ GOAL /*... subgoal_1, subgoal_2, etc. */

6 DOMAINS argument_type1,..., argument_typeN = argument_1,..., argument_N) = ; ; PREDICATES predicateName(argument_type1, argument_type2,..., argument_typeN) CLAUSES clauses (rules and facts) GOAL subgoal_1, subgoal_2, etc.

7 The clauses section: The clauses section is the heart of a Visual Prolog program; this is where you put the facts and rules that Visual Prolog will operate on when trying to satisfy the program's goal.

8 The predicates section The predicates section is where you declare your predicates and the domains (types) of the arguments to your predicates. (You don't need to declare Visual Prolog's built-in predicates.) - a sequence of clauses defining a predicate is called a procedure. - If you define your own predicate in the clauses section, you must declare it in a predicates section.

9 How to Declare User-Defined Predicates predicateName(argument_type1, argument_type2,...,argument_typeN) (Note: that, unlike the clauses in the clauses section of your program, a predicate declaration is not followed by a period.) PredicateNames:Rule Must begin with a lower-case letter, followed by a sequence of letters, digits, and underscores. Predicate names can be up to 250 characters long. Contd..

10 If you declare a predicate my_predicate(symbol, integer ) in the predicates section, like this: PREDICATES my_predicate(symbol, integer) you don't need to declare its arguments' domains in a domains section, because symbol and integer are standard domains. But if you declare a predicate my_predicate(name, number) in the predicates section, like this: PREDICATES my_predicate(name, number) contd..

11 you will need to declare suitable domains for name and number. Assuming you want these to be symbol and integer respectively, the domain declaration looks like this: DOMAINS name = symbol number = integer PREDICATES my_predicate(name, number)

12 Valid naming characters in Visual Prolog : Upper-case Letters: A, B,..., Z Lower-case Letters: a, b,..., z Digits: 0, 1,..., 9 Underscore character: _ Examples of legal and illegal predicate names: Legal Predicate NamesIllegal Predicate Names fact[fact] is_a*is_a* has_ahas/a patternCheckListpattern-Check-List choose_Menu_Itemchoose Menu Item predicateNamepredicate first_in_10>first_in_10

13 The domains section: The domains section is where you declare any domains. Domains enable you to give distinctive names to different kinds of data that would otherwise look alike. (You don't need to declare standard domains.) Ex: Frank is a male who is 45 years old. DOMAINS name, sex = symbol age = integer PREDICATES person(name, sex, age)

14 The goal section: The goal section is where you put the starting goal for a Visual Prolog program. It's simply a list of subgoals. The goal keyword is not followed by :-. Visual Prolog automatically executes the goal when the program runs.

15 Basic Standard Domains DescriptionDescription and implementation charA character, implemented as an unsigned byte. Syntactically, it is written as a character surrounded by single quotation marks: 'a'. real A floating-point number, implemented as 8 bytes. Examples: string A sequnce of characters. Examples: telephone_number "railway ticket" "Dorid Inc " symbol A sequence of characters. The syntax is the same as for strings

16 Multiple Arity The arity of a predicate is the number of arguments that it takes. You can have two predicates with the same name but different arity. You must group different arity versions of a given predicate name together in both the predicates and clauses sections of your program; apart from this restriction, the different arities are treated as completely different predicates

17 Multiple Arity:Example DOMAINS person = symbol PREDICATES father(person)% This person is a father father(person, person) % One person is the father of the other person CLAUSES father(Man):- father(Man,_). father(adam,seth). father(abraham,isaac).

18 Other Program Sections Other commonly-used program sections: The facts section, The constants section, and the various global sections.

19 The Facts Section A Visual Prolog program is a collection of facts and rules. The keyword facts declares the facts section. It is here that you declare the facts to be included in the dynamic facts section

20 The Constants Section A constant declaration section is indicated by the keyword constants. syntax: = is the name of your symbolic constant, and is what you're assigning to that constant. Each is terminated by a newline character, so there can only be one constant declaration per line.

21 CONSTANTS:Example A = (10*(10-1)+10)*34, delay(A), zero = 0 one = 1 two = 2 hundred = (10*(10-1)+10) pi = ega = 3 slash_fill = 4 red = 4 Before compiling your program, Visual Prolog will replace each constant with the actual string to which it corresponds. For instance:..., A = hundred*34, delay(A),

22 The Global Sections Visual Prolog allows you to declare some domains, predicates, and clauses in your program to be global (rather than local); you do this by setting aside separate global domains, global predicates, and global facts sections at the top of your program. These global sections are discussed later.

23 Exercises..