324-lecture11 - Principles of Programming Languages...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Principles of Programming Languages Principles of Programming Languages Lecture 11 Lecture 11 University of Toronto Wael Aboulsaadat Wael Aboulsaadat wael@cs.toronto.edu wael@cs.toronto.edu http://portal.utoronto.ca/ 1 SC324: Principles of Programming Languages cheme Practice 4 cheme Practice 4 Write a Scheme function rm-dupl that is called as (rm-dupl L). L is a list of atomic values. rm-dupl removes duplicate values in L, returning a list in which each value only appears once (the order of values is unimportant). You can use member? For example: ]=> (rm-dupl '(1 2 3 4)) (1 2 3 4) ]=> (rm-dupl '(1 1 1 1)) ) University of Toronto (1) ]=> (rm-dupl '(a b c b c a)) (b c a) ( define (remove-duplicates lst) ( cond (( null? lst) ()) (( member? ( car lst) ( cdr lst)) (remove-duplicates ( cdr lst))) (else ( cons ( car lst) (remove-duplicates ( cdr lst)))))) 2 SC324: Principles of Programming Languages cheme Practice 4 cheme Practice 4 - trace trace ( define (remove-duplicates lst) ( cond (( null? lst) ()) (( member? ( car lst) ( cdr lst)) (remove-duplicates ( cdr lst))) (else ns r t (remove uplicates ( r t )))) University of Toronto ( cons ( car lst) (remove-duplicates ( cdr lst)))))) ]=> (remove-duplicates (b b c b)) (remove-duplicates (b c b)) (remove-duplicates (c b)) (cons c (remove-duplicates(b)) (c b) (c b) (c b) 3 SC324: Principles of Programming Languages cheme Practice 4 cheme Practice 4 - trace trace ( define (remove-duplicates lst) ( cond (( null? lst) ()) (( member? ( car lst) ( cdr lst)) (remove-duplicates ( cdr lst))) (else ns r t (remove uplicates ( r t )))) University of Toronto ( cons ( car lst) (remove-duplicates ( cdr lst)))))) ]=> (remove-duplicates (b b c b)) (remove-duplicates (b c b)) (remove-duplicates (c b)) (cons c (remove-duplicates(b)) (c b) (c b) (c b) 4 SC324: Principles of Programming Languages cheme Practice 4 cheme Practice 4 - trace trace ( define (remove-duplicates lst) ( cond (( null? lst) ()) (( member? ( car lst) ( cdr lst)) (remove-duplicates ( cdr lst))) (else ns r t (remove uplicates ( r t )))) University of Toronto ( cons ( car lst) (remove-duplicates ( cdr lst)))))) ]=> (remove-duplicates (b b c b)) (remove-duplicates (b c b)) (remove-duplicates (c b)) (cons c (remove-duplicates(b)) (c b) (c b) (c b) 5 SC324: Principles of Programming Languages cheme Practice 4 cheme Practice 4 - trace trace ( define (remove-duplicates lst) ( cond (( null? lst) ()) (( member? ( car lst) ( cdr lst)) (remove-duplicates ( cdr lst))) (else ns r t (remove uplicates ( r t )))) University of Toronto ( cons ( car lst) (remove-duplicates ( cdr lst)))))) ]=> (remove-duplicates (b b c b)) (remove-duplicates (b c b)) (remove-duplicates (c b)) (cons c (remove-duplicates(b)) (c b) (c b) (c b) 6 SC324: Principles of Programming Languages cheme Practice 4 cheme Practice 4 - trace trace ( define (remove-duplicates lst) ( cond (( null? lst) ()) (( member? ( car lst) ( cdr lst)) (remove-duplicates (...
View Full Document

Page1 / 42

324-lecture11 - Principles of Programming Languages...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online