Introduction to UNIX, Subversion, and DrRacket

The filesystem

Files and folders (directories) form a hierarchy, called the filesystem: directories can contain files and other directories.
The top directory is called /. Everything is inside this directory or its contents (macOS hides the root directory; press Apple+Shift+G in Finder and enter / to reach it in the graphical file manager).
Every directory contains two virtual directories called . (a single dot) and .. (two dots); these represent the directory itself and the directory that holds it, respectively.

Processes

The term process refers to a running instance of a program.
The kernel (the core of the operating system) tracks processes, schedules them, and services requests they make.
For us, the most important thing the kernel tracks about a process is the current working directory.
The current working directory is the directory the kernel starts at when finding files mentioned by a process.
For example, if a process has a working directory of /home/janedoe and references the file notes/cs151.tex, this relative path is joined by the kernel with the working directory to form the absolute path (one which starts at the root directory) /home/janedoe/notes/cs151.tex, which is the full path to the file that is accessed.

The shell

The most important unix program for this class is the shell, which reads and interprets typed commands to run other programs.
We'll be using a shell called Bash, which is one of the most common.
Each command interpreted by a shell starts with the name of either a program or a shell builtin (a directive handled by the shell), followed by some number of (space-separated) arguments. These are referred to as "argv" (the argument vector).
The shell builtin or program receives argv as an input and uses it to determine which particular function to perform.
A common convention among builtins and programs is to accept a number of options or flags, prefixed with hyphens,
which alter the behavior of the command, followed by a list of paths indicating which files or directories to operate on.
Flags are usually available in short or long form; the short form (such as -h to get a short help summary) uses one hyphen and a single letter, while the long form (such as --help) has two hyphens and multiple letters.
For convenience, short flags may usually be combined as well as passed separately, such as -tf instead of writing out -t -f.
Note, however, that these are just conventions and not all programs follow the same convention.

There are many programs installed and accessible via the shell, but some of the most useful for this class are as follows:

Interacting with the shell

Typing into the shell is not the exact same as typing into the text boxes you are used to.
Shells provide tools for more quickly entering commands than typing the entire line;
they also permit some interactions with programs that have not explicitly requested input.

When typing commands, pressing the Tab key at any time will attempt to automatically finish typing the current word.
If there are multiple valid words, the shell may display the possible options.
You can type additional letters to disambiguate, then hit Tab again to type the unambiguous completion.

Previous commands run in the shell can be scrolled through with Up/Down or by pressing Ctrl+R and typing to search.

Computers are time-saving devices (anything they can compute, you can compute), and these shortcuts will save you a lot of time in the shell.

Individual or multiple filenames can also be specified with a simple shorthand called globbing.
In globbing, a question mark (?) can stand in for a single letter, and a star (*) can stand in for any number of letters.
A word that uses globbing is replaced by all matching filenames before the command is run.

Shells also allow moving the cursor around with Home/End or Ctrl+A/Ctrl+E (for beginning and end of line),
Alt+Left/Alt+Right (to move by word),
Alt+Backspace (to delete an entire word), Ctrl+T (to transpose the two characters around the cursor), and a number of other shortcuts.

In addition, Ctrl+C and Ctrl+\ (with the latter being more forceful) may be used to terminate the running process.
Ctrl+D may be used to signal "end of input"; programs like shells will exit after their input ends.

Practice shell operations

Subversion (svn)

This class uses the Subversion version control system to manage programming assignments, including the distribution of sample code to students, the collection of assignments, and the returning of graded work.
Version control systems are a class of powerful tool that are used to track different revisions of files, allowing one to consult old revisions, undo mistakes, and make changes to a multi-person project without accidental overwriting of others' work.
Our use of subversion will be much more limited.

Subversion is a distributed system. There is a server machine, called phoenixforge that holds the master copy of your work. To complete an assignment, you will need to checkout a local copy of your work, add and edit files in this local copy, and then commit your changes back to the server.
The local svn program is used to interact with the server.

The svn program has many subcommands, but the most important ones are these:

A project tracked with version control is called a repository, and may consist of many files and folders.
Each revision can include changes to multiple files.

Each registered student has a repository on the UChicago PhoenixForge SVN server already. You'll check out your repository and commit a file for Lab 1.
Unlike later labs, this work will not be graded and is just an exercise to become familiar with the process.

Getting started with DrRacket

The programming language for this course is Typed Racket, a functional programming language that uses surrounding parentheses to denote the application of functions to arguments.
Dr. Racket is an integrated editor for Typed Racket and related languages; we'll use Dr. Racket to write, run, and debug programs.
Open your lab1.rkt file in Dr. Racket (by finding it in your SVN checkout on your desktop).
When you finish working today, after saving lab1.rkt, be sure to run svn commit lab1.rkt again and verify its success (you should see the letter A at the left of SVN's output).
This is how you save your work for access on other machines and how you ensure your work is available to the graders.

DrRacket may at some point ask you to choose a "language level." For this exercise, select the "Beginning Student" level. When we start using Typed Racket you will select the "Determine language from source" option.

Type the following code into DrRacket's definitions pane:

9

(+ 9 1)

(+ 1 9)

(- 9 1)

(- 1 9)
Click the "Run" button at the top of the DrRacket window.
For each line entered above, consider how the printed result relates to the expression.

Type the following code into DrRacket's definitions pane beneath your previous input, and click "Run" again.

(* 9 1)

(* 1 9)

(/ 9 1)

(/ 1 9)

Try these more complex expressions:

(+ (* 9 9) 2)

(- (* 9 9) (* 9 9 9))

Next, test some of Typed Racket's relational operators:

(= (expt 9 1) (expt 9 2))

(< (expt 9 1) (expt 9 2))

(> (expt 9 1) (expt 9 2))

Finally, add these:

;; a : Integer
(define a 7)

;; b : Integer
(define b 8)

(* a b)

(- (* b b) (* a a))

At this point, you should feel free to add, remove or modify any of the expressions of definitions in the definitions pane.

Save your lab1.rkt file in whatever state it's in. You need to use svn commit again on it to push the local copy to the SVN server.

If you've closed your terminal or want to double-check that you've committed the file, first open a terminal, then change working directory to your checkout of your repository, the CNET-cs151-win-18 directory.
Then run:
  svn commit lab1 -m "committing lab1"
  
to commit the directory and its contents (the lab1.rkt file).

You will now use Racket to render a crude illustration of a local landmark, the Sears Tower (which I refuse to call by its other name).

At the top of your lab1.rkt file, type:

(require 2htdp/image)
Anywhere below, type:
(define sears-tower
  (above (beside (rectangle 2 11 "solid" "black")
                 (rectangle 3 1 "solid" "white")
                 (rectangle 2 11 "solid" "black"))
         (rectangle 10 30 "solid" "black")
         (rectangle 20 100 "solid" "black")))
After running, and hence registering this definition, you can view the illustration by typing sears-tower in the interactions pane.

Save the file. You don't need to add lab1.rkt to the repository again, because you've already done so. You do need to commit it again, though, and do not neglect the message (with the -m flag and quotes) in your commit command.