[standards text in articles] bold in listings tags computational humour artificial intelligence computational humour humour lisp .... [] John Fremlin's Portable Version of Jess Johnson's Joke Generator in Lisp [ Jocelyn Paine's Home Page | Publications | Dobbs Code Talk Index | Dobbs Blog Version ]

John Fremlin's Portable Version of Jess Johnson's Joke Generator in Lisp

In Jess Johnson's Joke Generator in Lisp, I wrote about Jess's Lisp program for generating "What do you get when you cross X with Y?" jokes. Jess describes it and shows the source code here, but warns that it isn't portable, needing to run under Franz Inc.'s Allegro Common Lisp. Franz do release a free Allegro, which I explained how to install and run the joke generator on. Nevertheless, a portable version would be nice. And shortly before Christmas, John Fremlin mailed me to say he'd made one. I'm going to explain how to run it under three free Common Lisps: Steel Bank Common Lisp or SBCL; GNU CLISP; and Poplog Lisp. May also be useful to those starting Lisp and wanting to know about installing.


What is Common Lisp?

Common Lisp, one of two main dialects of Lisp. The other dialect, by the way, is known as Scheme, and is small and elegant. Common Lisp is much bigger, and some call it inelegant, but with its size and range of features — conveniently summarised at Features of Common Lisp by Abhishek Reddy — you're likely to find a utility to do almost anything you need.

Steel Bank Common Lisp

The first Lisp I tried was Steel Bank Common Lisp. That was partly because John suggested SBCL when he mailed me. But also, I've run SBCL on Windows XP before, and I know it's easy to install. It has a command-line interface, so I don't have to learn the mysteries of an Interactive Development Environment. And it's recommended by Bill Clementson's blog posting The Best Open Source CL Implementation. Admittedly, Bill wrote that almost four years ago; and moreover, in a reply to his posting, SBCL implementor Christophe Rhodes criticises Bill for being too complimentary.

But as a way to test-run John Fremlin's code, I thought SBCL would be fine. Unfortunately, although SBCL did run his code, it refused to run it more than once, coming up with some obscure error. That's why I tried the other two Lisps. Nevertheless, I'll explain how I installed SBCL, because it may help those new to the system.

As the SBCL site's History and Copyright page explains, Steel Bank Common Lisp is named after steel and banking, the industries where Andrew Carnegie and Andrew Mellon made their fortunes. (Bankers of today, please note: funding good works makes you popular.) This is because SBCL descends from CMUCL, a Lisp developed at Carnegie Mellon University.

I downloaded SBCL from SBCL's Download page. There's a table there with rows for different operating systems. I clicked on the yellow square labelled 1.0.29 in the final, Windows, row. This took me to a SourceForge page and asked me to save a Windows .msi file. I saved this to my desktop, then double-clicked on it to run it. I accepted the defaults offered by the install wizard, except that I chose C:\sbcl\1.0.29\ as the directory to install into rather than the one the wizard proposed under "c:\Program Files".

Next, I copied John Fremlin's code from Paste number 92459: portable joke generator, and saved it as c:\dobbs\jokes_jf.lisp .

Please note that an edit I recommended in Jess Johnson's Joke Generator in Lisp isn't necessary with John's code. There, I said that Jess's original source code at How to Write Original Jokes (Or Have A Computer Do It For You) has these lines near the top:

(setq *debug* t)
(setq *test-know* t)
The first line sets a global emit-lots-of-diagnostics variable, and the second tells the generator to use not the full knowledge base, but a small test one about parrots. Both are inconvenient, so I recommended changing each "t" (Lisp for TRUE) to "nil" (Lisp for FALSE). But John has already done that in his code, so you needn't bother.

So I have now saved John's code as c:\dobbs\jokes_jf.lisp . To run it, I started SBCL by double-clicking the "SBCL 1.0.29" icon that installation had put at the end of my Windows All Programs menu. (The icon is a white rectangle with a blue bar along the top, signifying a command-line interface.) This opened a black DOS-style window containing SBCL welcome text followed by an asterisk prompt.

To check SBCL, I typed 1 then Enter. This displayed 1 followed by another asterisk: SBCL's Lisp evaluator telling me that 1 evaluates to 1. A slightly more arduous test was to type

(+ 1 2)
at this new prompt, and press Enter. SBCL then displayed 3 followed by another prompt. As I noted in How to Write Original Jokes (Or Have A Computer Do It For You), in Lisp we code function calls as lists, with the function being the first element.

Since this worked, I was ready to run the joke generator. I typed

(load "c:/dobbs/jokes_jf.lisp")
and Enter. This displayed lots of compilation warnings, followed by T and another prompt. Then I simply typed:
This thought for half a minute, then output a list of jokes, starting with
and ending with
cereal killer
The run took 30 minutes.

Unfortunately, SBCL had problems. After the run had finished, I tried rerunning:

But SBCL displayed this message:
fatal error encountered in SBCL pid 30852:
set_pseudo_atomic_atomic: pseudo atomic bits is 1.

Welcome to LDB, a low-level for the Lisp runtime environment.

set_pseudo_atomic_atomic: pseudo atomic b


GNU CLISP, often just called CLISP. http://www.cs.utexas.edu/~novak/gclwin.html

Poplog Lisp

I wrote about Poplog, with examples and links, in Poplog, continuations, Eliza, AI education, and Prolog. It's a system that implements four languages — Pop-11, Prolog, ML, and Lisp — together with an editor (from which one can compile and run programs) and lots of documentation on the languages (especially Pop-11) and on Artificial Intelligence. I used to use it for teaching AI, and I like it a lot.

I decided to try the joke generator in Poplog's Lisp. Now, as I remarked at the end of Poplog, continuations, Eliza, AI education, and Prolog, Poplog has been somewhat neglected recently, and parts of it may not be compatible with latest standards. (But I recommend it if one wants to modify the languages / implementations, because of its openness, or if one wants to mix languages.) So although its Lisp is called Common Lisp, I wasn't sure how compatible with the latest Common Lisp. This is the reply Aaron Sloman gave me when I asked on .... He pointed at this file, last updated in June 1995, which lists known bugs and omissions in Poplog Common lisp: HELP BUGS.

To install Poplog, I followed the instructions in the University of Birmingham's Computer Science notes, HOWTO install Poplog on Windows (Vista). They only took a few minutes, and worked first time.

Installation left two new icons on my desktop. Both show a grey square cut into quarters with the letters "P" "op" "lo" "g" on. One square is captioned "Poplog", and is a shortcut that when I double-click, brings up a white window containing this text:

━I━┃ 6 (EXAMINING: c:\documents and settings\jocelyn\output.p) ━━━━━━━

 Sussex Poplog (Version 15.5 18/11/1996 12:12:27)
 Copyright (c) 1982-1996 University of Sussex. All rights reserved.

This ....

The other icon, also a quartered grey square, is captioned "Pop-11". Double-clicking this shortcut brings up a black DOS-style window showing the above text but without the VED status bar and following blank line. This is ....

Because both these icons invoke the Pop-11 language, you need to create another that invokes Poplog Lisp. To do so, make a copy of the Pop-11 shortcut by right-clicking it and selecting "Create shortcut". Find this copy on the desktop, right-click it, and select "Properties". This will display a window with several text fields, one of which is labelled "Target" and contains the command string that runs Poplog. Append a space followed by "+clisp" (without the quotes) to it, and press OK. This will make the shortcut start up Poplog with the Common Lisp saved state loaded. Thanks to Roger Evans for these instructions, in his reply to my pop-forum posting.

Double-clicking the new shortcut should now display a black DOS-style window whose final two lines are "Setlisp" and an "==" prompt. You can now check that the installation works, as I did with the other two Lisps:

Sussex Poplog (Version 15.5 18/11/1996 12:12:27)
Copyright (c) 1982-1996 University of Sussex. All rights reserved.
Common Lisp (Version 2.0)

== 1
== (+ 1 2)

To run the joke generator, load and invoke it as before. This time, there are no compiler messages:

== (load "c:/dobbs/jokes_jf.lisp")
;;; LOADING \dobbs\jokes_jf.lisp
== (generate)
I don't know, but it's ruff
The jokes appeared in a different order from in the other runs. I don't know whether this indicates a bug in Poplog. I then reran, and the jokes appeared in a different order again, which looked as though it might be the same as in the other Lisps.

The run took over an hour, which is slower than SBCL and CLISP. As ... warns, "". On the