10.07.2015 Views

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

- 207 -iv) find the sum of applying a function fun <strong>to</strong> the numbers between n and zero in steps of s.2) (c.f. Chapter 6 Exercise 2)i) Write a function which indicates whether or not a list starts with a sub-list. For example:(lstarts ’(1 2 3) ’(1 2 3 4 5)) ->t(lstarts ’(1 2 3) ’(4 5 6)) ->nilii) Write a function which indicates whether or not a list contains a given sub-list. For example:(lcontains ’(4 5 6) ’(1 2 3 4 5 6 7 8 9)) ->t(lcontains ’(4 5 6) ’(2 4 6 8 10)) ->niliii) Write a function which counts how often a sub-list appears in another list. For example:(lcount ’(1 2) ’(1 2 3 1 2 3 1 2 3)) ->3iv) Write a function which removes a sub-list from the start of a list, assuming that you know that the sub-liststarts the list. For example:(lremove ’(1 2 3) ’(1 2 3 4 5 6 7 8 9)) ->(4 5 6 7 8 9)v) Write a function which deletes the first occurence of a sub-list in another list. For example:(ldelete ’(4 5 6) ’(1 2 3 4 5 6 7 8 9) ->(1 2 3 7 8 9)(ldelete ’(4 5 6) ’(2 4 6 8 10)) ->(2 4 6 8 19)vi) Write a function which inserts a sub-list after the first occurence of another sub-list in a list. For example:(linsert ’(4 5 6) ’(1 2 3) ’(1 2 3 7 8 9)) ->(1 2 3 4 5 6 7 8 9)(linsert ’(4 5 6) ’(1 2 3) ’(2 4 6 8 10)) ->(2 4 6 8 10)vii) Write a function which replaces a sub-list with another sub-list in a list. For example:(lreplace ’(6 5 4) ’(4 5 6) ’(9 8 7 6 5 4 3 2 1)) ->(9 8 7 4 5 6 3 2 1)(lreplace ’(6 5 4) ’(4 5 6) ’(2 4 6 8 10)) ->(2 4 6 8 10)3) (c.f. Chapter 6 Exercise 3)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!