Common Lisp Set-Up

(0) Background: Connection to the IFI Linux Environment

The course environment for INF4820 is pre-installed on Linux desktops and servers at IFI; thus, while at the department, one can usually proceed immedately with steps (1) and onwards below.

When not at the department, there are several options to connect to the IFI Linux environment.  On any (reasonably modern) Linux or MacOS installation, the following command will create a login session, typically prompting for the user password, and arrange for X11 display forwarding (please note that the modern-Y’ switch is required):

  ssh -Y <user>@login.ifi.uio.no

From a desktop running M$ Windows, the most straightforward option is to establish a remote desktop connection to the IFI server windows.ifi.uio.no. Once connected, there may be a desktop shortcut called ‘xterm’ (or the like) to connect onwards to the IFI Linux environment.  If not please create it yourself when you connect for the first time: Open the program 'X-Win32 2012'. Under the tab 'Connections', in the box 'New Connection', click 'Manual', then select 'ssh', and specify the following fields:

Connection Name: xterm
Host: login.ifi.uio.no
Login: <your username>
Command: xterm

Save and mark the new connection before clicking 'Shortcut', which will allow you to place a shortcut on the windows desktop to launch the connection to 'login.ifi.uio.no' and open up an 'xterm' command line window.

(0) Emacs Fundamentals

If you have not used emacs before, we recommend you spend five to ten minutes working through its tutorial, available from the ‘Help’ menu at the top of the window, or through typing ‘C-h t’, i.e. the ‘Control’ and ‘h’ keys jointly, followed by just the ‘t’ key (without holding down ‘Control’).

Emacs is organized internally in so-called buffers, creating a new buffer for every file that is opened for editing; in a similar spirit, communication with the Common Lisp environment (i.e. interactive development) will be through a dedicated buffer.  The ‘Buffers’ menu (or the command ‘C-x C-b’) can be used to view the current list of buffers and switch between them; the key binding for switching to another buffer is ‘C-x b’ (switch-to-buffer), which will prompt for a buffer name.

A buffer reserved for status messages and interactions with emacs is the so-called minibuffer at the bottom of the window; here, emacs will prompt for input (e.g. a file name or search pattern) and display status updates.

A compact summary of (more or less) common emacs commands and key bindings is available through the emacs reference card, which it might be worth printing out—to keep at hand during the day (and under your pillow at nighttime).

(1) First-Time Preparations

We distribute a set of configuration files and emacs add-ons through an anonymous SubVersion revision control system.  To obtain our starting set for the course, please run the following (typically from within your home directory) from the command line:

  svn co http://svn.emmtee.net/ltg/inf4820/17/public inf4820

The result should be a new directory called ‘inf4820’, containing code for the Superior Lisp Interaction Mode for Emacs (SLIME) and a file with configuration options called ‘dot.emacs’. 

To activate our course setup, please use emacs to open the file ‘.emacs’ in your home directory (which you can refer to as ‘~’ both in the shell and in emacs); add the following lines towards the end of the file:

  (if (file-exists-p "~/inf4820/dot.emacs")
    (load "~/inf4820/dot.emacs"))

For the configuration changes to take effect, exit emacs and start it again.

(2) Using SLIME and Allegro Common Lisp

Assuming the above one-time configuration was successful, emacs will now automatically load our course-specific configurations.  To invoke SLIME, launch the Common Lisp environment, and connect emacs for interactive Lisp development to it, type following in emacs:

  M-x slime RET

As you know from previous emacs experience, the above abbreviates a key sequence comprised of (a) pressing the ‘Alt’ (aka Meta) and ‘x’ keys simultaneously, which will put emacs into command prompt mode; (b) typing the command name to be executed, i.e. ‘slime’; and (s) submitting the command by pressing the ‘Enter’ (or Return) key.

The above command will create a new buffer in emacs called ‘*inferior-lisp*’, which ‘talks’ to the Common Lisp environment, i.e. its read–eval–print loop.  When trying out small, individual s-expressions or debugging something interactively, it can be convenient to work directly in this buffer; emacs maintains a history of previous expressions, which can be navigated through the key bindings ‘M-p’ (previous) and ‘M-n’.

For any serious programming, however, it will be convenient to edit code in a file (whose extension should be ‘.lisp’, e.g. something like ‘exercise1.lisp’) and use SLIME commands to load (i.e. evaluate) or compile the whole file or parts of it.  For example, it is possible to evaluate or compile a single function definition by typing ‘M-C-x’ or ‘C-c C-c’, respectively; here, the definition to be evaluated is the one closest to the current cursor position (called the point in emacs).  In a similar spirit, ‘C-c C-l’ and ‘C-c C-k’ will evaluate or compile the entire file.  The SLIME reference card provides a compact summary of common key bindings.

As a rule of thumb, note that debugging interpreted (i.e. uncompiled) code can at times be easier, but running your definitions through the compiler often has two advantages: compilation will perform much more rigid error checking, and compiled code runs much faster.

(3) Other Common Lisp Implementations

The Allegro Common Lisp environment is a very mature commercial product (with a strong compiler and garbage collector) that is available at IFI only. However, taking advantage of the abstraction offered by the open-source SLIME package, it should be relatively straightforward to use other, open-source Common Lisp environments. For the purpose of validating exercise submissions and general support, we will assume Allegro CL as the reference implementation. However, for complementary use away from the department or on private computers, it might be worth taking a look at Steel Bank Common Lisp (SBCL) or Clozure Common Lisp (CCL), which both are assumed to implement the ANSI Common Lisp standard and work well with SLIME.

Publisert 17. aug. 2017 13:40 - Sist endret 7. feb. 2020 16:03