Functional Problem Solving (CSC 151 2014F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Overview
Could you explain Problem 2 on Assignment 5?
Please explain Euclidean distance
Requires whiteboard. (Sam will try to transcribe.)
list
, make-list
, iota
map
append
reverse
- obviouslist-take
and list-drop
- build a new list by taking the first
N elements or dropping the first N elementscar
- get the first elementcdr
- get all but the first elementcadr
- get the second elementcons
- given a value and a list, build a new list by shoving a
value on the frontlist-ref
- given a list and a number, extract the particular
value from the listIs there a way to put an element at the end of a list?
No built-in one, but you can probably figure out some strategy.
(append lst (list val))
(reverse (cons val (reverse lst)))
How do you get the last element in a list?
(list-ref lst (+ -1 (length lst)))
(car (reverse lst))
How do we refer to the empty list?
Any of the following
null
'()
(list)
(make-list 0 "anything")
I prefer
null
.
Why do the indices start with 0 rather than 1?
Computer scientists like to start counting with 0.
It lets you think of
(list-ref lst i)
as "take thecdr
i times, then take thecar
"
What would lead you to name three lists one-two
, won-too
, and want-to
?
Lack of sleep.
Congratulations, you are the last class that will ever have to deal with these stupid names.
Why did we have that exercise?
To reinforce that "if you ssee a period, it's not a list"
What do you think of the following code to find element 5 using cdr
and car
?
((o car cdr cdr cdr cdr cdr) letters)
Creative.
What do you think of the following for rectangularize
?
(define rectangularize
(lambda (drawing)
(list 'drawing 'rectangle
(list-ref drawing 2)
(list-ref drawing 3)
(list-ref drawing 4)
(list-ref drawing 5)
(list-ref drawing 6)
(list-ref drawing 7))))
My, that's a lot of work.