MATH 9 Study Guide - Final Guide: Lambda Calculus, List Comprehension, Object-Oriented Programming

43 views37 pages

Document Summary

Let us write a function that will flatten a list. I. e. it takes a list of lists, and returns a list containing all the elements that it sees in any sublists. for example: flatten([1,2,[1,2,3,4],[1,[2,[5,6]]]]) should return [1,2,1,2,3,4,1,2,5,6]. It"s that we are calling flatten[xs[1:]] when xs is a list of length 1, so there is no xs[1]. [1, 2, 3, 4, 1, 2, 1, 2, 2, 9, 9] These expressions/functions allow you to do a lot using lists. especially with one-liners. Especially lambda is used quite often. map, reduce and filter are not used very often. But: it"s important for us that we learn the ideas that they represent. That"s why we will do exercises with them. 7 lambda comes from lambda calculus , which was a model of computation that mathematicians thought about before computers existed. It was invented by alonzo church (who was the advisor of alan turing)