Skip to content

Commit

Permalink
Fix 5_13
Browse files Browse the repository at this point in the history
It turns out that there's a built in procedure for removing duplicates from lists.
  • Loading branch information
fastred committed Jan 6, 2013
1 parent 6aa9f49 commit fcbcb88
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions 5_13.scm
Expand Up @@ -14,15 +14,11 @@
(else '()))) (else '())))
(define (not-null? x) (define (not-null? x)
(not (null? x))) (not (null? x)))
(define (remove-duplicates l)
(do ((a '() (if (member (car l) a) a (cons (car l) a)))
(l l (cdr l)))
((null? l) (reverse a))))
(define (make-machine ops controller-text) (define (make-machine ops controller-text)
(let* ((machine (make-new-machine)) (let* ((machine (make-new-machine))
(registers-with-dups (filter not-null? (registers-with-dups (filter not-null?
(map extract-register-name controller-text))) (map extract-register-name controller-text)))
(register-names (remove-duplicates registers-with-dups))) (register-names (delete-duplicates registers-with-dups)))
(for-each (lambda (register-name) (for-each (lambda (register-name)
((machine 'allocate-register) register-name)) ((machine 'allocate-register) register-name))
register-names) register-names)
Expand Down

0 comments on commit fcbcb88

Please sign in to comment.