CptS 355 Programming Language Design - PowerPoint PPT Presentation

1 / 56
About This Presentation
Title:

CptS 355 Programming Language Design

Description:

Creator(s): IBM (team lead by John Backus) ... the lark at heaven's gate sings, And Phoebus 'gins arise, His steeds to water at those springs ... – PowerPoint PPT presentation

Number of Views:102
Avg rating:3.0/5.0
Slides: 57
Provided by: roge2
Category:

less

Transcript and Presenter's Notes

Title: CptS 355 Programming Language Design


1
CptS 355Programming Language Design
Fortran
  • Tim Aspinwall
  • WSU Vancouver, Spring 2001

fortran.ppt
2
A Brief History
  • Created 1954-1957
  • Creator(s) IBM (team lead by John Backus)
  • Original Purpose Solution of problems involving
    numerical computation (IBM 704)
  • Significance
  • Oldest of the established High Level Languages
    (HLL)
  • First language to be standardized (1972)
    portable Code!
  • Primary goal speed of the generated object
    code very efficient!
  • Proved HLL's are practical
  • Established many conventions
  • - RCR

The IBM Mathematical FORmula TRANslating System
FORTRAN (IBM, 1954)
3
A Partial Genealogy
Fortran A Very Long History
4
Sample Code
REAL a, b, c LOGICAL
abigger CHARACTER5 assertion c
.01 a SQRT (c) b c2
assertion 'a gt b' abigger (a .GT. b)
WRITE (, 100) a, b 100 FORMAT (' a ',
F7.4, ' b ', F7.4) IF (abigger) THEN
WRITE (, ) assertion, ' is true.'
ELSE WRITE (, ) assertion, ' is false.'
END IF END
c c Hello, world. c Program Hello
implicit none logical DONE DO while
(.NOT. DONE) write(,10) END DO
10 format('Hello, world.') END

