CS 315
Homework Assignment 1


Assigned:  March 26, 2018
Due:  April 2, 2018, 23:59

Scoping in C, Javascript, Python, Perl and PHP

Scoping rules determine how a particular occurrence of a variable matches to the appropriate binding. There are two types of scoping rules: static scoping and dynamic scoping. In static scoping, a variable always refers to its nearest enclosing binding.  On the other hand, dynamic scoping is based on the calling sequence but not on the spatial relationships.

In this homework, you will compare the scoping rules in five different programming languages: C, Javascript, Python, Perl and PHP.

Write programs for the same test example in those five different languages to clearly illustrate the different scoping rules used by these languages. You are encouraged to come up with an example that emphasizes the advantages and limitations of both scoping rules.

For the C language, you can define nested blocks to model nested scopes.

For Python, you should use Python 3. On the dijkstra terminal, Python 3 is available by typing python3.

For Perl, you should investigate the effects of both static (lexical) and dynamic scoping, using my keyword for lexical scope and local keyword for dynamic scope.

You should prepare HTML files for Javascript and PHP programs.

To help the TA give you good grades, appropriately comment your source to explain your example and why your example is an appropriate one for this homework.

Make sure your programs execute in the dijkstra.cs.bilkent.edu.tr machine, since the TA will test your programs on this machine.

Put your example programs in different files, each having your last name and name, and a description for the language  and scoping used. For example, lastname_name_javascript.html, lastname_name_C.c, lastname_name_python.py, lastname_name_perl_static.pl, lastname_name_perl_dynamic.pl and lastname_name_php.php (or lastname_name_php.html). Also, write a report to compare all the programs that you have written. Copy the programs into the report (with the comments when necessary), explain what scoping rule is used in that example, if possible write the output or explain the program execution.

You may use the tutorials available in the Internet as a reference, but do not derive your example from the contents of the tutorials. If you do so, your programs may be similar to others in the class, that causes a disciplinary investigation.

Put your report and example files in a folder named lastname_name and make a zip or rar of the folder. Then e-mail this file to the TA, Gizem Çaylak < gizem.caylak@bilkent.edu.tr >.

Collaboration on the homework is not allowed.

Suggestion: Do not postpone the execution of your programs to the last minute! The dijkstra machine might be overloaded, then.