When making a private Ed question, make sure to select question rather than post
We will greatly appreciate it
HW 8 Released today
As for midterm → final tips, I think something that might be super important to practice is recursion (the rest of the course pretty much deals with recursion, so getting comfortable with recursion sooner rather than later will greatly help)
Results from last section
Notes from last section
Which is better to study if you had to choose: csm worksheets and discussion worksheets or practice midterm questions?
Ideally both, but if you were only able to choose one, then I'd say do practice midterm questions more so than CSM/discussion worksheets (however, I do think that doing discussion worksheets will help give you the foundation to do exam problems, so don't skip on those)
More tree recursion please
This is going to happen with Scheme naturally because it's a language where you can't do any iteration
Temperature Check
Linked Lists
Scheme
Scheme Lists
Would like to mention that I will be talking a lot this discussion at the start cause a lot of this is syntax
What is Scheme
Scheme is another language that you need to learn
It's a dialect of Lisp (List Processor)
Everything is done with recursion
No while/for loops
Good thing about this is that you get a lot of recursion/tree recursion practice with scheme
No mutation in scheme
IMO Scheme is a very good way to demonstrate that once you learn the logic for one programming language, learning a second one is way easier!
There are a lot of parentheses
Primitives
Scheme has a set of atomic primitive expressions.
Similar to the primitives in Python
These expressions cannot be divided up further
scm> 11
scm> 22
scm> #t
True
scm> #f
False
Booleans (Python)
Remember this table?
Falsey
Truthy
False
True
None
Everything else
0
[], "", (), {}
Booleans (Scheme)
Falsey
Truthy
#f
Everything else
This is something you need to remember
define
In scheme, everything that isn't a primitive is done with prefix notation
(<keyword> [<arguments> ...])
In scheme, we use the define keyword in order to bind values to symbols, which work the same way as variables.
This is also used to define functions - more on this later
This keyword returns the symbol:
In scheme, everything that isn't a primitive is done with prefix notation
(<keyword> [<arguments> ...])
In scheme, we use the define keyword in order to bind values to symbols, which work the same way as variables.
This is also used to define functions - more on this later
This keyword returns the symbol:
>>> x = 3
scm> (define x 3)
x
Intro WWSD (Maybe)
Call Expressions
Call expressions apply a procedure to some arguments
(<operator> [<operands> ...])
Exactly the same process as Python
Evaluate the operator (make sure it's a procedure/function)
Evaluate each of the operands (from left to right)
Apply the operands to the operator
Call Expression WWSD (Maybe)
Call Expressions
>>> add(1, 2)
3
scm> (+12)
3
Important to note that all the operands are evaluated!
Special Forms
They still look like call expressions (syntax-wise), but instead of evaluating all the operators, there are certain rules for evaluation.
Special Forms (if)
(if <predicate> <if-true> [<if-false>])
<predicate> and <if-true> are required, <if-false> is optional
Rule for evaluation:
Evaluate <predicate>
If <predicate> is truthy (don't forget what Scheme does!), evaluate <if-true>
Else evaluate <if-false> (if it exists)
This means that not all of its operands will be evaluated!