Functional Problem Solving (CSC 151 2015S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] - [Calendar]
Current: [Assignment] [EBoard am] [EBoard pm] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards am] [EBoards pm] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014F)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Book Office Hours] - [Issue Tracker (Course)]
Overview
listp? predicate.Nothing at present
What should we take from yesterday's lab?
Why are we studying this?
We see our first pair Print a single quotation mark and an open paren Print the car Look at the remaining pairs Print a space Print the car When you hit null, print a close paren When you hit something other than null, print the profanity symbol (.) and the cdr
(define print-something (lambda (thing) (cond [(pair? thing) (display "'(") (print-something (car thing)) (let kernel ([remaining (cdr thing)]) (cond [(null? remaining) (display ")")] [(pair? remaining) (display " ") (print-something (car remaining)) (kernel (cdr remaining)]
listp?A list is a collection of values.
In Scheme, we can build lists with pair structures.
"A list is either null or (cons VALUE LIST)".
(define listp?
(lambda (val)
(or ; is it null?
(null? val)
; is it a pair whose cdr is a list
(and (pair? val)
(listp? (cdr val))))))
"Structural recursion" -> Recurse over the parts of a structure (e.g., built with pairs)
Writeup is cancelled.