SICP OpenCourse (Structure and Interpretation of Computer Programs)
PART 1
1.POINT: A NEW LANGUAGE, FROM "HOW-TO" TO "WHAT"
2.ONE PIECE OF DECLARATIVE KNOWLEDGE CAN BE USED AS THE BASIS FOR A LOT OF DIFFERENT KINDS O HOW-TO KNOWLEDGE.
- Old program focus on "HOW-TO"
- new program focus on "WHAT"
- And the language knowing how-to do that automatically
Old:
x & y ===> MERGE--->ANS
New: 关注定位
MERGE-TO-FORM X, Y , Z
3.WHAT IS THE NEW LANGUAGE
- The first is , we're not going to be computing functions, We're not going to be talking about things that take input and output.
- We're going to talking about relations
- These relations don't have directionality
- Knowledge, One knowledge Many answer
- The second issue is that since we're talking about relations, these relations don't necessarily have one answer. So that third question down there doesn't have a particular answer, it has a whole bunch answers.
4.Logic Programming 's little phrase
- You use logic to express what is true.
- You use logic to check whether something is true
- You use logic to find out what is true.
- We call our PL Query language and is essentially has the essence of prolog.
5.EXAMPLE
-DATA PART AND RELATION
SON-OF ADAM ABEL
SON-OF ADAM CAIN
SON-OF CAIN ENOCH
-RULE PART
IF (SON-OF ?X ?Y) AND
(SON-OF ?Y ?Z)
THEN (GRASON ?X ?Z)
6.My understanding
- THREE PARTS :
- Primitives : address , private / public key, bitcoin
- Means of Combination : How to express BASIC RELATION - TX, basic business
- Means of Abstraction : RULE, BUSINESS LOGIC - Tree of Metanet, protocol, real business.
PART 2
7.HOW TO DESIGN A NEW LANGUAGE
- Primitives : QUERY
- Means of Combination : AND NOT OR LISP-VALUE
- Means of Abstraction : Rule
8.PRIMITIVES : QUERY
(job ?x (computer programmer))
matches
(job (Hacker Alyssa P)
(computer programmer))
(job ?x (computer ?type))
matches
(job (Bitdiddle Ben)(computer wizard))
(job (Hacker Alyssa P)(computer programmer))
(job ?x (computer ?type)
doesn't match
(job (Reasoner Louis)
(computer programmer trainee))
9.MEANS OF COMBINATION
(and (job ?x (computer . ?y))
(supervisor ?x ?z))
- MEANS List all people who work in the computer division. together with their supervisors
(and (salary ?p ?a)
(lisp-value > ?a 30000))
- List all people whose salary is greater than 30000
(and
(job ?x (computer . ?y)
(not (and (supervisor ?x ?z)
(job ?z (computer . ?w)))))
- List all people who work in the computer division. who do not have a supervisor who works in the computer division.
- This is why it's called a logic language are logic operations.
10.MEANS OF ABSTRACTION=> RULES
(rule
(bigshot ?x ?dept) //RULE CONCLUSION
(and // RULE BODY
(job ?x (?dept . ?y))
(not (and (supervisor ?x ?z)
(job ?z (?dept . ?w))))))
=>(MERGE-TO-FORM ?X ?Y (1 2 3 4 5)
-->(MERGE-TO-FORM (1 2 3 4) (5) (1 2 3 4 5)
-->(MERGE-TO-FORM (1 2 3) (45) (1 2 3 4 5)
...
- DETEMIN MERGE-TO-FORM
(RULE MERGE-TO-FORM () ?Y ?Y))
(RULE MERGE-TO-FORM ?Y () ?Y))
(RULE
(MERGE-TO-FORM
(?A . ?X)(?B . ?Y)(?B . ?Z))
(AND (MERGE-TO-FORM (?A . ?X) ?Y ?Z)
(LISP-VALUE > ?A ?B)))
=>(MERGE-TO-FORM (2 ?A) ?X (1 2 3 4))
-->(MERGE-TO-FORM (2 3) (1 4) (1 2 3 4))
-->(MERGE-TO-FORM (2 4) (1 3) (1 2 3 4))
- And those are the three elements of this language. Let's break now and then we'll talk about how it's actually implemented.
网友评论