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.



[Racket/Scheme] Project Euler Problem 5 Solution

Ok ok, I have to admit that Racket is pretty cool sometimes 😀 (despite it’s very verbous :D)
This is my solution for the problem 5:

#lang racket

(define (div-1-20? x)
  (let aux ([x x]
            [acc 1])
              [(= 0 x) #f]
              [(= 21 acc) #t]
              [(= 0 (modulo x acc)) (aux x (add1 acc))]
              [else #f])))

;; Pretty cool
(for ([i (stop-after (in-naturals 1) div-1-20?)]
      #:when (div-1-20? i)) (display i))

The dark magic is provided by in-naturals, stop-after and the #:when clausole:

  • in-naturals provide a lazy sequence from start to +inf
  • stop-after make sure that for will stop when the predicate div-1-20? will be satisfied
  • when assures that only when div-1-20? will be satisfied the for body will be executed

As result this code runs in constant space and is no memory-consuming at all 🙂