Getting started
This will likely be the last day that I write the getting started instructions. You should know them by now.
Approximate overview
Notes from the surveys
above, circle, *)When tracing, show the current state of the expression at every step. E.g.,
(+ 3 (* 5 (/ 2 (- 10 5))))
--> (+ 3 (* 5 (/ 2 5)))
--> (+ 3 (* 5 2/5))
--> (+ 3 2)
--> 5
or
(define add3 (lambda (x y z) (+ (+ x y) z)))
(add-3 (+ 1 2) 4 5)
--> (add-3 3 4 5)
--> (+ (+ 3 4) 5)
--> (+ 7 5)
--> 12
Note: We evaluate the parameters to procedures before we apply the procedure. And that’s for both built-in procedures and user-defined procedures.
(define name Sam)(define name ("Sam"))(define sam "Sam")(define (name "Sam"))#lang racket and the (require ...).#lang racket and the (require ...)
in quizzes.I’ve started putting answers to the reading questions in the readings. These are ones that didn’t naturally fit in a reading
What should I do when I come across an error in DrRacket that says something like “expects 4 arguments, only 3 provided”?
If DrRacket says “expects 4 arguments, only 3 provided”, it means that you’re calling a procedure that expects four arguments (e.g.,
rectangle, which expects width, height, opacity, and color) and only giving it three (e.g., you’ve forgotten the opacity and typed(rectangle 10 5 "blue")).
When using overlay/align how do I know what order I should put the commands like “center” then “bottom” or “left” then “center”. The different places of “center” confuse me as it works sometimes as the first one in the string and other times it doesn’t work.
The first parameter is the x (horizontal) alignment, the second the y (vertical). Since can be aligned horizontally or vertically at the center,
"center"is available for each.
More generally, you can experiment or read the documentation
I don’t understand the difference between function, procedure, and expression.
functions and procedures are basically algorithms (a set of instructions, with a name).
An expression is an instruction to compute a value, often using a function.
Could you explain how to define add-3 a little more?
Sure.
add3is a procedure that takes one input, which we’ll callx, and adds 3 tox.
To say “a procedure with one input, which we’ll call
x”, we write(lambda (x) …).
To say “add three to
x”, we write(+ 3 x).
And we use
defineas we’ve used it in the past.
Putting everything together, we get
(define add-3
(lambda (x)
(+ 3 x)))
Whoops, that’s the wrong
add-3.
Let’s try again.
add3is a procedure that takes three inputs, which we’ll callx,y, andz. If we pretend that addition only takes two parameters, we’ll addxandy, and then add that result andz.
We say that it’s a procedure with
(lambda (x y z) …).
We say “add
xandy, and then add that result andz” with(+ (+ x y) z).
Putting it all together, we get
(define add-3
(lambda (x y z)
(+ (+ x y) z)))
If we evaluate/trace, say
(add-3 2 3 4), we substitute2forx,3fory, and4forzin the body. We then evaluate with the normal strategy.
(add-3 2 3 4)
--> (+ (+ 2 3) 4)
--> (+ 5 4)
--> 9
Where do I find the evening tutors?
They should be in 3813 or 3815, with a flag by them to identify themselves.
Problems are labeled A and B.
The partner closer to the front of the room is Partner A. The partner further from the front of the room is Partner B. Partner A should be at the keyboard for A problems. Partner B should be at the keyboard for B problems.
Make sure to introduce yourself to your partner.
Make sure to update the csc151 library. (It’s always good to check.)
Make sure to grab the types.rkt file and put it into DrRacket.
All the instructions are in the file.