Hello, world. Hello, world. Hello, world.
  • Original version
  • blanks invisible to compiler
  • implicit declarations
  • names lt 8 chars, up case
  • no END (use stmt 's)

a .1000 b .0001 a gt b is true.
5
The Starving StudentsIntro to Lisp
  • Andrew Varner
  • CS 355 Spring 2001 WSUV

6
Through The Annals of Time
  • Lisp Stands for List Processing
  • Intended to formalize the use of recursion
    equations

7
Language Associations
The Lisp evolution was very linear with little
influence from other languages.
8
Evaluation and Significance
  • Of widespread languages today, only FORTRAN is
    older
  • Lisp dominated AI applications for over 25
    years, and is
  • still the most widely used language for AI
  • In 1994 Lisp became the first ANSI standard to
  • incorporate OOP
  • Big impact on computer science -- proved value of
    non-numericcomputation, recursion and
    pointer-based data structures
  • Unmatched power -- Lisp programs are Lisp data
    structures, so programs can can manipulate
    themselves!

-- RCR
9
Code Sample
Two flavors of Lisp are Common Lisp and Scheme
In Common Lisp, a simple program would look
something like the following
(defun fact (n) (if (lt n 2) 1
( n (fact (1- n)))))
In Scheme, the equivalent program would like like
this  
(define fact (lambda (n)
(if (lt n 2) 1 ( n
(fact (- n 1))))))
C Version int factorial(int n) int result
1 while (--n) result result n
return result
10
Wrap-Up
  • CAR -- Originally meant "Contents of Address
    portion of Register",
  • which is what CAR actually did on the
    original IBM 704.
  • CDR -- "Contents of Decrement portion of
    Register", again what CDR
  • actually did on the IBM 704. Pronounced
    "Cudder
  • Scheme is a dialect of Lisp and much smaller
    than Common Lisp.
  • Scheme is often used in computer science
    curricula and programming
  • language research, due to its ability to
    represent many programming
  • abstractions with its simple primitives.
    Common Lisp is often used for
  • real world programming because of its large
    library of utility functions,
  • a standard object-oriented programming
    facility (CLOS), and a
  • sophisticated condition handling system.

11
CptS 355Programming Language Design
Algol 60
  • Jason Graber
  • WSU Vancouver, Spring 2001

algol60.ppt
12
History
  • 1958 - Effort to design a universal language.
  • Desire for portable, non-proprietary language.
  • ACM and GAMM committees agreed to joint language
    design.
  • 1960 - First implementation

13
Significance
  • First precisely defined high-level language
  • introduced BNF notation
  • Elegant powerful design that had tremendous
    effect on computer science
  • block structure with nested scopes
  • formalized notion of data types
  • extremely orthogonal
  • standard for algorithm publication
  • led to disciplines in formal languages, parsing
    theory and compiler design
  • Not widely used in practice
  • undefined standard I/O

Algol 60
14
User Specifics
  • Syntax and language close to standard math
    notation
  • separate font for reserved words
  • for assignment and for equality
  • ... for subscripting
  • for statement separation
  • Stack dynamic arrays
  • Call by value and call by name
  • No defined standard I/O

comment Main program begin integer N
Read int(N) begin real array
Data1N real sum, avg
integer i sum0 for i1
step 1 until N do begin real val
Read Real(val)
Dataiif vallt0 then-val else val
end for i1 step 1 until N
do sumsum Datai
avgsum/N Print Real(avg)
end end
Calculate Mean
15
CptS 355Programming Language Design
Algol 68
  • Long-Hai Huynh
  • WSU Vancouver, Spring 2001

algol68.ppt
16
History of Algol 68
  • Created by van Wijngaarden in 1968
  • Design criteria orthogonality
  • Purpose scientific applications
  • Language Overview
  • User-defined data types
  • Dynamic arrays

17
A Partial Genealogy
Algol 68
18
Compare and Contrast with PL/1

  • PL/1
  • Writability Achieved writability by including a
    large number of fixed constructs
  • Added other features of several other languages
    to achieve its goals
  • Created for broad class of problems
  • More acceptance due to IBMs promotional efforts
  • Algol 68
  • Achieved writability through its principle of
    orthogonality
  • Extended the simplicity of Algol 60
  • Created to a single class of problems (scientific
    applications)

19
Algols Contributions to C
  • Constant declarations
  • "Expression" language
  • Improved syntax
  • Arrays
  • Controlled storage
  • Redefinition of operators, priorities,
    overloading
  • Standard input standard output
  • Unions
  • User definition of new modes by composing
    existing modes

20
Hello World
  • Algol-60
  • 'BEGIN
  • 'COMMENT' Hello World in Algol 60
  • OUTPUT(4,'(''('Hello World!')',/')')
  • 'END'

Algol-68 ( Hello World in Algol 68
print(("Hello World!", newline)))
C-Ansi / Hello World in C / include
ltstdio.hgt int main(void) printf("Hello
World!\n") return 0
Hello World!
21
CptS 355Programming Language Design
COBOL
  • Jacob Mutschler
  • WSU Vancouver, Spring 2001

22
History of COBOL
- Common Business Oriented Language
- Created by the Conference on Data Systems and
Languages (CODASYL) in 1959
- COBOL systems had to be fixed for Y2k
23
Influencing Factors
Rear Admiral Grace Hopper (December 9, 1906 -
January 1, 1992 )
  • Developed FLOW-MATIC which greatly influenced
    COBOL.
  • Actively participated in the first meetings to
    formulate specifications for a common business
    language.
  • A technical adviser to CODASYL
  • Devoted much time to convincing business managers
    that English language compilers such as
    FLOW-MATIC and COBOL were feasible

24
Significance
  • Developed for large-scale programs in government
    and business
  • First high-level language widely used by
    businesses
  • Convenient for handling input output
  • Designed for the average business person
  • Programs are very readable
  • COBOL programs are structured much like essays
  • Data types are numbers and strings of text
  • Data could be stored in arrays and records

25
Code Sample (Sum of Numbers)
000100 ID DIVISION. 000200 PROGRAM-ID.
ACCEPT1. 000300 DATA DIVISION. 000400
WORKING-STORAGE SECTION. 000500 01
WS-FIRST-NUMBER PIC 9(3). 000600 01
WS-SECOND-NUMBER PIC 9(3). 000700 01
WS-TOTAL PIC ZZZ9. 000800 000900
PROCEDURE DIVISION. 001000 0000-MAINLINE. 001100
DISPLAY 'ENTER A NUMBER '. 001200 ACCEPT
WS-FIRST-NUMBER. 001300 001400 DISPLAY
'ANOTHER NUMBER '. 001500 ACCEPT
WS-SECOND-NUMBER. 001600 001700 COMPUTE
WS-TOTAL WS-FIRST-NUMBER WS-SECOND-NUMBER. 001
800 DISPLAY 'THE TOTAL IS ',
WS-TOTAL. 001900 STOP RUN.
26
CptS 355Programming Language Design
PL/I
  • Raul Chiari
  • WSU Vancouver, Spring 2001

PL/I.ppt
27
History
  • 1964 IBM Hursley Laboratory (England)
  • Language to encompass broad spectrum of
    application areas (science and business)
  • SHARE GUIDE Dilemma

Scientific programmer IBM 7090 or 1620 Floating
points and arrays types FORTRAN
Business App programmers IBM 7080 or 1401 Decimal
and string data types with extensive I/O
facilities COBOL
?
IBM 360 and PL/I
28
Overview
  • What is PL/I?
  • General purpose language used to solve problems
    in a variety of fields (commerce, science,
    medicine, engineering, etc)
  • Facilities for scientific and business use
    (FORTRAN COBOL)
  • Systems programming
  • Significance?
  • First to allow program to create concurrently
    executing tasks
  • First to detect and handle 23 different types of
    run-time errors
  • First to allow procedures to be used recursively
  • First to include a pointer as a data type
  • Extensive array manipulation (up to 49
    dimensions!)

29
Example
/ Linked List in PL/I / LLIST PROCEDURE
OPTIONS (MAIN) DECLARE 1 Node BASED(HEAD)
2 Value FIXED BINARY
2 Ptr POINTER DECLARE Current POINTER DECLAR
E Head POINTER DECLARE NULL BUILTIN ALLOCATE
Node /allocate memory/ GET LIST
(Head-gtValue) /cin statement/ Current
Head Current -gt Ptr NULL /add to beginning
of linked list/ DO WHILE (Head-gtvalue0) / 0
sentinel value/ ALLOCATE Node GET LIST
(Head-gtValue) Head-gtPtr Current Current
Head END /end of scope/ /cout
statement/ PUT SKIP LIST (The elements in the
list are ) Current Head DO WHILE (Current
NULL) PUT LIST (Current-gtValue)
Current Current-gtPtr END END LLIST /end
of main/
  • DECLARE declares a data structure Node with
    two sub elements or just declares a data type
  • BASED merely a description of an element that
    would be declared at run time
  • ALLOCATE allocates memory for a based variable

30
CptS 355Programming Language Design
Snobol
  • Michael Van Hoff
  • WSU Vancouver, Spring 2001

31
History
  • 1962 Researchers at Bell Telephone Laboratories
    (BTL) were trying to use Symbolic Communication
    Language (SCL, an internal BTL product) and COMIT
    (designed for natural analysis) to do problems
    such as factoring multivariate polynomials and
    symbolic integration.
  • Out of frustration, they decided to design the
    language SNOBOL. Originally dubbed String
    Expression Interpreter(SEXI), it was renamed to
    StriNg Oriented symBOlic Language
  • The original designers were David J. Farber,
    Ralph E. Griswold and Ivan P. Polonsky. SNOBOL
    first ran on the IBM 7090 Mainframe in 1963.
  • As people saw how interesting the language was,
    new features were added such as built-in
    recursive functions.
  • SNOBOL was rewritten for other mainframes from
    scratch since it was not portable and so each
    iteration had its own dialect.
  • Implementations include SNOBOL2, SNOBOL3,
    SNOBOL4, FASBOL, SITBOL, MAINBOL, SPITBOL and
    vanilla.
  • SNOBOL3 had only one data type, the string.
  • In 1966, Ralph Griswold, Ivan Polonsky and Jim
    Poage added more data types, more complex pattern
    matching and used a macro assembly language to
    make the more portable SNOBOL4, which is still
    used today.

32
Overview
  • Easy string manipulation and string pattern
    matching.
  • SNOBOL is an imperative language, meaning that
    both instructions and data are stored in the same
    memory. SCL and COMIT are imperative as well,
    obviously influencing this design choice.
  • Features of SNOBOL
  • String concatenation
  • GOTO control structure
  • Run-time compilation
  • Variable string length
  • Array tables and record type objects
  • Operator overloading

33
Example
Input
Description This program demonstrates the pattern
matching ability of the SNOBOL programming
language by counting the number of occurrences of
a word length, from 3 to 9 letters, from the
following input file.
Hark! hark! the lark at heaven's gate sings, And
Phoebus 'gins arise, His steeds to water at
those springs On chaliced flowers that lies
And winking Mary-buds begin To ope their golden
eyes With every thing that pretty is, My lady
sweet arise Arise, arise!
Source Code TRIM 1 WORDPAT BREAK(LCASE
UCASE) SPAN(LCASE UCASE "'-") . WORD COUNT
ARRAY('39',0) READ LINE INPUT
F(DONE) NEXTW LINE WORDPAT F(READ)
COUNTltSIZE(WORD) gt COUNTltSIZE(WORD)gt 1
(NEXTW) DONE OUTPUT "WORD LENGTH NUMBER OF
OCCURRENCES" I 2 PRINT I I 1 OUTPUT
LPAD(I,5) LPAD(COUNTltIgt,20) S(PRINT) END
Sample Run Word Length Number of Occurrences
3 5 4 11 5 12 6 3
7 4 8 2 9 1
34
Evaluation
  • The developers of SNOBOL had little or no
    experience in software design. Griswold had no
    computing experience prior to BTL and Polonsky
    had limited software development skills.
  • This led to limited documentation.
  • Language semantics were treated casually.
  • Until SNOBOL4, there was only one data type, the
    string.
  • Operators were not chosen carefully.
  • The concatenation operator is a single space.
    Difficult to read and easy to use incorrectly.
  • Early implementations did not have built in
    functions for common tasks.
  • There was no type checking (only one type) so any
    string of characters was a legal SNOBOL program.
  • SNOBOLs only decendant is ICON, built in the
    1970s by Ralph Griswold, which has Pascal-like
    syntax and a Unix interface.

35
CptS 355Programming Language Design
"The best way to predict the future is to invent
it." -Alan Kay
Smalltalk
  • Shawn Williams
  • WSU Vancouver, April 17, 2001

36
Smalltalk Genealogy
37
Smalltalk History
  • Alan Kays doctoral thesis outlined the FLEX
    machine, which planted the seeds for the Dynabook
    (later reworked as the Minicom) - a portable
    interactive personal computer.
  • (Actually implemented as Apples Newton PDA).
  • A number of windows, top window is the focus of
    attention.
  • User interacts with keyboard and touch screen.
  • Designed to mimic Kay's biological model of
    individual entities, or "cells," communicating
    with each other via messages.
  • Kay defined the language on one page of code.
  • Several elements taken from Seymour Paperts LOGO
    system
  • Visual Feedback.
  • Accessibility to novices.
  • Orientation to wonder and creativity of
    childhood.
  • Many implementations Dolphin Smalltalk,
    VisualWorks, Smalltalk Express, Squeak,
    Smalltalk/X, IBM Smalltalk, etc.

38
Simple Example Code Operators are actually
messages
Simple Arithmetic
  • a 1. b 2. c a b.
  • Take the object a, which has the value 1, and
    send it the message "", which included the
    argument b, which, in turn, has the value 2.
  • Object a, receive this message and perform the
    action requested, which is to add the value of
    the argument to yourself.
  • Create a new object, give this the result, 3,
    and assign this object to c.
  • 212 passes parameter object 2 to the method
    of the object 21, which builds a new object, 23.
    If 23 already exists, the result is a reference

Strings
Something Even More Interesting
  • a List fromString 'John Jones'.b List
    fromString 'Suzy Smith'.c a b.
  • Now c 'John Jones, Suzy Smith'

a
b
c a b
39
Smalltalk Sample Code Count letters in a
sentence
Pascal Equivalent
Smalltalk
program frequency const size 80 var s
stringsize i integer c char f
array1..26 of integer k integer begin writeln
('enter line') readln(s) for i 1 to 26
do fi 0 for i 1 to size do begin c
asLowerCase(si) if isLetter(c)
then begin K ord(c) - ord('a') 1 fk
fk 1 end end for i 1 to 26 do write(fi,
' ') end.
"Return f st fi is of I-th letter ('a', 'b',
, 'z') in line from user" scfk f Array
new 26. 1 to 26 do i f at i put 0. s
Prompter prompt 'Enter line' default ''. 1
to s size do i c (s at i)
asLowerCase. c isLetter ifTrue k c
asciiValue a asciiValue 1. f at k put
((f at k) 1)). . f
clumsy
Smalltalks built-in building blocks
s f s Prompter prompt 'Enter line'
default ''. f Bag new. s do c c
isLetter ifTrue f add c asLowerCase. . f
40
Smalltalk Internals
  • Only 5 reserved words in Smalltalk self, super,
    nil, false and true
  • self Used by object to refer to itself.
  • super Used in sending messages to objects
    superclass.
  • nil Sole instance of UndefinedObject. Most
    variables initialized to nil.
  • true Sole instance of class True represents
    truth. 1gt0 true object.
  • false Sole instance of class False - represents
    falsity. 0gt1 false object.
  • Messages provide the means of communicating among
    objects.
  • A message is simply a request sent to an object
    to activate one of the operations defined on that
    object.
  • Two parts, specification of receiving object and
    message itself.
  • Message itself specifies method in receiver and
    possibly parameters.
  • Message replies are objects (return values).
  • Unary messages no parameters firstAngle sin
  • Binary messages single parameter 21 2
  • Keyword messages aPen drawFrom point1 to
    point2
  • Left to right precedence 1 2 3 ! 2 3
    1
  • No defined operators everything done through
    messages (see examples).
  • Special character groups
  • Assignment
  • Return from method

