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.
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
For Perl, you should investigate the effects of both static (lexical) and dynamic scoping, using
my keyword for lexical
local keyword for dynamic scope.
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
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.
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 < firstname.lastname@example.org >.
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.