Meeting 02 - Expressions

Bor-Yuh Evan Chang
\(\newcommand{\TirName}[1]{\text{#1}} \newcommand{\inferrule}[3][]{ \let\and\qquad \begin{array}{@{}l@{}} \TirName{#1} \\ \displaystyle \frac{#2}{#3} \end{array} } \newcommand{\infer}[3][]{\inferrule[#1]{#2}{#3}} \)

In-Class Slides
Book Chapter

Announcements

  • Syllabus Quiz due tomorrow (Friday) 6pm (with the 24-hour grace period for when “stuff happens”)
  • Recitation sections are lab sections — bring your laptop!
    • This Week: Getting your development environment set up!
    • Future Weeks (in general): Getting hands-on help to finish assignments for the 6pm deadline — in addition to office hours during the week

Announcements

  • Use Piazza for all course communication.
    • Energetically engage in discussions with your classmates to help each other on the learning activities — for your Class Participation score.
    • For course administrative things (e.g., grade issues, GitHub access issues), use private messages on Piazza to “Instructors” instead of email.
  • Added notebook links to PPPL Notes.

Today

Your Questions So Far?

Your Questions So Far?

Syllabus Policies

Requirements

Distinguishes between learning activities:

  • Reading
  • Quizzes and Exercises (25%)
  • Lab Assignments (30%)
  • Participation (5%)

And summative assessments:

  • In-Class Exams (20%)
  • Final Exam (20%)

Highlights

Is a Program Executed or Evaluated?

The imperative versus functional schism?

Imperative

Functional

Expression Rewriting

Pure Expressions and Order of Evaluation

Being effect-free or pure has advantages by being independent of how a machine evaluates expressions (i.e., called referential transparency).

\[ \begin{array}{rcl} (1 + 1) + (1 + 1) & \longrightarrow& 2 + (1 + 1) \\ & \longrightarrow& 2 + 2 \\ & \longrightarrow& 4 \end{array} \]

Basic Values, Types, and Expressions

Values and Types

Examples?

Expressions

An expression can be a literal or consist of operations that await to be evaluated. For example, here are some expected expressions:

Static Type Checking

We can check that an expression has the expected type as follows:

Static Type Checking

Static Type Checking

Type checking works by making sure all operations in all sub-expressions have the “expected type”.

Static Type Checking

Run-Time Errors

Assertions

Assertions

Unit

Since the unit value () itself is uninteresting and usually associated with side-effecting expression, the printer in the above simply chooses to not print unit values.

Operators and Methods

Evaluation Step

0-or-More Steps

Evaluation