41
Smalltalk Significance
  • Smalltalk is the definitive object-oriented
    programming language
  • A Smalltalk program is only made of objects.
  • Virtually everything is an object (integer
    constant 2, file system, etc), each with
  • Local memory.
  • Inherent processing ability.
  • Capability to communicate with other objects.
  • Possibility of inheriting methods and instance
    variables from ancestors.
  • Objects are allocated from the heap.
  • No explicit deallocation (uses a garbage
    collection process).
  • All variables are references only referring to
    objects or classes and of any type.
  • Implicit dereferencing of all variables.
  • Smalltalk is a programming methodology and
    programming environment.
  • Integrated program editor, compiler, and virtual
    machine.
  • Interface to environment is the original GUI
    cut/copy/paste environment.
  • Environment almost entirely written in Smalltalk.
  • Generally platform independent.
  • Faster development time rapid
    prototyping/extreme programming easy in
    Smalltalk.
  • Separation of message and method allows for
    polymorphism can have a different meaning
    for each object type (i.e. addition,
    concatenation, etc).

42
CptS 355Programming Language Design
APL
  • Britt Jud
  • WSU Vancouver, Spring 2001

43
History
  • "Iverson Notation" was invented by Kenneth E.
    Iverson while at Harvard University in the late
    1950s.
  • designed to overcome ambiguities of standard
    mathematical notation
  • he used the language to teach mathematics
  • in 1962, he described the Language in a book
    simply titled "A Programming Language" (hence
    APL)
  • Commercial implementation in late 1960's at IBM
  • used to develop and test numerical algorithms
  • rebirth of popularity with PC's now multiple
    dialects
  • Iverson received the Turing Award in 1980

