Quicklisp new packages, July 2013

bt-semaphore -- MIT
  A simple semaphore class for bordeaux-threads inspired by SBCL's semaphore.
  author: Ralph Möritz
  git: https://github.com/ralph-moeritz/bt-semaphore
  more: https://github.com/ralph-moeritz/bt-semaphore#readme

cl-dsl -- GPL
  Easily define domain specific languages
  author: Alexander Popolitov
  git: git://github.com/mabragor/cl-dsl.git
  more: https://github.com/mabragor/cl-dsl#readme

cl-glfw3 -- BSD-2
  Bindings for GLFW 3.x
  author: Alex Charlton
  git: https://github.com/AlexCharlton/cl-glfw3.git
  more: https://github.com/AlexCharlton/cl-glfw3#readme

cl-hctsmsl -- GPL v3
  Library to generate human-readable HTML and CSS forms.
  author: Mark Fedurin
  git: https://github.com/HiTECNOLOGYs/CL-HCTSMSL.git
  more: https://github.com/HiTECNOLOGYs/CL-HCTSMSL#readme

cl-indeterminism -- GPL
  Codewalk the form and find variables and functions that are undefined.
  author: Alexander Popolitov
  git: git://github.com/mabragor/cl-indeterminism.git
  more: https://github.com/mabragor/cl-indeterminism#readme

consix -- BSD
  Lispy Qix-like game in 7 days
  author: death
  git: git://github.com/death/consix.git
  more: https://github.com/death/consix#readme

fs-watcher -- MIT License
  Filesystem watcher for changes
  author: Florian Margaine
  git: https://github.com/Ralt/fs-watcher.git
  more: https://github.com/Ralt/fs-watcher#readme

lquery -- Artistic
  A library to allow jQuery-like HTML/DOM manipulation.
  author: Nicolas Hafner
  git: git://git.tymoon.eu/lquery.git
  more: http://shinmera.tymoon.eu/public/lquery-about.html

quicksearch -- MIT License
  Quicksearch searches CL library, then outputs results at REPL.
  author: Takaya OCHIAI
  git: git://github.com/tkych/quicksearch.git
  more: https://github.com/tkych/quicksearch#readme

quickutil -- BSD 3-clause
  Client for Quickutils, a new way to think about utilities.
  git: https://github.com/tarballs-are-good/quickutil.git
  more: https://github.com/tarballs-are-good/quickutil#readme

towers -- Public Domain
  Silly geodefense clone wannabe
  author: death
  git: git://github.com/death/towers.git
  more: https://github.com/death/towers#readme

weblocks-tree-widget -- LLGPL
  A tree widget for weblocks
  author: Olexiy Zamkoviy
  git: git://github.com/html/weblocks-tree-widget.git
  more: https://github.com/html/weblocks-tree-widget#readme

San Francisco, Renegade, and Chew your Food

Mimi and I will be in San Francisco tomorrow evening, leaving next Tuesday morning.  Mimi is exhibiting at the amazing Renegade crafts fair.  It’s in the Marina district at Fort Mason on one of the piers.  Last year there was also an wonderful farmer’s market on Saturday morning.  And, I gather, the America’s Cup will is taking place in the water at the end of the pier.  Last year was amazing.   It should be fun.

In the meantime slow down and be sure to chew your food:

foodfat

 

That’s from this old article in the New York Times: Obesity and the Fastness of Food.

My 1st Amazon Order

I just had a 3TB disk drive fail, and so was checking the warranty.  Happy news, it’s covered.  But in the meantime I can see my first Amazon order, Oct 1996.

amazon_my_1st_orderI know I ordered that shortly after I wrote my first web server.   God that was fun.  But it was during that fun I got my frightening case of RSI.  And, while that’s much much better now I still can’t code as the speed I could back then.

So then I decided I should learn about business, i.e. MBA stuff, and that when added to what I learned work on on my web server lead to a very calculated decision to get involved with Apache.  That was fascinating.

 

Open Reader API

I use Vienna as my RSS feed reading.  The new beta release is interesting.  A while back Vienna added support to pull your feeds from Google Reader.  I never used that, i pull each feed directly from the source.  I didn’t use it for three reasons: 1) while I read blogs on multiple devices I partitioned the blogs per-device; 2) I never got around to it; and 3) I don’t really like the idea of an intermediary knowing all the blogs I read.

The new release has support for pulling feeds from other sources.  And I’m delighted to see that there is some hope that we will see an open standard emerge for the aggregation service’s API; along with open implementations of that.

In turn this would help to allow more privacy around the aggregation service.  That’s a hard problem, but I have a sketch of a possible solution.

emacs w3m about pages

If you use w3m within emacs you might be interested to know you can do this:

