CS 315
Homework Assignment 1

Assigned:  November 21, 2017
Due:  November 27, 2017, 23:59

Scoping in 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 four different programming languages: Javascript, Python, Perl and PHP.

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

You should prepare html file for Javascript and PHP programs.

Write programs for the same test example in four 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.

To help the TAs 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.

Place your example programs under 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_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 under a folder named lastname_name and make a zip or rar of the folder. Then e-mail this file to the TA, Alper Erošlu < alper.eroglu@bilkent.edu.tr >.

Collaboration on the homework is not allowed.

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