This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
У Хьюго Дума не получается вызвать магнитуду потому, что для неё не определён комплексный селектор. Добавление Лизы это исправляет. Теперь первый раз applugeneric идёт для типа complex, второй раз для типа retangular, а дальше диспетчирует к его процедуре magnitude. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Обобщённые данные с явной диспетчеризацией: | |
а) При добавлении типа: | |
Добавить специфичные методы этого типа | |
Изменить обобщённые методы с учётом нового типа | |
б) При добавлении операции: | |
Добавить специфичную для него реализацию | |
Добавить обобщённую реализацию | |
2. Стиль, управляемый данными: | |
а) При добавлении типа: | |
Добавить пакет операций для нового типа |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-from-mag-ang r a) | |
(define (dispatch op) | |
(cond ((eq? op 'real-part) (* r (cos a))) | |
((eq? op 'imag-part) (* r (sin a))) | |
((eq? op 'magnitude) r) | |
((eq? op 'angle) a) | |
(else | |
(eror "Unknown op -- MAKE-FROM-MAG-ANG" op)))) | |
dispatch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;-------------put-get----------------------------------------- | |
(define global-array '()) | |
(define (make-entry k v) (list k v)) | |
(define (key entry) (car entry)) | |
(define (value entry) (cadr entry)) | |
(define (put op type item) | |
(define (put-helper k array) | |
(cond ((null? array) (list(make-entry k item))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;a Предикаты number? и variable? не содержат операцию, по которой собственно и происходит диспетчеризация. | |
;bc | |
;-------------put-get----------------------------------------- | |
(define global-array '()) | |
(define (make-entry k v) (list k v)) | |
(define (key entry) (car entry)) | |
(define (value entry) (cadr entry)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-leaf symbol weight) | |
(list 'leaf symbol weight)) | |
(define (leaf? object) | |
(eq? (car object) 'leaf)) | |
(define (symbol-leaf x) (cadr x)) | |
(define (weight-leaf x) (caddr x)) | |
(define (adjoin-set x set) | |
(cond ((null? set) (list x)) | |
((< (weight x) (weight (car set))) (cons x set)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-leaf symbol weight) | |
(list 'leaf symbol weight)) | |
(define (leaf? object) | |
(eq? (car object) 'leaf)) | |
(define (symbol-leaf x) (cadr x)) | |
(define (weight-leaf x) (caddr x)) | |
(define (adjoin-set x set) | |
(cond ((null? set) (list x)) | |
((< (weight x) (weight (car set))) (cons x set)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-leaf symbol weight) | |
(list 'leaf symbol weight)) | |
(define (leaf? object) | |
(eq? (car object) 'leaf)) | |
(define (symbol-leaf x) (cadr x)) | |
(define (weight-leaf x) (caddr x)) | |
(define (make-code-tree left right) | |
(list left | |
right |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (entry tree) (car tree)) | |
(define (left-branch tree) (cadr tree)) | |
(define (right-branch tree) (caddr tree)) | |
(define (make-tree entry left right) | |
(list entry left right)) | |
(define tree1 (make-tree 7 | |
(make-tree 3 | |
(make-tree 1 '() '()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (entry tree) (car tree)) | |
(define (left-branch tree) (cadr tree)) | |
(define (right-branch tree) (caddr tree)) | |
(define (make-tree entry left right) | |
(list entry left right)) | |
(define (tree->list tree) | |
(define (copy-to-list tree result-list) | |
(if (null? tree) | |
result-list |