CS 357 Spring 2010

Jeffrey Knockel
Class Homepage
Recitation is Monday 2pm – 3pm in Centennial Engineering 1041.

Office Hours

Location
FEC 301A
Times

Installing Required Software

Download mzscheme from PLT Scheme. If you are running a debian or Ubuntu distro, then alternatively type:

sudo apt-get install mzscheme

Download ghc from haskell.org. If you are running a debian or Ubuntu distro, then alternatively type:

sudo apt-get install ghc6 ghc6-doc

CS Facilities

All required software is already installed on the department's machines. This means that you may use their machines locally on the third floor of Farris or work remotely on them via ssh. See the department's page on how to get an account for these machines and/or access them remotely.

Hacking in emacs

emacs is the common choice for hacking in Scheme/Haskell. Its advantage over editors like vim when it comes to editing Scheme and Haskell code is that it can run background Scheme and Haskell REPL buffers and selectively move expressions from an emacs buffer into a REPL buffer.

For your ~/.emacs file (updated 3/22/10)

(setq scheme-program-name "mzscheme -i -l defmacro.ss")
(setq auto-mode-alist
      (cons '("\\.scm$" . scheme-mode)
            auto-mode-alist))
(put 'eval-expression 'disabled nil)
(require 'font-lock)
(global-font-lock-mode t)
(show-paren-mode 1)
(put 'upcase-region 'disabled nil)

(load "/usr/share/emacs/site-lisp/haskell-mode/haskell-site-file.el")
(setq haskell-program-name "ghci")
(setq auto-mode-alist
      (cons '("\\.hs$" . haskell-mode)
            auto-mode-alist))
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
;; Choose indentation mode (the latter requires haskell-mode >= 2.5):
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
;;(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)

Replace red paths with appropriate paths, which may be an absolute path if it is for a program not in your $PATH. For instance, on Windows, try c:/progra~1/mzscheme/mzscheme.exe or c:/progra~2/mzscheme/mzscheme.exe for mzscheme.

Unlike scheme-mode, haskell-mode is not included with emacs. Before haskell-mode will work, you will need to download it from projects.haskell.org and install it. Alternatively, if you are e.g. running debian or Ubuntu, I have provided a debian package for haskell-mode 2.7.0.

Minimalist emacs cheat sheet

CommandDescription
emacs foo.scm (from shell)open file in emacs
C-x C-ssave
C-x C-cquit
C-gabort command sequence
C-bbackward character
C-fforward character
C-pup line
C-ndown line
C-x uundo
C-g (after undoing)you can now undo your undo's, i.e., redo by now undoing
Tab (in scheme-mode)indent to the appropriate column
Tab (in haskell-mode)cycle through possible appropriate columns
C-x 2split window into two
C-x oselect other window
M-x run-schemerun scheme REPL in current window
M-x run-haskellrun haskell REPL in current window
C-c C-lload file into REPL buffer

Good emacs references

Hacking in vim

Famous Lisp/Scheme hacker Paul Graham uses vim. And so do I. So if you do too, then you are in good company. Here is how you can get started hacking Scheme code in vim.

For your ~/.vimrc file (updated 3/22/10)

set ai
filetype plugin on
filetype indent on
aug scheme
    au FileType scheme setl lispwords+=define-macro
    au FileType scheme setl lispwords-=if
    au FileType scheme nn <Tab> ==
    au FileType scheme vn <Tab> =
    au FileType scheme setl inde=lispindent(v:lnum)
    au FileType scheme setl indk+=!<Tab>
    au FileType scheme let &l:makeprg = 'mzscheme -i -l defmacro.ss -e \(load\ \"' . shellescape(escape(expand('%'), '"\')) . '\"\)'
    au FileType scheme setl efm=%C%.%#:%*\\d:%*\\d:%.%#,%E%f:%l:%c:\ %m,%Z>%.%#,%-G%.%#
aug END
aug haskell
    au FileType haskell setl makeprg=ghci\ %
aug END

Replace red paths with appropriate paths, which may be an absolute path if it is for a program not in your $PATH. This will allow you to load your scheme or haskell file inside of a new REPL environment by using :make. Note that, unlike with emacs, there is no REPL persistently running in a buffer, so the environment is not preserved in between instances of the interpreter. This file will also integrate mzscheme's and ghci's error output with vim's quickfix feature.

Note: if you are using a debian or Ubuntu distro, make sure that you have the vim package installed as opposed to only the vim-tiny package, which does not include the extras that we need.

Turnin Instructions

We will be using the department's turnin script for turning in homework. You must be logged into a department machine to use it.

Here is example usage:
turnin cs357.hw1 knockel-hw1.scm # turn in file knockel-hw1.scm for assignment cs357.hw1
turnin -ls cs357.hw1             # list file(s) turned in for assignment cs357.hw1
To remove file(s):
turnin -rm cs357.hw1             # remove file(s) turned in for assignment cs357.hw1

The assignment name will always be cs357.hw# for homework #. Additionally, I have provided a sandbox assignment named cs357.sandbox. You may and are advised to play around with turning in files to the sandbox assignment before homework 1 is due to ensure that you know how to use the turnin script in time. I will not be accepting submissions via email.

A potential pitfall of the turnin script is that your turnin file's directory must be world executable and the file itself must be world readable. The recommended way of ensuring this is as follows:

cp knockel-hw1.scm /tmp
cd /tmp
chmod a+r knockel-hw1.scm
turnin cs357.hw1 knockel-hw1.scm
rm knockel-hw1.scm

General turnin guidelines

Selected Notes