110 likes | 222 Views
Case Study. Functional Programming Languages Logic Programming Languages. Functional Languages. There are many functional languages. Scheme Haskell F# ML Lisp Others. Scheme.
E N D
Case Study Functional Programming Languages Logic Programming Languages
Functional Languages • There are many functional languages. • Scheme • Haskell • F# • ML • Lisp • Others
Scheme • Scheme was developed at the MIT AI Lab by Guy L. Steele and Gerald Jay Sussman who introduced it to the academic world via a series of memos • Defining Variable: (define a 10) (+ a 2)
Scheme • Printing : (display "Hello world") • To put new line: (newline) • Arithmetic Expression: (+ 4 6 7)
Scheme • Assignment Statement: (define b 10) (* b 2) (set! b 30)
Scheme (define (greet) (display "Hello, world!") (newline) ) (let ((x 1) (y 2)) (+ x y))
Logic Language • Prolog • Developed at Univ. of Aix-Marseille and Edinburgh in early to mid 1970s • Goal: natural language processing and theorem proving. • Used in Japan’s Fifth Generation Computing Project in 1981
Prolog • Prolog Syntax • Variables are uppercase • constants, predicates are lowercase • List syntax: • [1, 2, 3] • [head | tail] • Program consists of • facts, rules, and goals
Prolog • Facts female(shelley). male(bill). female(mary). male(jake). father(bill, jake). father(bill, shelley). mother(mary, jake). mother(mary, shelley).
Prolog • Rules parent(X, Y) :- mother(X, Y). parent(X, Y) :- father(X, Y). grandparent(X, Z) :- parent(X, Y), parent(Y, Z). sibling(X, Y) :- mother(M, X), mother(M, Y), father(F, X), father(F, Y). ancestor(X, X). ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y)
Prolog • Queries ?- father(bill, jake). yes ?- father(X, jake). X = bill yes ?- father(bill, X). X = jake ; X = shelley yes