Return to Video

06-30 Anonymous Functions Solution

  • 0:00 - 0:03
    The first part of our return value is just the word function.
  • 0:03 - 0:07
    This is to separate it from a number like 3 or 4
  • 0:07 - 0:09
    and to allow us to tell if the user mistakenly tries to call something
  • 0:09 - 0:11
    that's not a function later.
  • 0:11 - 0:15
    We then list the parameters which we got right from the abstract syntax tree,
  • 0:15 - 0:18
    the body of the function, which we also got right from the abstract syntax tree,
  • 0:18 - 0:23
    and the environment in which it was defined--this one, env.
  • 0:23 - 0:27
    And we're passing in env here instead of some global environment or whatnot
  • 0:27 - 0:33
    and this is what's going to allow local functions to see local variables.
  • 0:33 - 0:36
    This is why things like makegreeter work.
  • 0:36 - 0:39
    They can refer back to variables that were currently in scope
  • 0:39 - 0:42
    when they were defined.
  • 0:42 - 0:46
    Many of you may notice a striking similarity between this and our previous code
  • 0:46 - 0:48
    for handling function declarations.
  • 0:48 - 0:50
    In fact, our previous code just had 1 more step
  • 0:50 - 0:54
    where we added this value to the environment.
  • 0:54 - 0:57
    For an anonymous function, we don't add it to the environment
  • 0:57 - 0:59
    unless the user assigns it.
  • 0:59 - 1:01
    But this code should look really, really familiar.
  • 1:01 - 1:05
    We have something almost exactly like it for handling functions at the top level
  • 1:05 -
    as JavaScript elements.
Title:
06-30 Anonymous Functions Solution
Description:

Other units in this course below:
Unit 1:http://www.youtube.com/playlist?list=PL3FEF9299137945CC
Unit 2:http://www.youtube.com/playlist?list=PLBF6FC32358457242
Unit 3:http://www.youtube.com/playlist?list=PL30EF9EB86B4D2E54
Unit 4:http://www.youtube.com/playlist?list=PL6881C8D2E9D63242
Unit 5:http://www.youtube.com/playlist?list=PL62AF1F6D3B654E14
Unit 6:http://www.youtube.com/playlist?list=PL8FCC9D9C45A6640E
Unit 7:http://www.youtube.com/playlist?list=PL9533BCB71FD88E38

Q&A: http://www.youtube.com/playlist?list=PLE0EB375FA373A866

To gain access to interactive quizzes, homework, programming assignments and a helpful community, join the class at http://www.udacity.com

more » « less
Video Language:
English
Team:
Udacity
Project:
CS262 - Programming Languages
Duration:
01:08
Amara Bot added a translation

English subtitles

Revisions