Difference between revisions of "W1201 Scope"
Line 5: | Line 5: | ||
* Read [https://en.wikipedia.org/wiki/Scope_(computer_science) Scope (Wikipedia)] | * Read [https://en.wikipedia.org/wiki/Scope_(computer_science) Scope (Wikipedia)] | ||
* Read [[Media:ComputerScienceOne.pdf|Computer Science I Textbook (by Bourke)]] Chapter 2.2.4. Scoping | * Read [[Media:ComputerScienceOne.pdf|Computer Science I Textbook (by Bourke)]] Chapter 2.2.4. Scoping | ||
== Introduction == | |||
The '''lifetime''' of a variable is the time period in which the variable has memory allocated to it and may legitimately be referenced. | |||
The '''scope''' of a declaration is that part of the code in which the declaration is in effect. | |||
The '''visibility''' of a declaration refers to that part of the code in which the declaration is accessible (not hidden) by an identical declaration in another scope. | |||
== Experiment == | == Experiment == |
Revision as of 08:14, 22 November 2019
Prerequisites[edit]
Research[edit]
- Read Scope (Wikipedia)
- Read Computer Science I Textbook (by Bourke) Chapter 2.2.4. Scoping
Introduction[edit]
The lifetime of a variable is the time period in which the variable has memory allocated to it and may legitimately be referenced.
The scope of a declaration is that part of the code in which the declaration is in effect.
The visibility of a declaration refers to that part of the code in which the declaration is accessible (not hidden) by an identical declaration in another scope.
Experiment[edit]
Create a directory within your "project" directory.
cd ~/projects
mkdir project-1201
cd project-1201
Edit a new file named "main.swift"
emacs main.swift
For this project you'll repeatedly edit the same file. It's probably easiest to test this file within emacs by typing: M-& (async-shell-command) and observing the results. For each question, be sure to understand the behavior before proceeding to the next question. It will be helpful to record your answers and reasoning for later review.
Helpful hint: The async-shell-command can be executed with Alt-Shift-7. The command to execute each time is: swift main.swift