(defun w3m-about-foobar (&rest args)
  "Hang a emacs generated page on this url: about://foobar/"
  (insert
    (format "<p>This is so exciting, you have %d buffers!</p>"
            (length (buffer-list))))
  (insert "<img src=\"http://ergoemacs.org/emacs/i/emacs_learning_curves.png\"/>")
  "text/html")

Which means you can build entire pseudo web sites that are local to your emacs :).

I got to wondering about how I might do this because I use w3m to view Lisp documentation[1], and I have this little slime contribution (slime-documentation-search.el) that adds an easy way to search quickdocs.org.  As you can see if you look there are at least four alternatives to quickdocs.org; and I’ve been wondering if I could puzzle out a way to create little website that would let you browse between them.

The trick above looks like it could help, but the obvious approach doesn’t work because w3m doesn’t support iframes.  Exercise for the reader, I guess.

Plot Window #3

Another batch of improvements in plot-window.  Plot-window is not, as yet, intended for other people’s use.    It provides a bridge between Lisp and assorted Javascript widgets.  The original idea was to allow a web page to be used as a display from the Lisp REPL.  So, for example, to enable you to plot data using a Javascript plotting widget.

Most of the changes are internal.  For example I’m toying with a way to manage Parenscript modules (example module here).  I’m also using the LOG4CL, which I highly recommend.

All the widgets have now been factored out into individual examples.  Previously using a widget rewrote the display page entirely.  Now they are inserted at an insertion point.  Here’s a little screen capture…

 

Peter Sandman: Risk Communications

My sister (thanks RH) pointed me to an interview of Peter Sandman on NPR.  Peter says his gig is “Risk Communications.”  Which, to hear him tell it, is the art of managing outrage: turning it up, turning it down, and riding the wave – as appropriate.   He has a spectacularly rich and interesting website.  Many years ago he wrote a book “Responding to Community Outrage: Strategies for Effective Risk Communication” which you can pick up on Amazon for only two hundred and fifty bucks; or you can now get it for free on his site(pdf).

outrageWhen explaining what he does Peter most often begins with a curious fact.  People’s outrage about a given hazard is largely independent of the actual danger, only a 4% correlation.  I like to reframe a statistic like that.  It’s not about “people,” it’s about you.  Unless you’re better than most of us then you are aroused about the wrong things, but yeah – I’m sure you are better.

He calls this outrage, not arousal; and he has a list (pdf) of how to fuel the flames:

  • Controlled by Individual/Others
  • Source: Trustworthy/not
  • Process: Responsive/not
  • Voluntary/Coerced
  • Fair/Not
  • Not/Morally-salient
  • Natural/Industrial
  • Familiar/Exotic
  • Not/Memorable
  • Not/Dreaded
  • Knowable/not

You can feed or starve these fires.  Turn it down: “Outrage Management.” Turn it up “Precaution Advocacy.”

He argues, interestingly, that getting people to take an issue seriously usually requires lowering the level of outrage.  Lots of people find that counter intuitive.  I agree that managing the arousal is usually the first step in getting a group to solve a problem.

There is an alternate framing of that: conservation of outrage.  If you accept that people have a natural level of outrage, i.e. it’s part of their personality, then you can begin to see the problem in terms of transferring outrage from one worry account to another.

Recently, This American Life did a piece on climate change.  In one segment they visited Colorado.  The state was on fire.  The weather was bizarre   The crops were dying.  But nobody would even say the word climate change.  At one point the reporter utters the unspeakable and the farmer she is talking to goes ballistic.  But not really about climate change, rather his outrage is about environmentalists, leftists, etc.   Dan Savage mentioned this episode as reminding him how gay men would deny AIDS in the early years.  That in turn reminds me of the vigorous emotional lumber that resists addressing other issues – austerity, income distribution, health care, public transit, etc. etc.  Do people resist these because their outrage is elsewhere?

Experts in a domain to often work hard and carefully to read a conclusions about what needs to be done.   Usually they need to convince some other group to act.  Whenever they, or you, start to engage with that other group the exact same thing happens.  You say “X! and they say Z!;” and you reaction is that “WTF?  X has nothing to do with Z; … well very very little to do with it.”

There are plenty of words for alll this:  arousal, outrage, motivation, “what are those idiots thinking!”

The ideas in Peter’s work are scale free; they are useful from problems big and small.

Northwestern United States – Earthquake

Once upon a time geologists believed that, unlike California, the Pacific Northwest was pretty stable.  Earthquakes?  Not to worry.  Other than a few Native American folktales, it’s been quiet since settlers showed up.

But, I’m reading “Cascadia’s Fault: The Earthquake and Tsunami That Could Devastate North America” (library, amazonblog) which explains how they came to change their minds about that.

Now they think that something pretty horrific is in the cards.  If you can sublimate what that means it’s a very cool detective story.  I particularly like that they know exactly when the last monster quake occurred: 9pm on January 27th, 1700.  They know this because of extensive written records of the Tsunami it caused hitting the coast of Japan.  They know this because they found trees still standing in salt marshes, killed when the ground sank and the saltwater killed them.  They pulled the well preserved roots from under the mud and counted the rings.

