1/29
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
(iterated-above (lambda (i) (circle 20 "solid" "blue")) 4)
Give an example of an iterated image function
(lambda (n) immediately after the iterated function itself
What MUST be included in (iterated-above/below/overlay) for it to be valid?
Bullseye, starts at 0 with an invisible circle. (* 10 (+ i 1)) calculates the radius, making it dependent on the iteration index i
What does this produce, and which part of the function allows that?
(iterated-overlay
(lambda (i) (circle (* 10 (+ i 1)) "solid" "purple"))
5)
(interpolate-colors (color 255 0 0) (color 0 0 255) 0.6)
Use interpolate-colors to write a mix of 40% red and 60% blue
Defining the radius to be dependent on a input variable n, multiplying it by 10 and then adding 10 to it.
What is this function doing:
(define (ring-radius n)
(+ 10 (* 10 n)))
(check-expect (function-call...) expected-result)
Give the general format of a check expect function
To store multiple values together under one name
What is the purpose of a list?
Define only accepts one expression for the value. Therefore, we must wrap the several elements inside one element (list).
(define num-list (list 2 3 4 5 6))
(check-expect num-list (list 2 3 4 5 6))
Identify, explain, and fix the mistake in this list
(define num-list 2 3 4 5 6)
List is not a function, hence no parenthesis. (list num-list) is a function to create a new list.
(check-expect (list? num-list) true)
Identify, explain, and fix the mistake
(check-expect (list num-list) true)
Applying a function to every element in a list. Produces a new list. Maps everything to a new list.
What is the purpose of the map function?
(map (lambda (x) (expression using x) list)
Give the general syntax of the map function, which returns a new list after a function has been applied to every element in a list.
Multiplication is a function, hence needs to be preceded by parenthesis.
(map (lambda (x) (* 5 x)) (list 1 2 3))
Fix and explain the mistake with the "map" function that returns a new list after a function is applied to every element in the list
(map * 5 (list 1 2 3))
Multiplication cannot multiply a number by an entire list. The first argument must be a function like lambda, or something else which can take multiple arguments.
Fix and explain the mistake with the "map" function that returns a new list after a function is applied to every element in the list
(map (* 5 (list 1 2 3)))
Map must ALWAYS have list as the last argument. The function is defined but there is no new list created, since 1 2 3 are not defined as lists. They are just numbers floating around, and lambda cannot be called with all of them as the input for x.
(map (lambda (x) (* x 5)) (list 1 2 3))
Fix and explain the mistake
(map (lambda (x) (* x 5)) 1 2 3)
To modify a pre-existing list, to keep only list elements for which a condition is true
Define the purpose of the filter function?
(filter (lambda (x) insert-boolean-expression-here, either mathematically or true?) (list elements of list))
Write the general syntax for a filter function
The boolean function does not define what is being compared to 3.
(filter (lambda (x) (> x 3)) (list 1 2 3 4)
Explain and fix
(filter (lambda (x) (> 3)) (list 1 2 3 4))
Lambda only takes one boolean and only one input. If multiple booleans are inserted, they must be combined and wrapped with and or.
(filter (lambda (x) (or (= x 2) (> x 5))) (list 1 2 3 4 6))
Explain and fix
(filter (lambda (x) (= x 2) (> x 5)) (list 1 2 3 4 6))
To combine all the elements of a list into a single value
What is the purpose of foldl
(foldl (lambda function start-value (initial list))
Give the general format of foldl
(foldl + 0 (list 1 2 3 )) outputs 6
Give a correct syntax example of foldl
No start value is provided. 0 is the start value for sums, 1 is the start value for products.
(foldl + 0 (list 1 2 3))
Fix and explain
(foldl + (list 1 2 3))
No parenthesis necessary when passing a function as an argument to another function, which is meant to take in a function. Only necessary when nesting another function as an input.
Why no parenthesis before the plus?
(foldl + (list 1 2 3))
10, since 4 is the start value aka the accumulator
What would this produce?
(foldl + 4 (list 1 2 3))
Foldl always accepts 2 arguments: current list element, and accumulator. The lambda in this only takes 1 argument. Acc is undefined, since it isn't defined as a parameter of lambda. Acc means accumulator, where it starts, and the value it combines with x.
(foldl (lambda x acc) (+ x acc)) 5 (list 1 2 3))
x = 5
accumulator = (list 1 2 3)
Fix and explain
(foldl (lambda (x) (+ x acc)) 0 (list 1 2 3))
To test if all the elements of a list satisfy a condition
What is the purpose of the function andmap?
(andmap (lambda (x) (< x 3)) (list 1 2))
Write a correct example of andmap
One boolean value, true or false
What is the output of an andmap function?
Passing 3 separate arguments to lambda when it only accepts 1. Needs to combine 1 2 and 3 into a list.
(andmap (lambda (x) (< x 3)) (list 1 2 3))
Fix this andmap mistake
(andmap (lambda (x) (< x 3)) 1 2 3)
Only one expression can be passed for lambda.
(andmap (lambda (x) (and (
Fix this andmap mistake
(andmap (lambda (X) (< x 3) (> x 0)) (list 1 2 3))