CS151 Labs

Lab 1 will be collected from your subversion repository (see below) on Monday, October 3, at 5pm. Before then, you will need to commit work at the end of your lab session as well (Part 1, below).


Corrections

Goals

The purpose of this lab is to give you the opportunity to solve some programming problems in the Racket programming language, and to become familiar with the CS151 tool chain, which includes working at the command line and using DrRacket and subversion.

Command-Line Computing

The command line or terminal is an essential tool for this course. You will manipulate directories and files, receive and submit assignments, and do many other tasks through it. On a Mac, you can start the terminal by either clicking on the corresponding icon on the launch bar, or opening it in Finder under Applications/Utilities. On Linux, you can usually find it under Applications/Accessories.


The Terminal icon in Mac OSX.

Start the Terminal program and type the command ls; commands to be issued in the terminal are usually written like this:

$ ls
(Note that you do not need to type the $ symbol; it just denotes the beginning of a line in the Terminal).

The ls command you just issued lists the contents of the current directory of the Terminal (Note: this is NOT your desktop by default when you open a new Terminal, unless you configure your machine otherwise). Try issuing these simple commands:

$ mkdir mydirectory
creates a new directory called mydirectory (verify with ls that it was created).
$ cd mydirectory
changes the current directory to mydirectory (verify with ls that you are now in your new, empty directory).
$ cd ..
changes the current directory to the parent of your current directory.
$ rmdir mydirectory
deletes an empty directory.

You can now close the Terminal window (or you can use the command exit).

Subversion

Subversion is a version control system. Subversion, and version control systems generally, exist to manage collaborations between software developers working on the same project on different machines more or less at the same time. The main task of a version control system is to maintain a central repository of code (any files, actually) to which all collaborators share access. Furthermore, every time a file is committed to the repository, its current version is permanently saved in a central spot, so one can always go back to it if subsequent changes need to be undone. (Comprehensive documentation for subversion is available in their free online book.)

Version control systems adapt well to computer science coursework, although that may not be their primary intention. In the context of a course, the "collaboration" is between the student and his or her instructors, who share access to the coursework files; students produce the work, and graders grade it, all in the shared repository.

It is crucial to understand the following point. Synchronization between your local files and those in the central repository is not automatic. You must take action to commit your work to the central repository so that others (and you, working on a different machine) can get to it later. This is done through a commit command, instructions for which appear below.

In this course, you will be using the subversion client svn. We will create a subversion repository for every student. Each repository will be shared between you and the CS151 staff. You will store your homework and lab exercises in your repository as you work on them, and the staff will collect your submissions from the repository.

The subversion client, svn, will access the repository through the URL https://phoenixforge.cs.uchicago.edu. Your personal repository is https://phoenixforge.cs.uchicago.edu/svn/CNetID-cs151, with your own CNetID in place of CNetID.

Getting Started

You will work at the command line with the Terminal application. (These instructions assume you are working on a Mac in the MacLab.) Start Terminal.

Next, check out your repository, as follows. (You will need to repeat this process any time you work on a new machine, such as your own laptop, for example.) Replace CNetID with your own CNetID in the following:

$ cd ~
$ svn checkout https://phoenixforge.cs.uchicago.edu/svn/CNetID-cs151 cs151

You will be prompted to accept the SSL certificate for the phoenixforge server. Type 'p' to permanently accept it. Then, you will be prompted for your CNet password.

If you get a 403 error from svn, check to make sure that the path and username are typed correctly. If you run into any other errors, please flag down the TA immediately for assistance!

This command will create a directory named cs151 and will populate it with all of the files for the lab. Caution: this directory will be world-readable by default, making it possible for others to see your work. Use the following command to restrict access to only your account:

$ chmod 700 cs151

Now create a lab1 directory in cs151:

$ cd cs151
$ svn mkdir lab1

Open DrRacket by clicking on the blue/red lambda icon in the dock. Under Language > Choose Language... > Teaching Languages > How to Design Programs, set the language level to Beginning Student. Type your name and CNetID in the Definitions window as follows:

