数据修改
十二课
(define x 10)
(+ x 5)
> 15
(set! x 94)
(+ x 5)
> 99Pair/List Mutation
;constructor
(cons x y) ; creates a new pair p
; selectors
(car p) ; returns car part of pair
(cdr p) ; returns cdr part of pair
; mutators
(set-car! p new-x) ; changes car pointer in pair
(set-cdr! p new-y) ; changes cdr pointer in pair
; Pair, anytype -> undef ; side-effect onlyEquivalence and Identity
例1:Stack Data Abstraction
例2:Queue Data Abstraction
Last updated