Getting Started with SML
		
			Using Princeton's Machines
			
				We will be using OIT's hats/arizona machines for this course.
			
			
				To begin, ssh to
				
arizona.princeton.edu or
				
hats.princeton.edu. Assuming you are using 
				tcsh/csh, you need to add the following line to your ~/.cshrc file in order to 
				add SML to your path.
				
					setenv PATH ${PATH}:/u/cos441/ml/
				
			
				Once you have done this, issue the command
				source ~/.cshrc
				to reload your .cshrc file, and then run
				sml
				to begin interacting with SML.
			
		 
		
			Installing SML on your own machine
			
				If you would like to install SML on your own machines, you can download it from 
					SMLNJ.org. If you are using Windows or Linux, use the current version 
				110.0.7. If you're running Mac OS X, you'll have to try a working version.
			
 
		
			Interacting with SML
			
				The SML command prompt is a dash. Terminate commands with a semicolon. Assuming 
				your expression is well-typed, SML will respond with
				val it = v:t, where
				v
				is the resulting value and
				t
				is the type of that value. You can then use the variable
				it
				in the next input. To exit SML, close the input using the standard EOF 
				character,
				Control-D.
			
				willy% sml
	Standard ML of New Jersey, Version 110.0.7, September 28, 2000 [CM; autoload enabled]
	- 3+4;
	val it = 7 : int
	- it - 5; 
	val it = 2 : int
	- let val x = 3 in it + x end;
	val it = 5 : int
			
			
				Type
				use "file.sml";
				at the command prompt to load code from a file. SML will then try to locate 
				that file in the current directory.
				OS.FileSys.getDir();
				shows you the current directory.
				OS.FileSys.chDir("../where/ever/");
				changes the current directory.
			
		 
		
			Syntax Highlighting
			
				It may be helpful to use an editor with syntax highlighting for SML. We 
				recommend using emacs since there is a package called 
					sml mode, with documentation 
					available.
			
				To use sml mode on the department machines, put this 
.emacs
				file in your home directory.
			
 
		
			An Example
			
				The following details the way that I like to use sml and emacs. Feel free to 
				ignore it, but it's a good place to start if you're completely confused.
			
			
				If you've got an Xserver such as Exceed running, type
				emacs foo.sml &. If not, you can do
				emacs -nw foo.sml. (In this case, you'll get 
				grayscale syntax highlighting.)
			
			
				Assuming you are using the provided
				
.emacs
				file, emacs will realize from the file extension that you are writing sml code 
				and automatically put you into sml mode. You'll see
				
(SML)
				on the dark bar near the bottom of the window. You'll also get an SML menu on 
				the top bar.
				
			
				Emacs has slightly odd notions of windows. A emacs frame is basically what you 
				usually think of as a window. You can divide a frame into multiple windows 
				(just like splitting the screen in most editors). A buffer is an open file or 
				some other process (such as the SML buffer or the default scratch buffer). So 
				for example, you can have one frame split into two windows, while having three 
				files open, two of which are visible at the moment.
			
			
				I use the following keyboard shortcuts to set up my workspace the way I like 
				it. (The same options should be available in the menus somewhere.)
				
C-x
				means hit
				
Control
				and
				
x
				at the same time.
				
M-xmeans hit
				
Alt
				or
				
Esc
				and
				
x. (Note that if you're using an Xserver, you may 
				have to set it up to forward
				
Alt
				to X.)
				
C-x b
				means hit
				
Control
				and
				
x
				at the same time and then hit
				
b.
				
					- 
						C-x 2
					divides the frame horizontally into two windows.
					
- 
						C-x o
					moves you to the other window.
					
- 
						M-x sml enter
					starts SML in the background.
					
- 
						C-x b *sml* enter
					switches buffers and moves SML into the lower window.
					
- 
						C-x o
					moves you back to the top window.
					
- 
						C-c C-b
						loads the current buffer into SML and the results will be displayed in the SML 
						process in the bottom window.
				If emacs gets confused while you are entering a command, hitting
				C-g
				a few time usually sorts things out. If you're typing words (like a file name 
				or buffer name), you can use tab-completion.
			
			
				Here are a few more 
useful emacs commands.
			
 
		
			Using the Compilation Manager
			
				Some of the later assignments will use SML's compilation manager to 
				compile larger projects. All the files you want to compile should be listed in 
				a file called
				sources.cm. Path names in
				sources.cm
				are relative. (sources.cm
				will be provided for you with the code for each assigment.)
			
			
				To compile code with the compilation manager, first make sure SML is in the 
				directory where
				sources.cm
				is located. Use
				OS.FileSys.getDir();
				to see the current directory and
				OS.FileSys.chDir("../where/ever/");
				to change the current directory the current directory.
			
			
				Once the directory is correct, type
				CM.make();
				and SML will compile all the files listed in
				sources.cm. If you see
				val it= () : unit;
				at the end, then your files all compiled correctly. Otherwise there will be 
				error messages.
			
			
		 
		
			Other Useful Hints
			
				If you get hash marks when printing out values, try changing the printLength 
				and printDepth:
				
                        - int2nat(5); 
                        val it = succ (succ (succ (succ (succ #)))) : nat 
                        - Compiler.Control.Print.printLength := 1000; 
                        val it = () : unit 
                        - Compiler.Control.Print.printDepth := 1000; 
                        val it = () : unit 
                        - int2nat(5);           
                        val it = succ (succ (succ (succ (succ zero)))) : nat 
                        
			 
		
			Page maintained by frances@cs. Last updated 9/24/2005.