44
Technical Details
  • Dynamic Array Universe
  • key data type arrays of numbers (with very
    flexible operations!)
  • loops deprecated use array operations
    terseness valued
  • Non-Standard Character Set
  • many special symbols including Greek letters
  • each symbol an operation ( hundreds of
    combinations!)
  • Interpreted -
  • great for rapid prototyping
  • lots of high quality numerical libraries

e.g.
45
Sample Code Numerical sort
BASIC 10 DIM X(100 ), (100) 20 READ N 30 FOR I
1 TO N 40 READ X(I) 50 NEXT I 60 FOR I1 TO N
70 LET AX(I) 80 LET L1 90 FOR J1 TO 10 100
IF AltX(J) THEN 130 110 LET AX(J) 120 LETLJ
130 NEXT J 140 LET Y(I)A 150 LET
X(L)1000000. 160 PRINT Y(I) 170 NEXT I 180
DATA ... ... ... XXX END
FORTRAN DIMENSION X(100),Y(100)
READ(5,10) N,(X(I),I1,N) 10 FORMAT
(15/(F10.2)) DO 20 I1,N AX(I)
L1 DO 15 J1,N IF(A-X(J))15,15,12
12 AX(j) LJ 15 CONTINUE Y(I)A
20 X(L)100000. WRITE(6,30) (Y(I),I1,N)
30 FORMAT(E15.2) END
46
Sample Code All primes in array R
  • Select the highest number in desired range, and
    assign to R (e.g., 6 R
  • equals scalar value 6).
  • 2. Generate vector of all integers 1 thru R
    (1, 2, 3, 4, 5, 6). iota function
  • 3. Drop first element from the vector
    (drop 1, retain 2, 3, 4, 5, 6). down arrow
    function
  • 4. Set R to the vector (R equals 2, 3, 4, 5, 6
    ). left arrow function
  • 5. Generate "outer product" of R multiplied
    by R i.e., the multiplication table for R by R.
    R circle dot x R function (See right)
  • 6. Build a vector the same length as R, but
    with 1 in each place where the corresponding
    number in R is in the table true1, and 0 where
    the corresponding number is not false0
    (0, 0, 1, 0, 1). set inclusion function
  • 7. Logically negate the values in the vector
    (change zeros to ones and ones to zeros)
    (1, 1, 0, 1, 0). negation function
  • 8. Select the items in R, for which the
    corresponding element in vector from 7 is one
    (2, 3, 5). slash function, evaluated now due to
    parentheses -- Done!

