12/7/21, 6:07 PM
Discussion 2 | CS 61A Fall 2021
https://cs61a.org/disc/sol-disc02/
1/31
Discussion 2: Higher-Order Functions, Self
Reference disc02.pdf (disc02.pdf)
This
is
an
online
worksheet
that
you
can
work
on
during
discussions.
Your
work
is
not
graded
and
you
do
not
need
to
submit
anything.
Walkthrough Videos
Feel
free
to
try
these
problems
on
the
worksheet
in
discussion
or
on
your
own,
and
then
come
back
to
reference
these
walkthrough
videos
as
you
study.
To
see
these
videos,
you
should
be
logged
into
your
berkeley.edu
email.
YouTube
link
(https://youtu.be/playlist?list
=
PLx38hZJ5RLZd4XFnzPaIr2LhnWKsUhc4g)
Lambda Expressions
A
lambda
expression
evaluates
to
a
function,
called
a
lambda
function.
For
example,
lambda y: x + y
is
a
lambda
expression,
and
can
be
read
as
"
a
function
that
takes
in
one
parameter
y
and
returns
x + y
.
"
A
lambda
expression
by
itself
evaluates
to
a
function
but
does
not
bind
it
to
a
name.
Also
note
that
the
return
expression
of
this
function
is
not
evaluated
until
the
lambda
is
called.
This
is
similar
to
how
dening
a
new
function
using
a
def
statement
does
not
execute
the
function
’
s
body
until
it
is
later
called.