You'll need a CS account - if you're in CS 60, you should have one. This is different from your CIS accounts It's likely the same login name (though there are a few exceptions) and also likely that your password is different from your other accounts - unless you made it the same in the past.
Forgotten password or login name? If so, simply stop by Beckman B101 and see Tim Buchheim, our system administrator. It will take only a second for you to reset your password to something else.
The CS department has about 50 Macs in Beckman B102 and B105. Using those is an easy way to access your CS account and files and, in particular, Rex! If you login to one of the lab Macs, you will be able to navigate to your files using the familiar window-based interface of folders and files.
In order to get to the command-line and continue on with the assignment, continue with the From a Mac instructions below.
You can also access your CS account from your own machine (as long as you're connected to the internet, that is). The program from which you log in is different, depending on whether your machine is a Mac or a PC. We'll look at each one in turn.
From a Mac Macs come with a command-line interface program called Terminal. If you type "Terminal" in the spotlight search box available from the upper right corner, the terminal program will be the "top hit" it finds. It's also available via Go - Applications - Utilities - Terminal.
Within Terminal, you will be at a command prompt. You can navigate around your local machine using pwd, cd, and the other commands described below. At least try typing hostname at the prompt: it should tell you the name of your local machine.
Next, to log in remotely to the main CS server, named knuth.cs.hmc.edu, type
but replace hadas with your own login id. The ssh program is a "secure
shell," that is, a safely encrypted connection that will pass what you type locally
to the CS server knuth. The -Y is a flag that's helpful for opening
windows -- this is described in detail at the bottom of this page.
ssh -Y hadas@knuth.cs.hmc.edu
Note: as you type your password, no text will appear (not even the dots that op up on some web forms). If you make a mistake in typing your password, it will simply give you the password prompt again. Once you successfully enter your password, you will now see a "welcome" message and then yet another command prompt. Try typing hostname again -- this time, it should reply knuth, indicating that you're now accessing that server.
For some tips on navigating around, skip down to the getting around section.
From a windows PC To login to the command line of another machine from a windows PC, you'll need a secure-shell terminal program. The most popular is named putty, and can be downloaded from this link. The putty.exe top-left version under "binaries" works great.
Once you have putty, perhaps on your desktop, double-click it and type knuth.cs.hmc.edu into the textbox labeled "Host name or IP address" - then hit enter or click on "Open." If all goes well, you will get a window asking you for your login id (for example, hadas) and then your password, e.g., 42aliensLoveSpam. As you type your password, no text will appear; if there is a mistake, it will simply prompt you for your password again. Once you're successfully connected, you'll see a "welcome" message and then a command prompt. Try typing hostname at the prompt, and it should reply with knuth, indicating that you're indeed now on the main CS server.
This section is meant as a quick-as-possible introduction to the basic commands for getting around at a command prompt:
pwd The command-line is a text-based interface to all of the computational and storage facilities of a computer. The program that provides the command line is called a shell. The prompt provided by the shell can be customized, but it typically ends in % and awaits your commands... .
Type pwd at the prompt, and it will print your current directory. All of the files and programs on any machine are organized hierarchically. The root of the hierarchy is called root and is represented by a single forward-slash /. In text form, the nested-folder system of displaying this hierarchy becomes a series of directory names separated by forward-slashes, e.g., /home/hadas if you've logged in as Prof. Ran (please don't do this, unless you are Prof. Ran!)
ls This command lists all of the contents of the current directory. Try it - if you haven't added any files or directories, you'll see the default contents that new accounts are given.
I find ls rather frustrating because I can't tell which of the things listed are files and which are directories themselves (or programs). Use ls -F to get a forward-slash at the end of subdirectories and an asterisk at the end of runnable programs.
pico (or nano)
So, how to create files? There are many editors available, but the
one that is both the most hassle-free (and, perhaps, feature-free)
is named pico. To create a new text file named test.rex,
type
You will see an interface that looks like an ASCII-based window with
a header bar across the top and some available commands across the
bottom two lines. You can type some text into the window, for example,
pico test.rex
and then save the file with control-o (^O represents "control-o") -
it will prompt you for the name to save as, and hitting return simply keeps the
current name of the file. Finally, exit pico or nano with control-x.
answer = 42;
f(x) = x + 1;
In class we used nano -- it's OK, too. These do the same thing... (if one is scrolling through text in odd ways, use the other one).
If you type ls again, you should now see your text.rex file.
Try it out with
If there are no syntax errors, you'll see the rex > prompt. You
can make sure that Rex has read your file by trying
rex test.rex
You can get out of Rex by typing control-d. More Rex later.
rex > answer; // you're asking for the value of this expression
42 // this should be Rex's response
rex > f(f(answer)); // again, asking Rex to evaluate an expression
44 // its response
mkdir and cd
This command allows you to create a new directory.
It's probably a good idea to create a cs60 directory with
If you type ls -F, you should see that directory listed. To
leave the current directory and enter the one you just created, use the
"change directory" command, cd:
mkdir cs60
You can use pwd to ensure you're where you expect to be and ls
to verify that nothing is yet there! Create another directory named hw1
(or some other suitable name) and then change into that directory -- that will
be the location for this week's rex files.
cd cs60
cp and rm
These commands manpulate files: copying, removing, and moving them, respectively.
For example, there is a file in the directory named /cs/cs60/hwfiles/a1/part1.rex
that has a template for the first part of this week's hw and some example code.
To copy that file to your current directory, type (or copy-and-paste)
The period at the end is shorthand for "the current directory." Also, hitting tab
when you're in the midst of a partially-typed directory will ask the shell to
try to complete it for you. If you type cp /cs/cs60/h and then hit tab,
the shell will complete the hwfiles/ name - and so on. Tab-completion can
take a good deal of the typing out of text-based interfaces.
cp /cs/cs60/hwfiles/a1/part1.rex .
You will also want a file named part2.rex for the second
half of the problems. If you already have part1.rex in your
current directory, you can make a copy of it with a different name using
cp part1.rex part2.rex
If all went as expected, you should be able to use ls to see that you have a part1.rex and a part2.rex file in your current directory. You're ready to edit those files (perhaps with pico or nano) and get started with Rex!
Perhaps you don't want that test.rex file that was back in your home directory? You can "go up" a level in the directory hierarchy with cd .. -- those two periods are shorthand for "the next directory up." Another cd .. should bring you to your home directory, where rm test.rex will delete that file. Warning! rm should be used with caution. It does not warn you about deleting files and it does so completely -- it's not "undo-able." (If your file has been around long enough that the backup system has made a copy, you can ask CS staff to retrieve it for you, but that takes some time.)
These commands are only a small portion of the well-designed set of command-line tools that are available on all systems -- even windows PCs have all these same tools, though many have slightly different names, of course! A much more extensive introduction to the unix operating system and interacting with it via the command line is available at this link .
You can invoke Rex from the command line simply by typing rex. You
will see a rex > command-prompt, which is identical in spirit to
the Python command prompt. Try out a few definitions and evaluations:
If you forget to end an expression with a semicolon, rex will patiently (perhaps
frustratingly) wait for one... .
rex > x = 60; // binds x to 60
1 // rex says it's OK with that
rex > x; // asks for the current value of x
60 // rex says it's 60
rex > f(60) => 42; // a part of the definition for a function f
f // rex says it's OK with that
rex > f(x) => x+1; // another part of the definition for a function f
f // rex says it's OK with that
rex > f(60); // asks rex to evaluate this...
42
rex > f(41); // asks rex to evaluate this...
42
rex > f("hi"); // rex won't be so happy about this...
*** warning: can't add non-numerics hi
*** aborting to top-level
rex > (control-d) // hit the control-d sequence to exit rex
% // back at the unix prompt
You can load the definitions from your part1.rex file in two ways.
First, you can do so when you start rex via
Alternatively, when you're at the rex prompt, you can type
% rex part1.rex
Certainly, the file part1.rex needs to be in your current directory!
rex > *i part1.rex
When you load a file in, it will run any tests you have included (an easy way to run tests each time you change code!) - it will also provide you with the rex prompt so that you can test any of the definitions by hand, as well.
Efficiency suggestion - two windows: It's much more efficient to have two windows open to the same directory when developing programs - in Rex or any other language. In one window, you might have the rex prompt open; in the other window you would have the file you're editing -- that way, you won't need to close down the editor or rex in order to go back and forth between writing and testing! You could even have a third one open with a Rex prompt to test language questions, e.g., is 3/2 == 1 or 1.5? (It's 1.)
Good luck with Rex! You're ready to write the problems back on the main hw1 assignment page.
The instructions for submitting your work are at
the bottom of the main hw1 assignment page .
Back to the main hw1 assignment page
Back to the main hw2 assignment page
Being comfortable working from the command line is one thing; but it would be crazy not to use graphical interfaces when available and efficient! Although it takes a bit more setup, it's possible to open windows from knuth on a remotely logged-in machine. This section describes how (or at least one way how). Again, the instructions are different, depending on where you are...
From the Lab Macs Here, things are easiest -- you can use the computer's ordinary applications to open and edit your file. If you click on the background, you can then use the Go menu at the top of the screen to navigate to the TextMate application (or any other text editor). Open TextMate, and then use it to open your part1.rex file.
From a remote Mac
If you have the most recent Mac OS (version 10.5.x), this is pretty easy, too.
First, click on the background Desktop and then navigate the menu system through
Go - Utilities - X11. Double-clicking X11 will bring up a new terminal
window with the title xterm on top. Log in to knuth from that window with
the -Y flag, that is, ssh -Y name@knuth.cs.hmc.edu. This
line sets up a connection, known as X forwarding, over which graphical
data can be sent. Then, navigate to the directory where your part1.rex
file is located (or any other file). Type
The name gedit is the name of a text editor. The &
allows the editor to run in the background and gives you back a new
command prompt on the next line. Without the &, you won't be
able to use that window's command line until you shoutdown the emacs editor.
However, you will be able to open other windows to knuth.
% gedit part1.rex &
From a remote PC
The same instructions as described above for a Mac work also on a PC, except that you need to install the local graphics server, known as an X server, first. (On a Mac it's already there.)
The easiest, free X server for a PC is named Xming. You will need to download and install two packages: first, Xming itself and then, Xming's fonts. They are located at this Xming page under "Public Domain Releases" and at
I simply used the default install for each of them except that I chose to have an icon placed on my windows desktop for easy access... .Once those two packages are installed, you can change the settings within Putty to use Xming. To do this, first start Xming by double-clicking its desktop icon. You'll see a small Xming icon in the task bar at the bottom right of the screen. Then, open Putty and type knuth.cs.hmc.edu into the "Host Name" textbox as usual. Next, you'll need to turn on the "X11 forwarding" -- X11 is simply the name of the system allowing you to share graphics across machines:
Much more is possible, but this is certainly enough to get started interacting with a remote server via its command-line.