-
Notifications
You must be signed in to change notification settings - Fork 10
/
2.74.ss
43 lines (36 loc) · 1.33 KB
/
2.74.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(define (install-branch-package)
(define branch-file
(list 'branch ('branch name salary)))
(define (make-employee name salary)
(list 'branch name salary))
(define (name employee-record) (cadr employee-record))
(define (salary employee-record) (caddr employee-record))
(define (find-employee-record name)
(define (find-record-iter name file)
(if (null? file)
(error "NO FOUND -- BRANCH" name)
(let ((first-record (car file)))
(if (eq? name (name first-record))
first-record
(find-record-iter name (cdr file))))))
(find-record-iter name (cdr branch-file)))
(put 'name '(branch) name)
(put 'salary '(branch) salary)
(put 'find-employee-record '(branch) find-employee-record)
(put 'make-employee '(branch)
(lambda (name salary) (make-employee name salary)))
'done)
; a)
(define (get-record name file-name)
((get 'find-emloyee-record file-name) name))
; b)
(define (get-salary name file-name)
(let ((record (get-record name file-name)))
((get 'salary file-name) record)))
; c)
(define (find-employee-record name file)
(let ((first-file-name (caar file)))
(let ((emp-record (get name first-file-name)))
(if emp-record
emp-record
(find-employee-record name (cdr file))))))