Just more than a mental note for myself.

If playing with Lispbuilder-sdl you caught the error:


The solution is to locate the stdinc.lisp file under


And change all the occurrences of “putenv” into “setenv”.

Seems ok now. Tested under SBCL 1.0.54

ANN: Textmate 2 Common Lisp bundle

Hi everyone,

finding the perfect programming environment is a rough task, something akin to the search for the sense of life of the holy Graal. However, I think that this time I’m on the right track, or at least close to the perfection.

Fact 1: Common Lisp

Recently I’ve fallen in love (again) with Common Lisp: this kind of things happens in regular cycles, where I program for a while with a language, leave it behind, turn my attention to another one, to finally come back to the first one. This happened for Common Lisp, Clojure, Haskell and so on. Maybe this time of the year is my “Lisp time slice”.

Fact 2: Lispers love Emacs

If you ask to a random pick of 100 programmers, probably you’ll got 100 different answers to the question “What’s your favourite editor?”. By the way, two common answers are “Emacs” and “Vim”. I tried them both, but I’m not fully satisfied neither from Emacs nor from Vim. Let’s say that I like 50% of Emacs’ features and the same applies for Vim, but I’ve always found Emacs and Vim a general purpose solution not close to the cool look and feel and speed of Cocoa Native Applications.

Fact 3: TextMate 2

It happened that on December 15th, Macromates has finally released the alpha version of TextMate 2: best of all, for the TM1 users, this is a free upgrade, so I haven’t hesitated, and downloaded it instantly. TM2 offers many new cool enhancements, like tab support and a sort of manager that allow you to choose, download and keep updated tons of themes and bundle. One cons is that, at least for now, TM1 Bundles are not supported, so the only way you have to use an old fashioned TM1 Bundle is to manually convert to TM2: fortunately is not an hard task (let’s say a trivial one).

Fact 4: The Hound of the Baskervilles

The Hound of the Baskervilles is the third of four crime novels by Sir Arthur Conan Doyle featuring the detective Sherlock Holmes. Originally serialised in The Strand Magazine from August 1901 to April 1902, it is set largely on Dartmoor in Devon in England’s West Country and tells the story of an attempted murder inspired by the legend of a fearsome, diabolical hound.

Am I crazy, reporting the Wikipedia description of a book by Sir Arthur Conan Doyle? Nope, and you’ll find out why. TextMate 1 got an extremely sexy Bundle for Common Lisp, developed by Bastien Dejean (credits are due). As I said before, this was not compatible with TM2, so I decided to convert this for TM2, and finally have a cool environment to work with. For some unfathomable reasons it revealed a tricky task, so I thought that a blog post is necessary to celebrate my success.

Fact 5: tmux

tmux is a terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached. In a nutshell, the bundle use this to create a new SBCL session, and provide a mechanism to send and receive input/output from/to a terminal. So your workflow become:

  1. Open a new session (from TM)
  2. Attach to the newly created session (always from TM)
  3. Write a bunch of functions (higher order is preferred, cit.)
  4. Evaluate them sending to a running instance of SBCL
  5. Receive the response as growl notices
  6. Have fun!

The only tricky part of the conversion was that tmux 1.5 removed the -t option for load-buffer, a command heavily used from the Bundle to manage the communication with the SBCL instance, but I couple of bash if allowed me to extend the compatibility even to tmux 1.5.

After this little complication, I was able to successfully convert the bundle: you can download it from here, and watch the screencast Bastien has prepared for us!

Personally I think that I have everything I need to rapidly prototype and code in Common Lisp, and this bundle can easily adapted for Clojure and Haskell too! Best of all, TM2 is also faster the his grandaddy, so I’ve found the entire working process leaner and faster!

I hope you’ll enjoy this as much as I’ve enjoyed.



The power of the big


I’ve been quoted into a sort of report about F# and XNA development (Btw, I’ve only tweaked a bit a source code found on the net, just to learn a bit F# and XNA):

I’m really surprised due to the echo of F# and XNA all over the internet… I mean, I’ve spent hours playing and writing about other awesome functional languages (Haskell, Scheme, Common Lisp, Clojure) but I’ve never been quoted, because “Speaking about Common Lisp and other crazy stuff is not cool”. This is sad, really sad.

On the other side, I’m very proud of have been cited somewhere 😛 (despite I haven’t done nothing special)




Fixing Slime’s “connection broken by the peer” with Lispbuilder-sdl

Something more than a mental note.
While programming with Common Lisp using the Lispbuilder-sdl library probably you want to evaluate your programs within Emacs and Slime (as usual.)
By the way, even with the simplest SDL program on slime-eval-region (or whatever else) Slime terminate in an expected way with this message:

[…]Connection broken by the peer[…]

Googling hard, I’ve found a solution that works like a charm!
First of all, open your swank.lisp file (you can find it inside your Slime installation), then add this line:

(setf swank:*communication-style* :fd-handler)

Done! It was simple enough, wasn’t it?
Now you can evaluate your lisp game within Emacs!

Lisp is simmetry, understanding the find function

It may seems quite obvious, but the Lisp’s “find” semantic gave me some headache.
First of all, let’s start with some code:

(defvar *food-list*
  '((mela (pera banana)) (melanzane zucchine peperoni) (carne pesce uova)))

The “find” function gives you the power to search in a list for an item, returning back the element (if found) within his sublist (if present). Unfortunately, if the list is not symmetric, there is no guarantee to get the expected behaviour:

(find 'pera *food-list*)
=> NIL ;;WTF??

With find the list is visited one element at time, applying “eq” to any single element:

(eq 'pera '(mela (pera banana)))
=> NIL
(eq 'pera '(melanzane zucchine peperoni))
=> NIL
(eq 'pera '(carne pesce uova))
=> NIL

But how can we reach our pera within the find function? The “key” is in the “:key” parameter!!
With :key we can specify a function to be executed for each element find visit. It’s an old lisp school technique to use the car & cdr family functions:

(find 'pera *my-list* :key #'caadr)

Wow, it works! This is what happened in background for each element:

(eq 'pera (caadr '(mela (pera banana))))
=> T
(eq 'pera (caadr '(melanzane zucchine peperoni)))
=> NIL
(eq 'pera (caadr '(carne pesce uova)))
=> NIL

Simple enough, isn’t it?

Low and behold: subsequence

But what about searching for a sublist? What about searching for ‘(pera banana)? The following doesn’t work:

(find '(pera banana) *food-list* :key #'cadr)
=>NIL ;;WTF!!! AGAIN!!! WHY??

In order to solve this, remember what I’ve said about the comparison element by element! Yes, it’s made with the “eq” function! But you should know that “eq” works with nothing but symbols! We need the equal function in order to archive the result, but how can we force “find” using “equal”? The answer is in “:test”:

(find '(pera banana) *food-list* :test #'equal :key #'cadr)



At the beginning some Lisp’s functions can be puzzling even if you are not a newbie with the functional programming, but this post should be useful to properly understand even the “find” function: Now let’s the hack begin! (cit. from Slime)