In doing a problem set from the Internet a few weeks ago, I found myself writing awkward constructions with
LOOP to try to find the best one (or two or three) things in a big bag of things based on various criteria: similarity to English, hamming distance from their neighbor, etc.
I wrote a macro that encapsulated the pattern. I’ve reworked that macro into a library for public use.
There are a variety of examples in the README and the tests directory.
Here is one example to pique your interest. Suppose you have some data about the elevations of various cities in various states and you (being a Moxy Fruvous fan) want to know
What Is the Lowest Highest Point? Here’s how you might tackle that with the
(let ((data '(("Alabama" ("Birmingham" 664)
("Alaska" ("Anchorage" 144)
("Arizona" ("Grand Canyon" 6606)
(with-track-best (:order-by-fn #'<)
(dolist (state-info data)
(multiple-value-bind (city altitude)
(dolist (city-info (rest state-info))
(track (first city-info) (second city-info))))
(track (list (first state-info) city) altitude)))))
With this limited dataset, the end result would be
(VALUES '("Alaska" "Fairbanks") 531). The inner
WITH-TRACK-BEST finds the highest city in each state. The outer
WITH-TRACK-BEST finds the lowest of these.
I am putting together a networking library atop usocket for use in a multiplayer Lisp game. So far, I have implemented a library for serializing data into a byte buffer.
Here is a simple example of serializing some things into a buffer:
(make-enum-serializer :opcode (:login :run :jump :logout))
(make-bitfield-serializer :login-flags (:hidden :stay-logged-in))
(serialize* (:opcode :login
:string password) buffer)
You can unserialize those bits into existing places:
(let (opcode sequence-number flags login-name password)
(unserialize* (:opcode opcode
:string password) buffer)
You can unserialize them into newly-created variables for use within a body:
(unserialize-let* (:opcode opcode
:string password) buffer
Or, you can unserialize them into a list:
(let ((parts (unserialize-list* (:opcode
You can find out more about the serialization library on my unet page.
Growl is a notification system for Mac OS X. You run a Growl server on your machine. Then, applications can send notifications that will be displayed on your desktop. Growl supports a thin network protocol called Growl Talk that programs can use to send notifications to the Growl server (and hence, to your desktop).
Growl is incredibly useful for any program that operates asynchronously with the user. If you want to be notified when some portion of your job completes or when there is a critical error in your web application, Growl is a great tool to have at your disposal.
I wrote an implementation for Common Lisp of the client protocol. Here is a simple example of how you might use it:
(let ((growl:*growl-default-app* "My Lisp Application")
(growl:register :enabled (list "Warn" "Error")
:disabled (list "Info"))
(growl:notify "Program starting up..."
(unless (connect-to-database ...)
(growl:notify "Cannot connect to database!"
:title "Critical Error!"
For more complete usage information and to learn how to obtain the library, see the CL-Growl web page.
A few weeks back, I described an XML Parser Generator that I was working on. At the time, it could generate the parser it used itself. Now, it’s got Objective-C support and Lisp support. (The Lisp support is slightly better than the Objective-C support right now. With the Objective-C backend, you can create arrays of structs, but not arrays of strings or integers.)
Here is the Parser Generator home page.
Roto Mortar was written for the 2010 LISP Game Design Challenge. The challenge was to design and implement a game in seven days using some LISP dialect.
The KPs have been beating on your base all week. Your defenses are just about to collapse. In fact, your mortar cannons are both on the fritz. Billy Bob, the ACME Repair Guy, has just gotten one of your mortar cannons back online. Unfortunately, he had to wire things a little wonky. Your cannon is spinning all on its own. You’ve only got one button to control both the elevation of the cannon and when to fire it. And, you better fire it, because the KPs are still coming at you.
A few years ago, I read the book Game Design Workshop: Designing, Prototyping, and Playtesting Games. One of the exercises in the first chapter is to design a game with a “one-button interface”. At the time, I didn’t come up with anything particularly thrilling.
When I started brainstorming what to do for this Game Challenge, I remembered that exercise. I came up with this concept just under (as in 3.5 hours under) seven days ago. The game is nowhere near as polished as I’d like… but it was a 7-day thing. And, it was fun to take a break from Objective C to get back to some Lisp programming.
You can find out more about the game, including where to get the source and a Mac OS X binary, on the game’s web page.