YouTube 公开课mutual reference
视频好像用处不大,看的过程中头上插满了问号
小编觉得可能是大神录到这章的时候,已经情绪高涨, 一不小心讲飘了。。。
但这章是110的分水岭,mutual reference之后整门课好像换了一个难度,这编
notes有点长,但小编想尝试用人类的角度去理解一下mutual reference
在reference那章, 我们接触了list + compound data
假设我们想记录一个家族的眼睛颜色. 有person这么一种定义,他是有自己的名字(name)和眼睛
颜色(color), 然后我们也可以表示person的集合(ListOfPerson)
;; Color is one of:
;; - "Green"
;; - "Black"
;; - "Brown"
;; - "Blue"
;; inperp. the colors of eye
(define-struct person (name color))
;; Person is (make-region String Color)
;; interp. A person with its name, its eye color
;; ListOfPerson is one of:
;; - empty
;; - (cons Person ListOfPerson)
;; interp. a list of persons
(define Carl (make-person "Carl Williams" "Green"))
(define Bettina (make-person "Bettina Williams" "Black"))
(define Olivia (make-person "Olivia Williams" "Brown"))
(define Isabella (make-person "Isabella Williams" "Blue"))
(define Emily (make-person "Emily Williams" "Green"))
(define Jack (make-person "Jack Williams" "Blue"))
(define LOP0 (list Carl Bettina Olivia Isabella Emily Jack))
(list的用法)javaIsTheBest
我们可以表达一个person的list,但是, 如果我们想表达这么一种关系尼?
一个person和他的children,呈现级别关系
要这样表达data的话,我们只能在Person里面添加ListOfPerson
(define-struct person (name color children))
;; Person is (make-region String Color ListOfPerson)
;; interp. A person with its name, its eye color
那么 Person 里面reference 了 ListOfRegion, 而ListOfPerson 又reference 了region. 这就是mutual reference
comment 和 tempalte对应的箭头名字
Comment aaaaaaaaaaaaaaaaaa Template
R(reference) aaaaaaaaaaaaaaaa NH(natural helper)
MR(mutual reference) aaaaaaa NMR(natural mutual recursion)
SR(self reference) aaaaaaaaaaa NR(natural recursion)
现在就可以通过bottom-up的方法把Jack的family tree写出来
(define Carl (make-person "Carl Williams" "Green" empty))
(define Bettina (make-person "Bettina Williams" "Black" empty))
(define Olivia (make-person "Olivia Williams" "Brown" empty))
(define Isabella (make-person "Isabella Williams" "Blue" empty))
(define Emily (make-person "Emily Williams" "Green" (list Carl Bettina Olivia)))
(define Jack (make-person "Jack Williams" "Blue" (list Emily Isabella)))
全部的code和例题javaIsTheBest