CSC 4101 Chapter : Homework 5 Solutions

17 views2 pages
15 Mar 2019
School
Course
Professor

Document Summary

Homework 5 solutions: here is a solution for instersect as well. In ml: fun member e nil = false. | member e (h::t) = (e = h) orelse (member e t) fun intersect nil _ = nil. | intersect (h::t) l2 = if member h l2 then h :: (intersect t l2) else intersect t l2 fun union nil l2 = l2. | union (h::t) l2 = if member h l2 then union t l2 else h :: (union t l2) The built-in scheme function memv (without a question mark) returns the remainder of the list if the element was found instead of just a boolean. I indicated the rule from the database that was matched and the bindings produced. Using rule 4: mymember(1, [2,3]), intersect([2], [2,3], l3). where h=1, t=[2], l2=[2,3], x=[1|l3] Using rule 2: mymember(1, [3]), intersect([2], [2,3], x). where e=1, t=[3] Using rule 2: mymember(1, []), intersect([2], [2,3], x). where e=1, t=[]

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents