"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Saturday, April 02, 2011

Practical Common Lisp

I am reposting this from February 24, 2005 - given my renewed interest in Common Lisp. It has been 22 years since programming in CL professionally. I have brought up a CL implementation several times in between, but never to do much of anything real. Most of my Lisping over these years has been in various Scheme dialects.

I love Scheme and some great Scheme implementations like Gambit. I may not have given up on Scheme forever, but... After all these years the Scheme standard is a kernel and there's not much in the way of a portable registry of libraries.

There are several commercial and free Common Lisp implementations of very good quality. And an apparently long list of portable libraries. I've only recently tried Steel Bank Common Lisp (derived from CMU CL, which was first implemented in the early 1980s), but my impression is that any of these high-quality CL implementations is as good a choice as ever. Nothing like Java's base of software, but rich enough to keep exploring nevertheless.

What about Clojure? I've used Clojure a bit over the last couple of years. Clojure is great, and has access to Java's libraries. However I recently gave up the JVM for Lent. Really I'm just stepping away from the Java platform to see what other things can do. For exploring and fun I felt the need to step away at least temporarily from all the Java-based bits and pieces. I am not really missing anything so far.

I am happy to move around. There are a lot of good options in the wide web world. One dream not quite yet fulfilled is a world where all these languages can get along with extreme ease. (And by that I do *not* mean "running in the same virtual machine".) They can each get along fairly well with Javascript, running on a server and talking over HTTP. They can get along with each other modestly using JSON or XML, one as the HTTP client, another as the HTTP server. Better than ever, but the difficulties mount rapidly beyond this simple case.

Oh yeah, I digress. Here's that repost from 2005:

As seen on Lemonodor...

The book Practical Common Lisp shows the power of Lisp not only in the areas that it has traditionally been noted for—such as developing a complete unit test framework in only 26 lines of code but also in new areas such as parsing binary MP3 files, building a Web application for browsing a collection of songs, and streaming audio over the Web. Many readers will be surprised that Lisp allows you to do all this with conciseness similar to scripting languages such as Python, efficiency similar to C++, and unparalleled flexibility in designing your own language extensions.

Using SPARQL endpoints and 4store RDF databases from Common Lisp

Jeni Tennison posted an interesting article using the 4store for RDF databases from Ruby. This was an experiment to see how close one can get to meeting a challenge from Richard Pope. The challenge puts forth criteria for a set of easy-to-use "linked data" programming tools.

I have duplicated the essence of the ruby/4store demonstration, using common lisp. Mainly because I like programming in various lisp dialects, I want to explore using 4store, and I recently decided to pick up common lisp again after, for all intents and purposes, a 20 year hiatus from that particular dialect.

The source and sample data is on github at https://github.com/patrickdlogan/sbcl-4store

These are just some examples that a reusable package could be based on. The code in workspace.lisp includes instructions for installing 4store on ubuntu, installing Steel Bank Common Lisp, and using the quicklisp system (think ruby gems) for finding and installing useful libraries.

Several functions are defined showing quickly how to load, query, and process RDF data. Two primary functions and their results are listed here:

The function extract-rdfs-classes performs a SPARQL "select" query to select all of the RDFS classes from the sample data. Note: these are not 'object-oriented classes', rather an RDFS class is more like the identifier of a logical "set" of members which are themselves identifiers.

The SPARQL query is:

prefix rdf: 
prefix rdfs: 
select distinct ?type 
where { 
  ?x a ?type .
} 
order by ?type
And running it from the lisp REPL:
* (extract-rdfs-classes)

