{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

DayEight

# DayEight - parameter has order 1 o Inductive – Function...

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

let and High Order Functions

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

View Full Document
let in general let o val varName = expression o val varName2 = expression o o val varNamen = expression in o expression end;
let ’s importance Allows us to split apart parts that must be split before we use them. let example – Create a function that splits apart a list. The function should return a tuple that contains 2 lists. The first list should contain the odd elements (i.e. 1 st , 3 rd , 5 th ,…) and the second list should contain the even elements (2 nd , 4 th , 6 th , …).

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

View Full Document
Let example Using the merge function and using the split function, create a function that implements mergeSort.
More than just convenience? Can also help a function run correctly Create a function that implements the quadratic formula o First without using let o Second using let o Third using exceptions

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

View Full Document
High Order Functions Function that takes a function as an argument Function that produces a function as output Every function has an order: o Base – Function that does not take parameter as a function or return a

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: parameter has order 1. o Inductive – Function that takes a function as a parameter or returns a function value has order (n+1) where n is the order of its highest-order parameter or returned value. High Order Functions • Consider the problem of filtering out a list based on some criteria. • Create a function that accepts an integer and returns true if that number is greater than 0, false otherwise. • Create a function that accepts a string and returns true if the string is a palindrome, false otherwise. • Create a function that accepts a list and a function that will be used to “filter” out bad elements. Map Example • Write a function that doubles the value of every element in a list. • Write a function that squares the value of every element in a list. • Write a generic map function that accepts (lst, f) and returns the following list: [ f(lst[0]), f(lst[1]), f(lst[2]), …, f(lst[n]) ]...
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

DayEight - parameter has order 1 o Inductive – Function...

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

View Full Document
Ask a homework question - tutors are online