Emacs + Slime + SBCL on Windows Vista May 27th, 2009
Patrick Stein

I just finished setting up Windows Vista to run in VMWare Fusion. Then, I finally tackled setting up Emacs with Slime and SBCL under Windows Vista.

For the most part, I followed Robert Zubek’s gameplan. However, I quickly ran into a problem with swank’s temporary files not being in a writable location. I wish I had found this thread sooner. Alas, I ended up rolling my own by tweaking the temp-file-name function in swank-sbcl.lisp. The new version looks like this:

(defun temp-file-name ()
    "Return a temporary file name to compile strings into."
  #-win32 (concatenate 'string (tmpnam nil) ".lisp")
  #+win32 (concatenate 'string
                       (sb-ext:posix-getenv "TEMP")
                       "/"
                       (symbol-name (gensym "SL"))
                       ".lisp"))

Developing Lisp in Ubuntu Linux with VMWare Fusion May 27th, 2009
Patrick Stein

I am working on some lisp software that I would like to run under Linux, MacOSX, and Windows.

I have a PC that I can boot into either Ubuntu Linux or Windows Vista. Of course, I have a variety of services running under Ubuntu Linux on that box that the rest of my network would rather have around. As such, I would rather never boot that machine into Windows. So, I thought I’d give VMWare Fusion a try.

Actually, I thought I would try both VMWare Fusion and Parallels. Alas, Parallels lets me get my virtual machine set up, but will not let me run it without a license. VMWare Fusion lets me play for 30 days before buying a license. From what I’m seeing from VMWare Fusion’s performance, I can’t imagine dropping $80 on Parallels just to see if its virtual machine can outperform what I’m seeing from Fusion.

Right now, I am in the process of moving over the PC’s Windows stuff to my laptop so I can try running Vista through Fusion. While I was waiting for that, however, I installed Ubuntu under Fusion, updated a ton of packages, installed emacs, sbcl, slime, etc.

For comparison, I took some lisp code that runs in just under 11 seconds on my laptop. I ran the same code under Ubuntu in Fusion on the same laptop. It ran in just under 12 seconds. Some of that may also be that I am using an older version of SBCL under Ubuntu than I am native.

I have some more testing to do to make sure that cl-opengl will perform as well. But, I am quite pleased.

Kindle App Makes Progress May 26th, 2009
Patrick Stein

Last month, I wrote about Four Ways eReader Beats Kindle on the iPhone. It looks like the 1.1 release of the Kindle iPhone app addresses the first of those four ways.

They now let you select between portrait or landscape mode. It lets you turn pages by tapping or swiping. And, it lets you change the background and text colors a bit.

I’m not terribly fond of its mechanism for letting you lock in landscape or portrait mode, but at least you can do it now. And, I don’t have free range on color choices, but at least I have some choice.

I hope they tackle my other three points in later releases.

Optimizing Lisp May 24th, 2009
Patrick Stein

Paul Reiners recently posted some code to the TC Lispers mailing list. The code began from Paul Graham’s ANSI Common Lisp book. Exercise 13b has you adding declarations to some code so that the compiler can better take advantage of the types involved. Oddly, the code ran more slowly with his typing than it did without it. I had the same experience when I tried this code under SBCL 1.0.23 on Mac OS X.

Here is Paul’s original code which he made available with Creative Commons License the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.

I stripped out the declarations and started adding them in one by one, trying to deal with as many compiler notes as I could figure out in the process. First, in the base case, the following took 22.5 seconds on my computer.

(time (ray-test 8))

After much tweaking, I have gotten it down to just under 11 seconds. Most of that came with declaring the types of the slots in the (defstruct …)‘s and these three declarations:

(declaim (ftype (function (long-float) long-float) sq))
(declaim (ftype (function (long-float
                           long-float
                           long-float) long-float) mag))
(declaim (ftype (function (long-float
                           long-float
                           long-float)
                          (values long-float
                                  long-float
                                  long-float)) unit-vector))

This declaration, however, shot me back up to 22 seconds.

(declaim (ftype (function (long-float
                           long-float
                           long-float)
                          long-float)) minroot))

Of course, it really should have been returning (or long-float nil). But, that didn’t help either. From the compiler notes, it seems that (min …) in SBCL doesn’t deal well with unboxed floats. I will have to look harder at that section and ask on the SBCL lists. I believe that I tried decorating the expressions there, too.

(the long-float (min (the long-float
                       (/ (the long-float (+ (the long-float (- b))
                                             discrt)
                               (the long-float (* 2L0 a)))))
                     (the long-float
                       (/ (the long-float (- (the long-float (- b))
                                             discrt)
                               (the long-float (* 2L0 a)))))))

Lisp Patterns Question W.R.T. Clifford Algebras May 20th, 2009
Patrick Stein

Since I moved my website to WordPress, I have been watching what search-engine searches land people on my page.

Sadly, two of the things that get people to my page most often still have not been moved over to the new site from the old. One of those things is a C++ template library for Clifford algebras. I am going to move that stuff over this week, I promise. But, I thought I might also make a Lisp library for Clifford algebras, too.

An example Clifford algebra might be C_{3,0}. A generic element in this algebra is of the form:

a_0 + a_1 e_1 + a_2 e_2 + a_3 e_3 + a_{1,2} e_{1,2} + a_{1,3} e_{1,3} + a_{2,3} e_{2,3} + a_{1,2,3} e_{1,2,3}

where the a_* are coefficients. For ease in dealing with these items, I will probably store that in a vector that looks something like this:
#(a_0 #(a_1 a_2 a_3) #(a_{1,2} a_{1,3} a_{2,3}) a_{1,2,3})

If you want a simple element though (where most of the coefficients are zero), you shouldn’t have to stare down all of that stuff or remember that a_{1,3} comes before a_{2,3}. I want you to be able to make 3 + 4 e_1 + 5 e_{1,2,3} more simply. Something like one of the following:

(defvar *a* (ca-element '(3 (4 1) (5 1 2 3)) :p 3))
(defvar *a* (ca-element '(3 (4 . :e1) (5 . :e1-2-3)) :p 3))
(defvar *a* (ca-element :s 3 :e1 4 :e1-2-3 5 :p 3))

Similarly, I will define something akin to (aref …) so that one can check or change a_{1,2} like one of the following:

(caref *a* 1 2)
(caref *a* :e1-2)

By analogy with the complex numbers, I should instead have:

(e1-2 *a*)

But, that just doesn’t scale very well.

I am leaning toward using a list of numbers to tell which a_* is being referenced. This would allow greater flexibility in other functions. But, it’s also less mathy.

Does anyone have any suggestions? Should I really be supporting both? Through the same function names or through (caref …) and (caref* …) or something?

Updates In Email

Email:

l