47
Evaluation
  • An extreme programming language?
  • Very terse programs using extensive character set
  • A PERT program comparison between ASSEMBLER,
    FORTRAN and APL showed the lines of code to be in
    the proportions of 25,000 to 10,000 to 750 and
    the man years of effort, 10 to 5.8 to 1.
  • Still used, but only by devotees
  • requires special keyboard PC makes this easier
  • arrays make some numerical work easy to program
    (e.g. financial)
  • interpretation too slow for production, but great
    for prototyping
  • very hard to modify programs!
  • Influenced other languages indirectly
  • importance of array operations
  • some operations now CS standards

48
CptS 355Programming Language Design
Alain Colmerauer
Robert Kowalski
Prolog
  • Tim Krajcar
  • WSU Vancouver, Spring 2001

prolog.ppt
49
Language Types
most programming languages
imperative
declarative
process-oriented (von Neumann)
data-oriented (object-oriented)
functional
logic
other
matches standard HW efficiency
modelsexternal world maintenance
matchesmathematics experimentation
sophisticatedsearching simplicity
specializedto problem convenience
C
Java
C
Lisp Scheme
Yacc
Prolog
Smalltalk
Fortran Cobol, PL/1 Algol, Pascal
Excel
ML
APL Snobol
Perl
interpreted
compiled
50
Prolog Introduction
  • Forget everything you know!
  • Prolog is a declarative language, rather than
    imperative like C.
  • In C, you describe algorithms, in Prolog, you
    describe facts and rules.
  • Prolog deduces the needed answers.
  • So, Prolog works at a higher level than C, or
    for that matter most programming languages!