;; My Name
;; CNetID
Use the Save Definitions As... command in the File menu to save your file as lab1-CNetID.rkt in the lab1 folder you just created.

You can use the 2htdp/image package in your work by using the command below to import it:

(require 2htdp/image)
Search DrRacket's help system for "2htdp/image" (under Help). Keep the documentation close at hand through this exercise.

The 2htdp/image package provides functions such as rectangle, circle, ellipse, etc. You build images out of these elemental parts and sticking them together, stacking them up, and stretching and squeezing them in various ways. For example, images can put together vertically and horizontally using the image operators above and beside, respectively. The use of common image operators like above and beside will be discussed briefly at the beginning of the lab session.

Part 1

Your first task is to write a program to draw diamonds, as in the suit symbol (along with clubs, spades and hearts) on playing cards.

diamond from cards

Write a function diamond consumes one input: a number indication the side length of the square bounding the whole symbol. So, for instance, a call to the function would be:

(diamond 50)
This draws a diamond that fits in a 50x50 pixel square. A possible image you could generate is below. Note your diamond need not be "perfect" in the sense of having slightly curved sides; having said that, feel free to be creative with the details of the shapes you generate.

diamond from cardsdiamond from cardsdiamond from cards
Various diamonds created in DrRacket.

You can create your diamond with any combination of basic shapes such as rectangles. triangles, circles, etc. Be sure to use some of the rotate, flip, crop, beside, overlay, above, and other such functions in the image packages mentioned above. Also, make sure you place the diamond in a box that fits the diamond as shown above.

As for testing your code, the conventional tesing tools (such as check-expect) aren't as useful for images. In this case, it is best to just observe instances of images such as (diamond 50) or (diamond 100) by adding them to the definitions window.

Now switch back to the command line. Check the state of your repository by running the command below:

$ svn status

The status command will show you all a list files that have been modified, added, deleted, or have magically appeared. The file lab1-CNetID.rkt will have a ? next to it. This indicates that it is a new file on disk that has not yet been added to the repository. Type these:

$ svn add lab1/lab1-CNetID.rkt
$ svn status

Now, lab1-CNetID.rkt should have an A before it, meaning that it has been added (but not yet committed) to the repository.

$ svn update

Subversion should tell you what version of the files you currently have, but not make any local changes as you are already up to date. This command will check all of the files in and below the current directory to see if they need to be updated with new status from the repository.

Now commit your files to the repository. Commit (and several other subversion commands) require a log message to associate with your change. You can provide it in two ways, one way is to provide this at the command-line by using a special argument of the form:

$ svn commit -m "log message"

Write log messages that concisely describe the reasons and goals for the changes that were made. Do not include your name or the date, as the repository already has that information.

Note: If you don't provide this message, a default editor opens up that lets you add your log message. For example, if you set the EDITOR environment variable and run the command, emacs will be launched whenever the svn client needs you to edit text. You can then edit the file to contain a comment about the commit, save, and exit.

$ export EDITOR=emacs
$ svn commit

If svn cannot launch your editor and is not able to get a log message, you will get an error message stating that the commit failed, with a possibly confusing error message involving the file svn-commit.tmp. Just set your EDITOR environment variable or provide the -m "log message" argument on the command-line and try again.

Commit the source file containing your diamond function by the end of your lab session. We will not assign you Part 2 of the lab without your having committed your work to your repository.

Part 2

Some time Thursday night (9/29), we will add an additional exercise to your repository. (We will make an announcement when we have done so.) You will retrieve the additional exercise by checking out a local copy of your repository, or updating the one you already have, after that time. Perform an update

$ svn update
and see what happens. Not everyone will receive the same extra exercise, so you must check out your own repository to get your own individual assignment.

The completed lab exercise is due 5pm on Monday 10/3. Remember to commit your finished work before it is due! We will collect your work by checking out our own copies of your subversion repository Monday at 5.