They have core samples of the off shore mudslides that the monster quakes have created.  Using techniques from the oil industry they can match up the wiggles in the core samples taken from these samples they can puzzle out a history for these monster quakes that goes back a long way.  They can draw a sobering timeline (click to enlarge).

CascadiaTimeline

 

They know the mountain tops are slowly squeezing together.  These days they can watch the mountains of the entire region move, every day.  They can sum up how much stress has accumulated.  Around 60 feet of slippage will be unwound by the next quake.  The big ones on that timeline are magnitude 9.  No city with sky scrapers has have ever experienced that.  The 2011 Japanese Tsunami was triggered by a one.

So, the state of Washington has a brochure.   It suggests that most every bridge in the state will collapse.

ps. Mimi and I will be in San Francisco the last weekend of July; for the Renegade Craft fair.

Optima

One project I’ve been doing while unemployeed is to review how the Common Lisp landscape has changed since I was last paying attention. And the big change is the emergance of a rapidly growing pool of libraries (900+) all distributed via Quicklisp.

My current favorite is a library called Optima. Optima adds constructs for doing rich pattern matching. It can match lists, arrays, objects, structs, strings; and if you load fare-quasiquote you can write patterns using backquote.

Let’s build a JavaScript to Parenscript translator. First we can use a Javascript parsing library.

> (ql:quickload '("optima" "fare-quasiquote" "parse-js" "parenscript"))
...
> (defpackage #:js2ps (:use #:cl #:optima #:parenscript #:parse-js))
> (in-package #:js2ps)
> (pprint (parse-js "a[3] += f(x,y)")))
(:toplevel
 ((:stat
   (:assign :+ 
      (:sub (:name "a") (:num 3))
      (:call (:name "f")
       ((:name "x") (:name "y")))))))

Then we can write a recursive function using Optima to translate that into parenscript like so:

(defun js2ps (txt)
  (labels
      ((r (x)
         (match x
           (`(:toplevel ,stms)         `(progn ,@(mapcar #'r stms)))
           (`(:stat ,s)                `(progn ,(r s)))
           (`(:assign :+ ,left ,right) `(incf ,(r left) ,(r right)))
           (`(:call ,func ,args)       `(,(r func) ,@(mapcar #'r args)))
           (`(:name ,name)             (js2ps-name name))
           (`(:num  ,n)                n)
           (`(:sub ,array ,index)      `(aref ,(r array) ,(r index)))
           (eck (error "TBD ~S" eck)))))
    (r (parse-js txt))))

Let’s try it, and then using ps* we can have parenscript translate it back into Javascript.

js2ps> (js2ps "a[3] += f(x,y)")
(progn (progn (incf (aref a 3) (f x y))))
js2ps> (ps* *)
"a[3] += f(x, y);"

You have already noticed that the patterns look just like the code for building the result. Pretty eh?

A complete translator is easy. The fiddly bits arise around handling variable bindings and around what in Parenscript are called @ and chain. There code here that does much of that.

I’ve also used Optima is to scrap web pages. It’s trivial to load and parse an page into an s-expression, just quickload “drakma” and “closure-html”, and then do (parse (http-request url) (closure-html:make-lhtml-builder)). Then let’s say you wanted to know the prices that macbook airs have sold for on ebay.

 (defun snarf-prices (page-sxpr)
  ;; for example: (snarf-prices (fetch-price-page "macbook air 13" 3))
  (labels ((recure (x)
             (match x
               (`(:div ((:class "g-b bidsold") (:itemprop "price"))
                       ,(ppcre "\\$([\\d.]+)" price))
                 (push (parse-number price) result))
               (`(,(satisfies keywordp) _ ,@children)
                (map nil #'recure children)))))
     (recure page-sxpr)
     (nreverse result))))

The second pattern match `(,(satisfies keywordp) _ ,@children) uses two new tricks. The statisfies shows how we can put arbitrary predicates into your patterns, and the _ is a wildcard.

The first pattern shows how to match strings to regular expressions. The pattern (ppcre “\\w*\\$([\\d.]+)” price) would match the string
” $647.10″ and binds price to the string “647.10”.

The code for an earlier version of this page scraping example can be seen here.

One problem with Optima is that it’s a bit addictive. Once you start using it you stop using lots of other techniques. For example I hardly ever use cl-ppcre directly anymore. For example if I want to pluck the host out of some URLs I’ll write: (match url ((ppcre "//([-_.\\w]+)/" host) host)). It also lets me write code in the style of awk or perl, i.e. with a set of pattern matches.

And I should have mentioned, it expands into pretty good raw code. I say pretty good rather than great because it doesn’t currently factor out common subexpressions.

So try it out, you’ll like it.