51
Prolog Basics
  • A Prolog program doesnt have statements or
    instructions, it has
  • facts and rules.
  • Facts state properties of the system were
    describing.
  • Rules give us ways of deducing new facts from
    existing ones.
  • Because it gives information about a system, a
    Prolog program is often called a knowledge base.
  • So, a program is not run the knowledge base is
    queried.
  • The question is asked Is the fact xyz true?
  • Prolog then answers yes or no, using the
    knowledge base we have provided.
  • It can also tell you all the situations in the
    knowledge base that make that fact true (very
    powerful!)
  • This takes getting used to!
  • Prolog has two basic procedure forms functions
    and relations
  • Functions return one particular answer for a
    given set of inputs. (one-to-many)
  • Relations can return many different answers for
    one set of inputs. (many-to-one)

52
Code Example 1 Genealogy
Facts
Rules
female (elizabeth). male (phillip). female
(diana). male (charles). male (andrew). male
(william). married (elizabeth, phillip). married
(charles, diana). parent (elizabeth,
charles). parent (diana, andrew). parent
(charles, william).
married(X,Y) - married (Y,X). mother (X,C) -
female (X), parent(X,C). father (X,C) - male
(X), parent(X,C). parent (X,C) - married (X,Y),
parent(Y,C).
  • X is parent of C, if
  • X is married to Y, and
  • Y is parent of C