("http://purl.org/linked-data/cube#DataSet"
"http://purl.org/linked-data/cube#DataStructureDefinition"
"http://purl.org/linked-data/cube#Observation"
"http://purl.org/net/opmv/ns#Artifact" "http://purl.org/net/opmv/ns#Process"
"http://purl.org/net/opmv/types/google-refine#OperationDescription"
"http://purl.org/net/opmv/types/google-refine#Process"
"http://purl.org/net/opmv/types/google-refine#Project"
"http://rdfs.org/ns/void#Dataset"
"http://reference.data.gov.uk/def/central-government/AssistantParliamentaryCounsel"
"http://reference.data.gov.uk/def/central-government/CivilServicePost"
"http://reference.data.gov.uk/def/central-government/Department"
"http://reference.data.gov.uk/def/central-government/DeputyDirector"
...
The function extract-persons performs a SPARQL "construct" query to construct a graph of FOAF Person instances along with their FOAF names and other triples having the instance as the subject.

The SPARQL query is:

prefix foaf: 
construct {
  ?person 
    a foaf:Person ;
    foaf:name ?name ;
    ?prop ?value .
} where { 
  ?person a foaf:Person ;
  foaf:name ?name ;
  ?prop ?value .                        
}
And running it from the lisp REPL:
* (extract-persons)

(("http://source.data.gov.uk/data/reference/organogram-co/2010-10-31#person189"
  "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
  "http://xmlns.com/foaf/0.1/Person")
 ("http://source.data.gov.uk/data/reference/organogram-co/2010-10-31#person189"
  "http://xmlns.com/foaf/0.1/name" #<"Philip Davies"@en>)
 ("http://source.data.gov.uk/data/reference/organogram-co/2010-10-31#person189"
  "http://reference.data.gov.uk/def/central-government/holdsPost"
  "http://reference.data.gov.uk/id/department/co/post/190")
 ("http://source.data.gov.uk/data/reference/organogram-co/2010-10-31#person189"
  "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
  "http://xmlns.com/foaf/0.1/Person")
 ("http://source.data.gov.uk/data/reference/organogram-co/2010-10-31#person189"
  "http://xmlns.com/foaf/0.1/name" #<"Philip Davies"@en>)
 ("http://source.data.gov.uk/data/reference/organogram-co/2010-10-31#person189"
  "http://xmlns.com/foaf/0.1/mbox"
  "mailto:philip.j.davies@cabinet-office.x.gsi.gov.uk")
 ("http://source.data.gov.uk/data/reference/organogram-co/2010-10-31#person189"
  "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
  "http://xmlns.com/foaf/0.1/Person")
...

Bill Hicks

Netflix now has four "watch instantly" shows regarding Bill Hicks. Three standups and one posthumous documentary.

Youtube has a number of videos too, including a good portion of the posthumous documentary, and the 2009 Late Show With David Letterman with Bill Hicks' mother. The Late Show decided to censor Hicks' October 1993 appearance.

The following February, Hicks died of pancreatic cancer in his early 30's. Letterman had his mother on in 2009, regretted the censorship and the additional pain it caused in Hicks' last months, then aired the censored performance. Letterman had had Hicks on a dozen times, on his previous 12:30am NBC show.

(Aside: I also recall Letterman had an episode at 12:30am in the 1980s where, during the course of the hour, the broadcast rotated once around the center of the screen. i.e. at 1:00am the show was upside down. An ongoing theme originally was the absurdity of television. There were many ways the show was "toned down" for the 11:30pm slot.)

There are a handful of social critics/satirists/comedians I continue to rate high my the list:

I'd have to put the Pythons on the list too, from my early teens and their series showing up on PBS, waiting each week for the next one, trying to memorize as much as possible in the half-hour. I didn't really recognize the Pythons or Carlin as social critics at the time. And Andy Kaufman, in his own way. More recently, Bill Maher and probably Eddie Izzard.

Hicks and I were born the same year. I wonder where he'd have gone over the last 17 years. He was pretty far out on the edge back then, and he didn't seem to hold anything back.

"It's just a ride... a choice right now, between fear and love." -Bill Hicks

Common Lisp libraries and Quicklisp

I made a modest donation to quicklisp, a very handy hosted-library system for common lisp. (Think of ruby gems and clojure's clojars) Quicklisp is fairly new, but already worth using at very low effort.

One thing that strikes me about common lisp libraries, beyond quicklisp per se, is the number of libraries available. I've been away from common lisp for all intents and purposes since 1989. The total number of libraries, and the number of library alternatives in any one feature area, are nowhere near those for the currently popular languages like java, ruby, or python. However I am impressed at the ease I've had finding what I am looking for, and then installing and using these libraries with ease.

I can simply say my recently renewed engagement with common lisp has been more than satisfactory on this front, and others I'll write about later.

Thursday, March 31, 2011

Richard Stallman at Portland State - April 7

Richard Stallman will be speaking at Portland State University next Thursday (April 7th) at 7:30.

Details are now on caligator:

http://calagator.org/events/1250460423

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.