COMP 511 Written Assignments

Over the course of the semester, COMP 511 students are required to write three brief reports. Unlike the programming projects, these written reports are individual assignments. The goal of the reports is to help you relate the programming language concepts studied in this course with features and idioms in the programming languages that you are already familiar with.

Written assignment description

A programming language feature is a construct that is built into the language. An idiom is a common code recipe used to imitate the behavior of a feature that is not a first-class construct of the language. For each assignment, you will pick one topic from a pool of approved topics that have been covered in class. Your task is to describe how a feature or idiom in a programming language of your choice exemplifies your chosen topic. You should also highlight any differences or limitations that might exist compared to the features as discussed in the lectures.

At the bottom of this page we have provided an example write-up on the topic of lexical scope. Please use this example as a guide for your own write-ups, and follow the format illustrated in the template below. Your grade will be based both on your correct usage of the template (make sure to include all the same headers as in the template), and on the quality of your discussion about your chosen topic. The descriptions should be brief. Please try to limit the descriptions to no more than two paragraphs. (Note that lexical scope—the topic used in the example—is not in the topics pool for any of the three written assignments.)

Written assignments are to be submitted on OwlSpace. Please compose your write-up in the editor of your choice, and paste the submission directly into the text area on the corresponding assignment page for submission.

Topics for written assignment 1

Topics for written assignment 2

Note that topics starting with "implementing" require you to discuss how the feature / idiom is implemented. Simply stating that the feature is supported is insufficient.

Topics for written assignment 3

Note that topics starting with "implementing" require you to discuss how the feature / idiom is implemented. Simply stating that the feature is supported is insufficient.


Write-up format template

Topic

State the topic that you selected. It should be selected from the topic list for the current assignment.

Exemplifying PL feature or idiom

State the programming language you have chosen, as well as the feature/idiom in that language matching your selected topic.

Description of features and limitations

Describe how your chosen PL feature/idiom relates to your selected topic. The feature/idiom may relate to the topic because the topic concept is used in the implementation of the feature/idiom, or the feature/idiom may be used to implement the topic concept manually by users of the programming language. Also describe how your selected feature/idiom might differ from the topic concept as discussed in the course material.

This should be a short and succinct description. You do not need to describe the topic concept since the discussion of your chosen PL feature/idiom (and how it relates to your selected topic) should reflect your understanding of the whole topic.


Sample write-up

Topic

Nested lexical scopes

Exemplifying PL feature or idiom

Java’s anonymous inner classes

Description of features and limitations

Since version 1.1, Java has supported closures that capture variables across multiple lexical scopes in the form of inner classes which may be anonymous (unnamed) mimicking lambda-expression notation for functions (map in Jam). Inner classes may be embedded inside methods. Since inner classes contain methods, this nesting hierarchy can be arbitrarily deep. An inner class’s definition can reference variables in the lexical scopes of the enclosing methods and classes, some of which may also be inner classes. Java imposes a major restriction on the method variables that can be accessed in inner classes: they must be final so that there values can be copied into hidden fields on inner class instances. Of course the final values may be objects with mutable fields, so the restriction is not very significant in practice.

Like the Jam map construct, Java’s anonymous inner classes create a lexical closure to capture the values of all referenced final variables; the lexical closure consists of hidden final fields in the instance itself that are the values of the referenced variables. Hence, the referenced values are available in the method code of an inner class instance as long as the instance exists. Unlike Jam, Java’s closures only capture the referenced variables, whereas Jam’s closures capture a reference to the entire environment corresponding to the current lexical scope. The Jam approach is simple, but wastes memory because it retains entire environments as reachable data when only the referenced variables are required.