Questions
(an interaction with Prolog using above facts and
rules)
? parent (diana, andrew). yes ? parent
(charles, andrew). yes ? parent (charles,
phillip). no
? parent (X, andrew). X diana X
charles ? parent (charles, C). C andrew C
william
find all X such that X is parent of "andrew"
53
Code Example 2 Change For A Dollar
  • change(H,Q,D,N,P) -
  • member(H,0,1,2), / half-dollars /
  • member(Q,0,1,2,3,4), / quarters /
  • member(D,0,1,2,3,4,5,6,7,8,9,10), / dimes /
  • member(N,0,1,2,3,4,5,6,7,8,9,10,
  • 11,12,13,14,15,16,17,18,19,20), /
    nickels /
  • S is 50H 25Q 10D 5N,
  • S lt 100,
  • P is 100-S.
  • Now we can do some really nifty things!
  • ?- change(0,2,3,4,6).
  • no - since 2 quarters, 3 dimes, 4 nickels, and 6
    pennies does not make a dollar!
  • ?- change(0,2,3,2,P).
  • P10
  • yes
  • ?- change(H,Q,N,D,P).
  • ... all the ways of getting change for a dollar!

54
Prologs History
  • Objective
  • simplify deducing conclusions from facts and
    rules
  • Technique
  • sophisticated searching based on automated
    theorem proving ("unification")
  • Status
  • Developed in Europe during 1970's
  • Robert A. Kowalski, Edinburgh University
    research of theory
  • Alain Colmerauer, University of Aix-Marseille
    actual programming language
  • First practical interpreter built at Edinburgh
    University
  • Wide usage during 1980's via Borland PC-based
    "Turbo Prolog"
  • Steady, but narrow continuing usage
  • Used in Japanese governmental programs
  • Moving now to ISO standardization (1995)
  • Prolog Management Group international consortium
    of Prolog vendors

55
Prologs Significance
  • Not widely known
  • not commonly taught
  • considered impractical and inefficient
  • so unlike everything else that most programmers
    wont take the time to learn
  • But, used in "expert systems"
  • computer configuration planning, CASE, rapid
    prototyping, knowledge bases
  • problems where computers need to simulate human
    reasoning using a constantly growing collection
    of facts and rules
  • And, strong indirect influence on CS
  • power of theorem proving as general programming
    technique
  • repackaged as special libraries to use with
    "normal" languages

56
Learning Further
  • Prolog is something different then almost any
    other language!
  • If youre interested, here are some links
    with some good information.
  • Webpages of the creators
  • Robert Kowalski
  • http//www-lp.doc.ic.ac.uk/UserPages/staff/rak/rak
    .html
  • Alain Colmerauer
  • http//www.lim.univ-mrs.fr/colmer/
  • Code Tutorials
  • http//www.csupomona.edu/jrfisher/www/prolog_tuto
    rial/contents.html
  • http//cbl.leeds.ac.uk/tamsin/prologtutorial/
  • Other Interesting Readings
  • http//www.practical-applications.co.uk/Prolog/all
    i.html
  • http//www.zdnet.com/computershopper/edit/cshopper
    /content/9903/387613.html
  • http//www.math-cs.gordonc.edu/courses/cs323/lectu
    res/prolog.html

57
Learning Further
  • Books
  • PROLOG Programming for Artificial Intelligence,
    by Ivan Bratko
  • The Art of Prolog, by Leon Sterling
  • Programming in Prolog, by W.F Clocksin and C.S.
    Mellish
Write a Comment
User Comments (0)
About PowerShow.com