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)]
Continue partners.
Overview
Key points of the reading?
What was confusing?
Using counters makes sense, but I don't get how they work
We set up one counter per procedure.
That means we need things that change.
Vectors allow us to change. Each counter is a one element vector where the element is the count (of calls to the corresponding procedure).
(vector-set! vec 0 (+ 1 (vector-get! vec 0)))
Once you know how to do something, you don't rewrite the complex code, you name it as a procedure.
counter-increment!
I don't get the difference between linear time and constant time
Terms for efficiency.
Linear time: You do a number of calls approximately proportional to the size of input elements (e.g., the number of elements in a list).
Constant time: Independent on the size of the input. car takes only one step, whether it's 100 elements or 1000 elements or 10000000 elements.
Explain all of the counter-x
procedures. How do we integrate them
Setup: Outside the procedure
(define PROC-counter (counter-new "procedure"))
(define member?-counter (counter-new "member?"))
Setup: Inside the definition of the procedure
(counter-increment! PROC-counter)
(define member?$
(lambda (val lst)
(counter-increment! member?-counter)
(and (not (null? lst))
(or (equal? (val (car lst)))
(member?$ val (cdr lst))))))
Analysis
(counter-reset! member?-counter)
(member?$ 1000 (iota 1000))
(counter-print! member?-counter)
(counter-reset! member?-counter)
(member?$ -1 (iota 1000))
(counter-print! member?-counter)