Category Archives: common-lisp

Running Lispworks from the shell.

Shell script for Mac OS X that launchs Lispworks Personal edition and then uses applescript to initialize it. The initialization then presumably loads swank, so slime can talk to it. This works with the recently release 4.4.5 LispWorks.

I spend an inordinate amount of time working thru an AppleScript error where the line activate application "LispWorks Personal" would fail on one machine but not on another. Finally deleting LispWorks, empting the trash, rebooting the machine, reinstalling LispWorks, and firing it up via the finder before running this script fixed it. I think some sort of directory of known applications was wedged.

#!/bin/sh

# Because we fork, and then wait for the fork to end you can't do all
# this in AppleScript.
# 1. Fork Lispworks.
# 2. Run an applescript to step it thru start-up.
# 3. Finally wait till it exits.

cd ~/w/lispworks

"/Applications/LispWorks Personal 4.4.5/LispWorks Personal.app/Contents/MacOS/lispworks-personal-4-4-5-darwin" &

osascript <<EOS

-- Wait for it.
tell application "System Events"
  repeat until process "lispworks-personal-4-4-5-darwin" exists
    delay 1
  end repeat

  activate application "LispWorks Personal"

  -- Clear splash screen, force feed the init, hide the application.

  tell process "lispworks-personal-4-4-5-darwin"
    repeat until window "LispWorks Personal Edition" exists
      delay 1
    end repeat
    click button "Close" of window "LispWorks Personal Edition"
    tell window "Listener 1"
      keystroke "(load \"~/w/lispworks/init\")"
      keystroke return
    end tell
--    set visible to false
  end tell
end tell

EOS

wait

Brand Religiosity

There a lot of fun “statically improbable phrases” in this paper (sadly hidden behind a garden wall) about religiosity in brand communities. It’s about the Newton community, which like the Lisp community, can be described as “operating in a threatened state.”

Like all communities these brand communities have rituals, including stories. And when the community is threatened then you can look for these kinds of stories: “(1) tails of persecution, (2) tales of faith rewarded, (3) survival tales, (4) tales of miraculous recovery, and (5) tales of resurrection.”

I particularly liked the idea of “highly visible stigma symbol.” The damn back lite apple on my powerbook for example. Until recently I could use the word closure as a stigma symbol but it apparently it’s making a comeback. The stigma symbol attracts persecution. Communities have what salesmen call objection handling techniques for responding to those. In this paper we get the wonderful phrase “taming the facts.”

Of course Brand communities have product at their center, often technological products. Technology is magical. That leads to the wonderful phrase “technopagan magic.” The best heroic fantasy tales deal with persecution with a burst of tecnopagan magic.

But the real reason I needed to write this posting was this marvalous signature line used by somebody in the Newton community:

“Would the last person to leave the platform, please turn off the backlight.”

Displacement and Common Lisp

Displacement is an economic or cultural process where by a community of practice wakes up one morning to discover that the tide of history has left it high and dry. The displaced community is not, necessarily, at fault in these stories. The archetypical example of displacement was the introduction of a new technology into northern england that displaced the tenant farmers from their land holds. In that case the displacement unfolded pretty quickly because their legal claim to their land was based on leases; so when the leases came due and the landlord’s (who wanted to convert to the new paradigm) displaced the residents. The technical innovation that displaced the farmers was a more robust breed of sheep coupled with a business fad for sheep.

In the software industry displacement happens when an existing language community – Cobol, Fortran, whatever – wakes up one morning to discover that the industries current fast growing network effect is taking place outside their community. Some communities manage to catch up by quickly piling on the tools, design patterns, etc. etc. required to play in the new world.

The Common Lisp made one mistake back in the 1980s that helped with it’s displacement. This mistake was around graphic user interfaces. When the Mac came out it redefined how graphic user interface interaction would take place. It set a standard for the interaction. This standard featured the idea of a current selection. First the user would use his mouse to accumulate the selection. He’d select the window/document to work on. He’d adjust the view to bring the thing he wished to modify into view. He’d then select that object. Only then would he browse a selection of commands to affect the object. Who knows if that’s the best design; but it certainly became the standard approach.

Meanwhile over in the older graphic user interface communities the command loop worked quite differently. For example selection was often entangled with mouse location. For example if you moved the mouse over an window or an object the object was automatically selected – but that’s only an example.

In the Common Lisp community a really unbelievably elegant user interface tool kit emerged known as CLIM (or Common Lisp Interface Manager). But this beautiful elegant thing had no concept of “the selection.” As a result it was totally irrelevant to the building of the kinds of user interface that were demanded by those working where the action was. Great ideas displaced by no particular fault of it’s own.

