Homework3-sol

Homework3-sol - ) ) 3. let rec power n x = n eq 0 -> 1 |...

This preview shows pages 1–2. Sign up to view the full content.

sol3.txt COP 5555 - Programming Language Principles Solution to Homework 3 1. (a) -> (b) (_____->_____) (c) tau / | \ / | \ / | \ or x -> infix -> x aug z 3 / \ / | \ / | \ / | \ / \ x y z x y x eq y z x y x y (d) tau (e) (__let___) (f) same as (e) / | \ / \ x y aug fcn_form where / \ / | \ / \ z 3 f x + G = / \ / \ / \ * 1 f z z 6 / \ x 2 (g) (__let__) (h) No AST possible; / \ a definition following 'where' and ** cannot contain 'and' unless / \ / \ the definition is parenthesized. = = x ** / \ / \ / \ x z y where y y / \ * = / \ / \ 2 z z 3 2. (a) x or y -> x | z -> x | y (b) x eq y -> z -> x | y | x (c) x aug y, z, 3 (d) x, y, z aug 3 (e,f) let f(x) = X*2+1 in f(z) where z=6 (g) let x = z and y = 2 * z where z = 3 in x** y**y (h) Not possible. Page 1

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

View Full Document
sol3.txt 3. let x = a*b/c in e or f -> g -> x**x**2 | y | ( f x where ( f y = y*2 and x = 3+x*2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ) ) 3. let rec power n x = n eq 0 -> 1 | (n / 2) * 2 eq n-> power (n/2) (x*x) | x*(power (n-1) x) in Print(power 3 2) 4. let merge (list1,list2)= S(list1, 1, list2, 1, nil) where (rec S(list1, index1, list2, index2, list) = (index1 le (Order list1)) & (index2 le (Order list2)) -> ((list1 index1) le (list2 index2) -> (S(list1, index1+1, list2, index2, list aug (list1 index1))) |(S(list1, index1, list2, index2+1, list aug (list2 index2))) ) | (index1 le (Order list1)) -> ( S(list1, index1+1, list2, index2, list aug (list1 index1))) |(index2 le (Order list2)) -> ( S(list1, index1, list2, index2+1, list aug (list2 index2))) | list ) in let list1 = (1,3,4,7) in let list2 = (2,4,6,7,8) in Print(merge(list1, list2)) Page 2...
View Full Document

This note was uploaded on 01/22/2012 for the course COP 5555 taught by Professor Staff during the Fall '08 term at University of Florida.

Page1 / 2

Homework3-sol - ) ) 3. let rec power n x = n eq 0 -> 1 |...

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

View Full Document
Ask a homework question - tutors are online