Difference between revisions of "W1201 Scope"
Line 30: | Line 30: | ||
'''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. | '''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. | ||
{{ | {{Hint|The '''async-shell-command''' can be executed with {{VerySpecialKey|ALT|SHIFT|7}}. The command to execute each time is: ''swift main.swift''}} | ||
Revision as of 20:24, 2 December 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.