Monthly Archives: May 2013

cl-interpol and parenscript

Cl-interpol adds Perl style interpolated strings to Common Lisp. For example:


#?"The result is ${(let ((y 2)) (+ x y))}"
-->
"The result is 42"

Cl-interpol works by defining a reader macro, i.e. #?”…”. For personal reasons I don’t like reader macros so I wrote a quick macro to avoid them.


(defun interp% (str)
  "Avoid the need to use a unique read table."
  (assert (stringp str))
  (with-input-from-string (s str)
    (cl-interpol::interpol-reader s #\? nil)))

(defmacro interpolate (str)
  (interp% str))

Which lets you write:


 (interpolate "{This string appeared in package: ${(package-name *package*)}.}")

Like any self respecting Lisp code cl-interpol avoids interpreting the string at runtime, instead it converts the interpolated string into code. For example that last example expands into:


(with-output-to-string (#:g13131)
  (write-string "This string appeared in package: " #:g13131)
  (princ (progn (package-name *package*)) #:g13131)
  (write-string "." #:g13131))

I started using cl-interpol because somebody suggested it as yet another way to generate HTML. The Lisp community as a few templating languages for this kind of thing.  Who doesn’t?  The more popular of these have mimics in Parenscript.

Parenscript, you will recall, is a thin gloss over Javascript that enables you to write your Javascript using s-expressions which are then converted into Javascript before delivery to the browser.

So I wanted that for cl-interpol as well. So I wrote something that translates the expanded code into parenscript.

As in the example above the output of cl-interpol’s expansion is always a with-output-to-string form, so my hack consists of a parenscript macro for with-output-to-string which then walks the enclosing form converting it into parenscript and then into javascript. For example:

This parenscript:


(let ((x 40)) (interpolate "{How about ${(+ x 2)}.}")))

becomes this javascript:


(function () {
    var x = 40;
    return ['How about ', String(x + 2), '.'].join('');
})();

Cl-interpol has lots of features, and I certainly do not handle things it can do. I’ve only covered cases as I need them. But I’ve found it useful.

Tax the Rich

Why have the top few percent have taken over such a large part of the economy?

TaxTheRich

 

That chart (source) shows that lowering their taxes plays a very large part in the story.

Is this due to economic fundamentals (aka: globalization, computers, the rise of winner take all business models), or a simple political victory by agents of high income individuals?

Monocarpic

Monocarpic plants set seed only once and then die.  Bamboo is of this kind, but they have very long lives.  We have a lovely clumping bamboo (Fargesia), i.e. it’s not invasive.  It currently has has an abundant crop of seed.  So this is the end.   Or is it?  I think it’s over.

The cultivar we have is Fargesia nitida, which features a pretty dark purple cane.  It was brought out of China by a Russian collector in the 1880s, and presumably all the plants like ours have been cloned from that one.  They are all setting seed these days, that started a few years ago.   It would seem that the setting of seeds in the Bamboo is a somewhat synchronized event, worldwide.  You can already buy new plants grown from the seeds; though only time will tell exactly how those will behave.

That this only happens every 100+ years makes me curious if it would be possible to brew a craft beer from the abundant grain harvest.

Fargesia

Cicadas

EP-130509471 (1) (1)

See More

The New Yorker has a short essay about long reproductive cycle of the Cicadas.  Cicadas emerge every 13, or 17 years; this year’s appear every 17 part of the largest “brood.”  13 and 17 are prime numbers.  The theory for why that is is that this helps them remain out of synch with the reproductive cycles of their predators.

This all reminded me of the mast years.  You’ll recall that mast years are apparently random events were in a given species of tree across a region will produce a vast number of seeds.  Animals that eat those seeds are overwhelmed so some of the seeds survive.  But also the animals suffer a population bubble, and the the following year they starve.  There is an amazing story about the ripple effects of a mast year in Bamboo.  In that story the rat population exploded, and the next year the rats moved onto eating people’s grain stores; which lead to a revolution.

Which got me wondering what are the ripple effects around the Circada’s emergence.   This essay provides a bit of of that.   The Circada laval eat tree roots – trees have very long reproduction cycles – and you can see the signature of the prime number cycles in the tree rings. Moles thrive in the year before the emergence as they feast on the soon to emerge population.  Presumably next year will be a lousy time to be a mole.

That article also talks about wasps and bacteria.   Settling into a reproductive cycle based on a prime number is only gone to help you avoid predators who’s reproductive cycles are multiples of years.   Moles, rats, and wasps for example.  But it’s no help against the bacteria.  They can ramp up their population fast.   Which leads to a curiosity that older trees have a resident population of bacteria that loves to eat Circada; and the Circada tend to emerge around younger trees.

Meanwhile there is a cool example of crowd sourced science over at MagiCicada.org, where you can see where they are emerging.  See also www.cicadamania.com.  Sadly they aren’t common here in Boston.

More widgets in plot-window.

Here’s another video showing a bit more progress on my hack that allows you to use a browser as a place to display output from your Common Lisp REPL.  I’ve been playing with various javascript widgets.  Here the demo routine shows:

  1. Using JQuery to animate the color of a small rectangle.
  2. A rich WYSIWYG text editor.  This one’s called nicedit.   There are dozens of these.
  3. Mapping via mapstraction, which provides a provider independent mapping widget, in this case I’m using open street maps as a provider.
  4. A tool that does syntax highlighting, i.e. it displays source code with pretty colors.

The initial plot is unchanged from my earlier posting.  You might want to watch this full screen…

Getting these to work isn’t terribly hard, but it’s slightly harder than I’d expected since most of them don’t expect to be loaded dynamically as I’m doing here.

The code running in this demo is in the dev branch over at github, but there is an odd bug I haven’t tracked down yet. Pretty soon I’ll need to change the name 🙂

Reverse Archimedes Screw Turbine

My home is a short walk from Mill St, where the first falling water powered mill was built by the colonists.   That stream had a number of mills along.  But, after the 2nd world war when housing covered the surrounding hills.  Removing the trees, adding the roads and storm drains sucked the water out of the ground quickly after storms.  The water in the stream become less dependable the mills closed.

All of New England was once home to mill towns.  Each was situated along a river where falling water could be tapped to power the mill.  Power rather than labor, markets, or supplies defined these businesses. This model imploded when coal became a preferable source of energy.  When you drive thru these old mill towns you can see lovely homes and mills that are now quite pitiful.

This is an American pattern.  If the business models shift we just abandon the cities that fit that model   We leave them to the poor.  The coal based cities need flat water to get the coal and they had better labor and access to supplies and markets.  These were flat water cities.  Later when coal was replaced by electricity, and cars replaced to walking, and phones and procedures replaced hands on management abandoned flat water cities.

Anyhow, there are lots and lots of little mill ponds and dams all over New England.  Sooner or later these dams will fail, but in the meantime I’ve often wondered why we can’t convert them to micro-hydro generation.  Is power too cheap to make it worth the bother?  Are the coordination costs or the regulatory barriers to difficult.  Maybe the engineering doesn’t work.

This chart shows what kind of tech ou should use for various hydro scenarios.

Tubine-operating-regions2-300x279

 

Most of New England’s old mills had water wheels; and the water didn’t fall very far.  How far the water falls is called “head”, and that’s the Y axis on that chart.  So from this chart we learn that we want to look into something called “Archimedes.”  That turns out to mean “Archimedes screw,” or actually something called a “reverse archimedes screw turbine” … though calling it a turbine is pretty silly.screw

Apparently these are extremely rare, though their are some in the UK, and there is somebody working on it in Canada.  This is a nice video of one running, and here is a nice animated version.  I have no idea if these are a good or a bad idea.

This chart, reportedly, shows feasiblity.  They still need a lot of water.  Which tends to suggest why this paper is so pessimistic.  The entire cost/benefit of the 19th century New England mills lived it would appear in a very different world.

I wonder if these would be practical for energy storage as well.  All the good hydro-storage sites are taken, but if they don’t need as much head then, presumably, other venues would become viable.

Novare Res

Portland Maine is very lucky, they have an amazing bar!  Affordable too!IMAG0432Portland’s harbor is protected by a number of extremely cute little islands.  These can be reached by ferry.  Some of them have little newspapers full of articles about the residents.  For example I read an article once about the man who brings the interlibrary loan books.

It was in one of these I first read about this bar.  It seems that they have a room where you can store your chalice, but first you must earn your chalice.  The article told the story of a resident who had recently obtained that right.  Each day for near on a year he had left work and before heading on down to the ferry and home he had stopped in at the bar to ordering another kind of beer until he had ticked off a sufficiently long list.

That seemed like a worthy achievement and a very romantic lifestyle.

I had a Jandrain-Jandrenouille IV Saison, lucky me!

 

Plot-Window

I’ve been playing with Parenscript and Websockets.  I’ve made a small useful thing.  Plot-window can be used to plot data from your Common Lisp repl.  It displays the plot into a web page; you leave this web page up as you work, the plot function revises the web page on demand.

Here’s a little screen cast. That shows how to clone it from github, load it up, start a little embedded webserver, open the display page in the browser, and then finally we make a makes a few plots from the REPL.

The actual charts are rendered by Flot, one of many Javascript charting libraries.  So you can actually make many many different kinds of charts.  (FYI Liam Healy has a posting about a more traditional approach to Lisp charting.)

Finally, this short video is a preview of how this might be extended to use a web browser as a generalized display for your lisp process, in this case a Parenscript form is evaluated in emacs which builds and animates a page (using D3JS and SVG).

Metering, discriminatory pricing, subscriptions … Adobe.

Pricing is a mess.  On the one hand you can argue that things should cost exactly what they cost to produce (including, of course, a pleasant lifestyle for their producers).  On the other hand you can argue that they should cost exactly whatever value their users extract from the product. Surplus is the term of art.  If you charge less than the value extracted the consumer is left to capture the surplus value.

More than a decade ago I had a bit of fun at the expense of my employeer arguing that we should switch all our pricing to subscription, just as Adobe has just recently decided to.  My suggestion was greeted with an abundance eye rolling and head shaking.

Leaving surplus value on the table can be very risky for the producer.  It’s not just about how pleasant a lifestyle he get’s (aka greed).  Businesses are multi-round games; what you can invest in the next round of the game depends on how much of the surplus value you capture v.s. your competitors.   But also businesses with large market share and large volumes gain scale advantages that drive down costs, establish standards, and generally create positive feedback loops.  (That leads to the perverse tendency for the largest vendor to be the best and the cheapest.)  Which brings us to discriminatory pricing, aka value pricing.

The demand side network effects depend on the scale of your installed base.  Discounting lets you reach users that you wouldn’t otherwise.  If you can segment your market then you can enlarge it.  There is a standard text book illustration for this.

priceing

That chart shows the number of buyers your product will have if you charge various prices, or looking at it another way it’s showing you how much value users think they will get from your product.  If you’d like a lot of users you should charge the green price.  Your total revenue is, of course, the volume of the rectangle.  Why not both?  Why stop there?   As a vendor, what you’d love charge everybody exactly what they are willing to pay.  You could have both the maximum number of users and all the volume (revenue) under that curve.

Subscription pricing gives you a tool, because it lets’ you meter usage, that can stand in as a proxy for the value the users are getting from the product.

I was surprised by Adobe’s subscription pricing, not because it’s expensive and draconian.  No, I was surprised because it appears to have no metering.  My insta-theory for why?  Well I think what we are seeing at this stage is the classic: e.g. “list price.”  That they will start offering various discounted variations on the service.  It would be odd if they don’t.  Because, otherwise, they are leaving two things on the table.  They are shunning a huge pool of users, missing out on all the demand side network effects they create, and encouraging competitors to fill into that abandoned market segment.  And, they are leaving money on the table.

I’ve no idea what they will meter, but I’d be surprised if they don’t.

 

Frightening the Baby Boomers

This report has an interesting detail.  It mentions in passing that men between 55-65 continue to participate in the labor force at roughly pre-recession levels.  All other groups have sharply reduced levels participation rates.   Increased economic uncertainty has scared them into holding onto their jobs.  They did not to retire.