Microsoft had an analogous brush with displacement when the Internet broke out and desk top suddenly became marginalized. Microsoft has, historically, been better at mustering the sense of fear and panic necessary to respond to displacement events. So when it became clear they were at risk they reacted.

The Common Lisp community endures. I still use and prefer it for all kinds of tasks.

But, recently I’ve been concerned by what looks to me like a another displacement threat – character sets.

Emacs is a key complement to the Lisp community; and quite a few others. Emacs has amazing character set support, both the major variants (GNU Emacs, and XEmacs). The support is uniquely powerful. The approach emerged in a branch of emacs known as Mule and more recently has getting folded back into Emacs. All the input output streams can be configured to declare their encoding schemes. The internal strings and buffers are especially clever. The usual trick for systems having to tackle this problem is to normalize all the characters into one standard format, typically unicode. Mule’s approach is different; buffers in a mule enhanced emacs retain their character encoding. Load a file of Big5 characters and point at an arbitrary character in the string and mule emacs knows that’s a big5 character; paste a string of unicode characters into that buffer and now you have a buffer who’s characters are in assorted character set encoding in a way analogous (but with a different implementation) the way that you can have a buffer with characters in assorted fonts. That I find the mule design so cool reminds a bit of how cool I found the CLIM design; but at this point I’m feeling a bit paranoid.

So on the emacs front things are in in pretty good, even very good, shape. It’s all a bit rough around the edges though. The emac communities are still holding mule emacs at arm’s length so you often have to build the mule variant by hand. You often need to get the version of emacs that’s ahead of the stable release curve to capture the features you need. Font support is both amazing and frustrating. If your running under X then you can get a large set of international fonts and after a mess of suffering you can get your GNU emacs or xemacs to use them. One curiosity of the mule buffer design is that a character encoded in one character set may not have a font to render it only because the only font you have installed able to render that cute character happens to be laid out using a different character set. That’s a big pain on the Mac which has beautiful fonts but I can’t see how to get to them from unicode characters sets in emacs.

Over on the Lisp side of things the story is slowly resolving it’s self. There are a _lot_ of really fine commercial and open Common Lisp implementations. Each one has a slightly different story about how and when the unicode problem is getting addressed. The best unicode support in an open implementation happens to be in the slowest implementation. The implementation I’m using today (Steel Bank Common Lisp, or SBCL) has very fresh unicode support.

