1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
To create a custom data type with named fields. Groups pieces of related information together.
What is the purpose of a struct? define-struct
(define-struct russian-dance-team (nickname height coach lifts-per-program))
Give a correct example of creating a struct
No parenthesis separating the field names from the struct name itself
(define-struct cat (name breed color meow-volume)
Fix and explain:
(define-struct cat name breed color meow-volume)
Does not specify the type of item as struct, therefore cat seems like a variable
Fix and explain:
(define cat (name breed color meow-volume))
the inner 2 arguments are not defined as lists, so they are passed as function or variable inputs instead.
List of lists, nested lists. Explain and fix
(define list-of-lists (1 2) (3 4))
No parenthesis necessary at *, 1 is taken as the accumulator start value. But outer list needs sub-lists, not numbers .
(map (lambda (xub) (fodll * 1 sub)) list-of-lists)
Nested lists, explain and fix
(foldl * 1 list-of-lists)
To extract and combine different parts of strings
What is the purpose of a substring and string-append function
(string-append "a" "n" "n" "a")
Write a correct example of string-append
Substring needs both a start and end indice, even if only producing one letter.
(substring "hello" 0 1)
Explain and fix
(substring "hello" 0)
Nothing! string-append doesn't need a parenthesis since it is a function being passed as an argument to foldl
Explain and fix
(foldl string-append "" (list "a" "b" "c"))
Libraries take lists of string input
(define pop-lib (list (make-track "living la vida loca" "ricky martin" "pop")))
Explain and fix this library
(define pop-lib (make-track "livin la vida loca" "ricky martin" "pop"))
Doesn't define the name of the struct. Needs to make-something for it to be findable as a "something"
(define latin-library (list (make-song "voy a reir" "marc anthony" "ice dance")))
Explain and fix this library
(define latin-library (list "voy a reir" "marc anthony" "ice dance"))
(define-struct track (title artist genre))
(list of track) -> (list of string) where all the strings are song titles,
Give the type signature of this function, which extracts all song titles from a library
(define all-titles
(lambda (lib)
(map track-title lib)))
(define-struct skating-programs (team year music))
Define a struct with a title and the input types
Not using the complete struct name.
(map (skating-programs-team name-of-new-list-here)
Fix and explain
(define-struct skating-programs (team year music))
(map programs team)
Should use map, not foldl. We are transferring items to a new list, not combining.
Fix and explain
(foldl skating-program-title empty lib)
(filter (lambda (t) (string=? team (track-year t))) name-of-a-new-list)
Use filter not map, because map returns booleans. Andmap returns a single boolean. Filter iterates through and edits the list.
Write a line of code from this struct that outputs a list of all the programs by a specific ice dance team
(define-struct skating-programs (team year music))
(map programs team)
(= (music (skating-programs-music "upbeat" library)) 2)
Write a boolean function to produce #true or #false from testing whether a team's music fits the upbeat 90s theme