* Lecture 8A: Logic Programming, Pt 1
hal lookin real cute in that shirt!!

last time we looked at how languages are constructed,
made of two parts:
  - eval
    - takes exp and env
  - apply
    - takes proc and args

once you have the interpreter, we have the power to play with the
language. more generally, we have /metalinguistic abstraction/

we can gain control of complexity by inventing new languages

computer programming is only incidentally about getting a computer to
do something. primarily, it's a way of expressing ideas.

today we are going to apply this idea to build a new language

instead of "building pascal" we are going to make a really different
language. this lecture is at two simultaneous language levels:
  - what the language looks like
  - how it's implemented

lessons to learn:
  - how different a language can be
  - how it still comes down to eval/apply
  - how streams are cool

DECLARATIVE KNOWLEDGE: what is

what if we could bridge the gap between imperative knowledge and
declarative knowledge.

we might go to this program and tell it some things:

: son-of adam abel
: son-of adam cain
: son-of cain enoch
: son-of enoch irad

once we've told it these facts, we might ask it things

declarative is unbiased as to what to derive. our procedures take a
certain and give a certain output, specifically. biased to what we are
asking of it.

let's invent a syntax:

: if (son-of ?x ?y) and
:  (son-of ?y ?z)
:    then (grandson ?x ?z)

Logic Programming allow us to express relationships that express what
is true, check what is true, and find out what is true.

prolog does this, and we are going to build something very similar

--> break

an employee database.

this is the first time they've mentioned a book character by name!

: (job (bitdiddle ben) (computer wizard))
: (salary (hacker alyssa p) 3500)
: (supervisor (tweakit lem e) (bitdiddle ben))
: (address (reasoner louis) (slumerville (pine tree road) 80))
: ...

once more, the most important thing:

  - primitives

  - means of combination

  - means of abstraction

in this language, we have one primitive, the query:

: (job ?x (computer programmer))
: (job ?x (computer ?type))
: (job ?x (computer . ?type))

means of combination, compound queries 
  (logical operations such as and, not, or):

: (and (job ?x (computer . ?y))
:      (supervisor ?x ?z))

: (and (salary ?p ?a)
:      (lisp-value > ?a 30000))

means of abstraction, rules:

: (rule
:  (bigshot ?x ?dept)
:  (and
:   (job ?x (?dept . ?y))
:   (not (and (supervisor ?x ?z)
:             (job ?z (?dept . ?w))))))

--> break
* Lecture 8B: Logic Programming, Pt 2
we've seen how the query language works, now we can look at how it's
implemented. 

: (match pattern data dictionary)

can we match this pattern against this data subject to the bindings in
the dictionary?

the pattern takes in two streams,
  - the database
  - dict of var bindings

it's important that all the building blocks (and, not, or) look the
same from the outside (black box with two stream inputs, one stream
output)

:      +-----+
: ---> |     | --->
:      +-----+
:         ^
:         |
:      ---+

       CLOSURE

--> break

we also need a unifier, to combine multiple patterns

"it looks like this thing is being very clever but it's not being
really clever at all"

--> break

"let's turn to a more profound question: what do these things mean?"

classic logic!

: all humans are mortal.
: all greeks are human.
: socrates is a greek.

: ∴ socrates is a mortal

in our language, not is not not

in logic, not is not true

in our language, not is not deducible

the CLOSED WORLD ASSUMPTION

"anything i dont know cannot be true" -- harry back with the corporate
					 commentary humor!! lol