It’s taken me almost two weeks to get a working tool chain for this stuff. I have tried a lot of combinations and experianced a lot of crashes where both Lisp and Emacs die horrible recursive deaths choking as tried to display or transport characters down pipelines. Currently I’m running the lastest released beta version of XEmacs, build from scratch to get mule support. I’m running that under X on my Mac; so I’m using the open international X fonts. I’m running the bleeding edge versions (CVS Head) of both SBCL and Slime (the emacs< ->lisp interaction mode). [Hint: (setf slime-net-coding-system 'utf-8-unix)]

I’m happy to report that I can now stream unpredictable UTF-8 streams thru reasonably long chains of tools and it all works. Everything in my tool chain except the fonts is beta or bleeding. I’ll be really happy when I’ve got the database linkages working.

If this was 1995 I’d be less concerned about displacement; but it’s 2004. The good news is that the problem is getting solved.

Dump Translation Unit

I was inspired by:

   Reflectance from C/C++ code (pdf)
   Duncan Temple Lang
   Statistics and Data Mining Research,
   Bell Labs, Lucent Technologies January 15, 2003

Fun things based on leveraging the GCC compiler’s willingness to dump what it’s compiling after it’s done the parsing etc. So I wasted a few hours writing this hack.

Common Lisp is fun; for example this code that takes things like this xpath mimic “//function-decl/name/strn” and converts it into this SEXP ((:class tu-classes::tu-function-decl) (:attribute tu-classes::tu-name) (:attribute tu-classes::tu-strn)).


(defun parse-path (path-string)
  (let ((path-from-string
	  (with-perl-style (path-string)
            (sg "//" ")(:class tu-")
	    (sg "/" ") (:attribute tu-")
	    (s "$" ")")
	    (s "^)" "")
	    (s "(.*)" "(1)"))))
    (let ((*package* (find-package "TU-CLASSES")))
      (read-from-string path-from-string))))

Then later i can write things like (do-path (x "//function-decl/name/strn") (print x)) to print the name of the functions declared in what ever GCC was asked to compile.

Some things about Lisp have gotten better since I was last playing with it. For example with-perl-style is a little macro I wrote that depends on CL-PPRE. So now we have a solid regular expression package that’s Lisp native. Installing things extentions is easier too. Installing CL-PPRE? Type: (asdf-install:install ‘CL-PPRE).

Growing Powerlaw Graphs

I believe the earliest paper that outlines the process that gives rise to a power-law distribution is Herb Simon’s paper from the 1950s that explains that the distribution of words found in human language texts (pdf). He explained them by modeling the process of word selection in those texts by proposing that the next word is selected based on the popularity of the previous words that have been attached to the text.

Barbasi and Albert’s revisit this model (pdf) in the context of growing a network. Their model can be illustrated by this simple function that builds a graph. As we will see the resulting graph will exhibit a power-law distribution in the node connection counts.


    (defun make-pgraph (n)
      (loop
        with g = (make-initial-pgraph n)
        finally (return g)
        for i from 1 below n
        as node1 = (find-prefered-node g)
        as node2 = (find-prefered-node g)
        do (add-node g node1 node2)))

This function grows a graph where each node adds two edges to the network. The function proceeds by creating an initial node, who’s two edges are self connected. It then proceeds to add the remaining N-1 nodes with two edges connected to two nodes, node1 and node2. We select which node to connect to via find-prefered-node.

All the debates about what gives rise to power-law distributions arise from arguments about the behavior of the find-prefered-node function. Here’s the one used here. It randomly picks one of the existing edges and then randomly selects the node at one end of that edge or the other.


    (defmethod find-prefered-node ((g pgraph))
      (let ((e (svref (edges g) (random (edge-count g)))))
        (if (eq 0 (random 2))
          (left-node e)
          (right-node e))))

Here is a graph showing the wealth distribution of the nodes in five graphs grown by this code. Wealth is measured by the number of connections a node manages to aggregate.

fewPowerLaw.png

I don’t see much merit in that function that guides the preferential attachment.

More code below the fold.

Continue reading

Worse is Better

Richard Gabriel’s essay Worse is Better is one of the handful of things I strongly advocate any serious designer reading. It’s a bit bitter, since it reflects the hard won discovery that the way he and his community were approaching the systems design problem was fatally flawed. As such it’s an attempt to frame the arguement for why they should move out of their comfort zone and into foreign territory. With minor variations this is a key reason that Common Lisp only captured a niche rather than the world. The lessons in this essay were taken to heart by any number of the refugees that left that world.

I now tell the story he’s telling in very different way.

Systems are valuable because they solve integration problems. They bring stuff together in new ways. Designers need to appreciate that there are two kinds of integration value: inside and outside. The inside connections of a system are what most engineers think of as design. When it’s easy they take modular components and hook them together; when it’s hard they force unwilling bits of technology to cohabitate in a space slightly too small for them.

External integration is what marketing folks tend to claim as their turf. But if you set back and consider the situation engineers to this too. For example when unix was designed to have pipes that made it easy to hook elements together dynamicly and a uniform file system that made it easy to hang devices of all kinds off the same name space as the files the result was a substrate that encouraged complementary connections. All that stuff that plugged into that framework created external connections. When a programming language is designed to be easy to learn your creating affordances for easy connections.

As soon as the system your building has network effects associated with these external connections the designer needs to wake up and embrace that external connections are more important then internal ones. External connections tend to be more durable, external connections are often more scalable, external connections capture early in a market a the seeds of hubs.

Lisp Code Walking

One of the reasons Common Lisp is a marvel is because it allows the programmer to manipulate the program after parsing and before falling into the compiler. This allows the designer to create craft the programming language best suited to his problem domain and then write the program in that language. The program he writes in his custom language is then converted into a program that can be compiled into something with all the efficency of a program written in at a lower semantic level.

This is note is kind of a complementary note to the one about the value of knowing assembler language :-).

The tool provided in the language for this is called a macro. That name tends to mislead programers that are familiar with macros written at the lexical or textual level. Lisp macros get to chew on the whole program, though usually they just chew on sections of the parse tree.

When you start to write really complex lisp macros you need to walk the entire program tree. To make that possible the language, which is huge, has a very small kernel of what are known as “special forms.” By using macros to convert the entire program into these special forms we are able to let any author that comes along latter play with the code, all the way down. Thus for example if you want you could write macros that find all the asignments in a function and keep a journal of them so that the function’s execution can be reversed.

You can read more about this kind of thing in the second chapter of this three chapter paper by Richard C. Walters.

Meanwhile the first chapter is a nice example of the kind of rich package you can build on this foundation. A pretty printer so powerful that I once used it to convert Lisp forms into C code.

More about code walking here.

Old enough for a Real Language

Old fart posting…

Bill Clementson and Dave Roberts point out a thread on comp.lang.lisp that is
unearthing a thought provoking sample of people who only became fans of Lisp late in the life.

I made a commitment to Lisp when I was in my mid-30s. It was quite calculated. I’d written a huge amount of software in various languages by that point; including L* back in the 70s which had similar depth to Lisp. I had spent a few years suffering thru writing a big ugly Ada program and I’d become quite disillusioned with strong typing. It worked but it was so damn hard. Just to debug the damn thing I’d ended up writing a fun system in Prolog. Just to build the system we had writing lots of programs that in turn wrote the program that we would then compile and ship. The build cascades of that systems were neat, wonderfully adhoc. A little sed, a little m4, a little awk, a custom lex/yacc do hicky, etc. etc. Amazingly weird make files.

At about that point Guy Steel’s first version of the Common Lisp manual came out. The most elegantly written language specification I’ve ever read. Just chapter after chapter of language facilities that I’d had to build by hand again and again. All beautifully designed. It was clear that Lisp would just subsume all all the junk I’d had to write both before and after writing my Ada system.

So I went off and got myself a job at an AI company that managed to go down the tubes with great vigor.

But, I got to write some really fun software there. For example I wrote a system that would allow you declare what I called a data-structure-tour. You would sketch how to tour each individual data structure; usually next to it’s declaration. They you could then write statements that said things like “Tour e over X as a window-display doing redraw(e).” Man was that fun.

Lisp Machine Video

Rainer Joswig has released a 44 Meg Quicktime video showing some of the features of the Lisp machine. I found this extremely nostalgic. The Lisp Machines did all this in the middle 80s; and large portions of it in the late 70s.

The announcement in his blog implies that this is one of a series so he may have already said some of the following.

One thing to note is the integration of four interface styles. One style is a classic editor development loop. The second style is a rich graphic user interface; you need to wait till the little demo of the drawing editor to see that kind of UI. The third is an semi-english language like interface; you can see that in some of the commands he types.

The fourth, and this one is waiting for somebody to rediscover it, is that everything that is rendered into the output typescript retains knowledge of what type it is. That allows the mouse to move over the transcripts and everything that was output is “alive.” For example when his mouse moves over a symbol the system knows that it’s a symbol and the menus offered are appropriate for a symbol. This is, no surprisingly, true for small small types and large types. So when his mouse moves over the print out of, say, a system definition the menus then offer up operations like patching that system.

All four UI stand on a single foundation; a bridge between the dynamic type of the objects in the system and various “presentations” of those objects into the UI. Interaction is then intermediated by the nature of those presentations. That allowed you to write commands that would be offered up to the user when a given gesture was made on an object of a given type that appears in a given style of presentation.

You can see some of the notation for that in the simple examples he goes thru. The first few examples differ only in the kind of UI the interaction takes place within.

The demo ends with an example of the integration of source control the mechanisms for patching running systems. These are the kinds of systems that we are now having to rediscover to be able to respond quickly when hackers find security flaws in our running systems.

it

Anaphora, now there’s a word. It’s a grammer term: “The use of a word which refers to, or is a substitute for a group of words.” Pronouns for example. Programming languages spend most of their capital providing anaphoric devices. Local variables, functions, types are all examples of this.

I’ve always had an affection for scripting languages that take this heart. Languages that let you write things like this:

  open(file)
  read_line(that steam)
  match(pattern, that string);
  print the first match;

Expressions like “that stream” which or “that <type-name>” aren’t difficult for a compiler to figure out. An phrases like “the <ordinal> <type-name>” aren’t hard either. It’s a bit hard, but a lot more fun, if you allow the the universe of type-names to be a bit more flexible so that in that example “match” isn’t really a type; it’s a pseudo type naming the return value of the call done to match.

I also love the way this kind of stuff makes some people’s skin crawl while it makes other people grin with glee.

I was reminded of this by a little macro package for Common Lisp that gives the programmer a bit of anaphoric semantics. Instead of writing:

    (if (car x)
        (incf (car x)))

It lets you write

    (sif (car x)
         (incf it))

It’s a nice example of how it is fun to write in Common Lisp where you can invent and explore ideas like this. Note that incf is analagous to prefix ++ operator in C.