Functional Problem Solving (CSC 151 2014F) : Outlines
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)]
Held: Monday, 8 September 2014
Back to Outline 05 - Drawings as Values. On to Outline 07 - Writing Your Own Procedures, Continued.
Summary
We begin to consider how you can write your own procedures and why you might do so.
Related Pages
Overview
Administrivia
(ceiling -9.3)
-> -9.0
.In Scheme, we often write compound expressions, with subexpressions.
(sqrt (+ (square x) (square y)))
Which is done first, square
, +
, or sqrt
?
square
operations first, then the addition, then the sqrt
.square
operations is done first?
Compare these two pairs of operations
(define val 3)
(sqrt val)
(define d drawing-unit-circle)
(scale-drawing 5 d)
Because of this model, we often describe drawings with a series of nested operations (innermost first).
drawing->image
to convert the drawing to
an image.image-show
to display the image.square
and +
, or the DrFu procedures, such as
hshift-drawing
.sqrt
How do you define your own procedures? Using the following template:
(define your-procedure (lambda (param1 ... paramn) expression1 ... expressionm))
For example,
(define square (lambda (val) (* val val)))
You can (and should) document your procedures so that others can understand what they are supposed to do. We'll come back to this issue soon.
define
for each
parameter as the corresponding sent value.So (square 5)
is a lot like
(define val 5) (* 5 5)