Enhancing Your Development EnvironmentTopAdding DimensionsWorking Within a FileGoTo Top

Working Within a File

Now that we've enhanced our GBBopen and Common Lisp development environment, let's begin developing the random-walk application in earnest.


This exercise shows you how to:


Step 1: Create the tutorial-example directories

Create a directory to hold the random-walk application. I'm calling mine tutorial. Next, create a subdirectory in that directory named source. The reason for doing this will become clear in an upcoming exercise. Here are the shell commands that I used to create my directories:

  [~]$ mkdir tutorial
  [~]$ cd tutorial
  [~/tutorial]$ mkdir source
  [~/tutorial]$

Step 2: Create the tutorial-example file

Start up a fresh Common Lisp session and load the :gbbopen-user module, using the REPL command we set up in the last exercise:

  cl-user> :gbbopen-user
  ;; Loading <install-dir>/startup.lisp
     ...
  ;; Loading <install-dir>/<platform-dir>/gbbopen/gbbopen-user.fasl
  gbbopen-user>

Next, begin editing a new file named tutorial-example.lisp in the source subdirectory that you just created. Even if you are more comfortable using another editor, use the editing facilities that are provided by your Common Lisp environment. The development features of a quality Common Lisp environment are well worth the price of learning a new editor. In an Emacs-based environment, such as SLIME or Allegro CL's ELI, typing C-x C-f will prompt you for the name of a file to editor or create. (We will use Emacs key-binding notation, where C-x C-f means typing ^c followed by ^f.)

Type the following two forms into the tutorial-example.lisp file buffer:

  (in-package :gbbopen-user)

  (define-unit-class location ()
    (x y))

The in-package form specifies the Common Lisp package that is made current when the file is compiled or loaded. The first form in every Common Lisp source file that you create should begin with an in-package form. This form is also used by most Common Lisp editing environments to set the package associated with development operations.

The define-unit-class definition is the same one we used in the Creating a Unit instance exercise.

Now, save the file.

Step 3: Compile and load the tutorial-example file

At this point, we have been using Common Lisp's development environment, but we have not loaded the forms in our file into Common Lisp:

  gbbopen-user> (make-instance 'location)
  Error: No class named: location.
  gbbopen-user>> :a
  gbbopen-user>

We could use Common Lisp's compile-file to compile the file and then load to load the resulting compiled file. For example:

  gbbopen-user> (load (compile-file "~/tutorial/source/tutorial-example.lisp"))
  ;; Compiling file ~/tutorial/source/tutorial-example.lisp
  ;; Loading ~/tutorial/source/tutorial-example.fasl
  t
  gbbopen-user>
but you should be able to compile and load the file directly from the editor buffer. In SLIME, the command C-c C-k will compile and load the file currently being edited. Allegro's ELI interface compile-and-load command is C-c C-b. Identify and use the compile-and-load-file command in your editing environment.

Verify that all is well by creating a location unit instance in the REPL:

  gbbopen-user> (make-instance 'location)
  #<location 1>
  gbbopen-user>

Then delete the blackboard repository in preparation for the next exercise:

  gbbopen-user> (delete-blackboard-repository)
  t
  gbbopen-user>


The GBBopen Project


Enhancing Your Development EnvironmentTopAdding DimensionsWorking Within a FileGoTo Top