Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Class 33: Exploring the Interpreter

Class 33: Exploring the Interpreter

cs1120: Introduction to Computing
Explorations in Language, Logic, and Machine
University of Virginia, Spring 2016

http://xplorecs.org/class33

Class 33:
Implementing Names
Python Dictionaries
globals()
Frames and Environments

David Evans

April 18, 2016
Tweet

More Decks by David Evans

Other Decks in Programming

Transcript

  1. Class 33: Exploring the Interpreter Introduction to Computing: Explorations in

    Language, Logic, and Machines cs1120 Spring 2016 David Evans University of Virginia
  2. Questions for Today • How did we get from =

    to primitiveEquals? • How do we make procedures in Charme? • How does the interpreter apply a constructed procedure? Names, Frames, and Enviroments
  3. Python Dictionary Dictionary abstraction provides a lookup table. Each entry

    in a dictionary is a <key, value> pair. The key must be an immutable object. The value can be anything. dictionary[key] evaluates to the value associated with key. Running time is approximately constant!
  4. >>> d = {} >>> d['UVa'] = 1818 >>> d['UVa']

    = 1819 >>> d['Cambridge'] = 1209 >>> d['UVa'] 1819 >>> d['Oxford'] Traceback (most recent call last): File "<pyshell#93>", line 1, in <module> d['Oxford'] KeyError: 'Oxford' Create a new, empty dictionary Add an entry: key ‘UVa’, value 1818 Update the value: key ‘UVa’, value 1819
  5. Charge • Make progress on Project 6: understand and experiment

    with the provided Charme interpreter, extended it for questions • Wednesday: how to apply a constructed procedure