Saturday, June 13, 2009

Helicopters and jets

I looked out a window into my back yard where a small helicopter sat. I think it was mine even though the back yard didn't look like the one at our current house or any where I've lived. Another helicopter was flying very low and slightly erratically so as to jostle my craft with its downdraft. Did I mention loud?

‘I should call the FAA,’ I thought, ‘that's harassing flight.’ (I don't guess they have a game warden at the FAA.)

My neighbor had a small jet in his back yard, and the helicopter was also buzzing it. By this time, my wife was watching the scene with me. Next thing I know, the jet was in the air (must’ve come with the vertical takeoff feature) at about the same height as the helicopter.

“I hope it doesn’t hit the house,” Sam said, but as it flew away, we heard a thud from the roof.

We ran out to the back yard. We didn't seem concerned about the helicopter any longer, so maybe it departed too. The yard and house now seemed to be our current house, and we inspected the roof for damage. Because of the recent hail, we have a nice new roof in real life, but in the dream, the roof was old and faded with a comically ghetto patch-job of all kinds of different materials and colors. For example, in one spot there was a tannish piece of linoleum with a faux tile look next to maybe a tar patch.

Thursday, June 11, 2009

A huge step!

As of today, more than a majority of the U.S. House of Representatives have cosponsored the Federal Reserve Transparency Act, but Parker Griffith is still taking a wait-and-see approach. This bill matters to ordinary Americans because all government activities should take place in sunlight. The Fed's easy-money policies are destroying the value of the dollar, which will cause increased prices for everyday goods such as gas and groceries, and destroying families' balance sheets by enticing households to go deeper into debt.

Ron Paul's staff issued a press release heralding the achievement.

Why hasn't the Fed already opened its books for all to see? What do they have to hide?

Wednesday, June 10, 2009

Tuesday, June 09, 2009

But I'm still a spring chicken!

I've been trying to duck it for a couple of years now, but it doesn't look like there's any way around it. I met with a surgeon today, and after reviewing MRI and CT studies, he recommends a laproscopic procedure to clean up bone spurs on my right hip and (we hope) a little tidying of the labrum.

The weirdest thing is I don't know how I did it. A few years ago, we owned a house on an acre-sized lot, and toward the end of push-mowing sessions, that hip seemed to become really tired. The worst incident was after—not during!—a street hockey game where I suddenly couldn't walk and had to use my stick as a cane. You'd think there'd be some nasty collision or fall or something to pin this on, but it really seemed to come out of the blue.

That's been a couple of years ago. Back then, I didn't know I had a likely tear and hoped that I could work through the condition. In my defense, the pain was only in certain positions, and I walk limp-free. Deep squats at the gym hurt, and I hope I didn't do additional damage trying to tough it out.

So I'm facing four to six weeks on crutches and several months of rehab. It's tough getting old.

Monday, June 08, 2009

No legal plunder

In The Law, Frédéric Bastiat argues that a lack of what he derisively refers to as legal plunder is “the principle of justice, peace, order, stability, harmony, and logic.”

Although it was written more than a century and a half ago, Bastiat's frank criticisms have held their edge, but public ministers continue making the same mistakes he so harshly condemns. Consider the section called The Proper Function of the Law:

And, in all sincerity, can anything more than the absence of plunder be required of the law? Can the law — which necessarily requires the use of force — rationally be used for anything except protecting the rights of everyone?
Note that Bastiat uses “rights” in the same sense as Jefferson and Locke did, under which all are equal and must abide within the limits of this universal equality. Some characterize the concept as “negative rights,” e.g. no one may steal from, defraud, or murder others. Columnist Charley Reese put it in downhome terms: “The best way to understand the difference between a true right and a falsely claimed right is that a true right does not compel anyone else to do anything except leave us alone.”

Although not at all glamorous, Bastiat asserts (and later supports) that protecting these rights is a big enough problem for the law. He uses the rhetorical question to assert that broadening the scope of the law beyond this essential function is irrational.

I defy anyone to extend it beyond this purpose without perverting it and, consequently, turning might against right. This is the most fatal and most illogical social perversion that can possibly be imagined.
As experience and history show plainly, placing great power in the hands of a few rulers creates a vicious struggle to control its reigns. The concern moves from seeing that right prevails to becoming the mighty. During the Bush years, Democrats wailed about the abominable “Patriot” act and how it was forced upon them, but they then nominated for vice-president a man who claimed to be its intellectual forebear. Now that they control the White House and the congress, the alleged party of the common man has failed through inaction as terribly as the alleged party of small government that levied this surveillance-state measure.
It must be admitted that the true solution — so long searched for in the area of social relationships — is contained in these simple words: Law is organized justice.
Although anathema to the wonks and their grand schemes, they need to first master their humble assignment before pursuing more ambitious goals. Bastiat continues concerning justice:
Now this must be said: When justice is organized by law — that is, by force — this excludes the idea of using law (force) to organize any human activity whatever, whether it be labor, charity, agriculture, commerce, industry, education, art, or religion. The organizing by law of any one of these would inevitably destroy the essential organization — justice. For truly, how can we imagine force being used against the liberty of citizens without it also being used against justice, and thus acting against its proper purpose?
Consider the horrid mess of the Wall Street bailouts. Diane Feinstein openly admitted constituents' opposition was better than 9-1, but this “representative” voted for it anyway. The U.S. auto industry is a complete trainwreck, but Washington is forcing Americans to continue propping it up despite years of bailouts in the form of protective tariffs. Californians overwhelmingly rejected proposals for huge tax hikes, and now with the prospect of a federal bailout for Arnold & Co. (rivers of paper money flowing into the Golden State!), the people are likely to be forced to pay up even though the vox populi spoke an unmistakable No!

Unjust measures all! Each one is legal plunder. Carry the economist's old saw “there ain't no such thing as a free lunch” a step further: who must pay, and is it justice or might-cum-right?

Sunday, June 07, 2009

GWT not hitting breakpoints in hosted mode

With Eclipse 3.4.2 (Ganymede), Google Web Toolkit, and JDK 1.6.0_14, the debugger seemed to ignore my breakpoints while running the hosted-mode browser even though the breakpoint indicators had checkmarks while the app was running. I added calls to GWT.log, and the server's log output demonstrated that control was definitely passing through my breakpoints.

Google's Rajeev Dayal confirms the problem, and Eclipse has a ticket associated with this issue.

One workaround is falling back to JDK 1.6.0_13. If you don't have it yet, download it from Sun, and tell Eclipse about it:

  1. In Eclipse select Window > Preferences.
  2. In the Preferences dialog, select Java > Installed JREs.
  3. In the Installed JREs panel, select the Add... button.
  4. In the Add JRE dialog, select Standard VM and then the Next button.
  5. Select the Directory... button next to the textbox labeled JRE home and navigate to the JRE bundled with JDK 1.6.0_13 (e.g., C:\Program Files\Java\jdk1.6.0_13\jre). This should add several JARs to the list of JRE system libraries.
  6. Select the Finish button.
  7. Back in the Installed JREs panel, check the JRE for update 13, and then click
Set breakpoints, launch the debugger, and your application should now be stopping when control reaches the specified lines of code!

UPDATE: early-access release 6u18 is reported to fix this problem.

Saturday, June 06, 2009

Quidquid latine dictum sit, altum videtur

Sally suggested the title quote has a dynamic equivalent in C “and could be even more obfuscated!”

What do you think?

#include <stdio.h>
char s[]=" iptanohs iosonwa' nltnsud \
rfud";int i=sizeof s;void p(int n){n<i
?p((n<<1)+1),putchar(*(s+n)),p((n+1)
<<1):3;}int main(){p(0);putchar('\n');}

Loading object files into ghci

On Haskell-Cafe, Murray asked about loading objects associated with FFI imports in ghci.

FFI is Haskell's Foreign Function Interface and allows interoperability with other languages, e.g., calling into a C library from Haskell or using your Haskell module from a C program. For more examples, see the FFI cookbook.

GHC's interactive environment, invoked with ghci, evaluates Haskell code in a REPL, loads and runs compiled modules, and provides familiar debugger functionality such as stepping, tracing, and catching exceptions.

Consider the following simple Haskell program that comprises two modules: Even though our program is split into multiple modules, we need point ghci at the main module, and it will follow the other dependencies:

$ ghci hello.hs 
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 2] Compiling Message          ( Message.hs, interpreted )
[2 of 2] Compiling Main             ( hello.hs, interpreted )
Ok, modules loaded: Main, Message.
*Main> main
Hello, world!
(If you're invoking ghci from Cygwin, you'll want to use ghcii.sh.)

With FFI, you have to hold ghci's hand a little. Consider the following shell script: The environment variable PREFIX is the path to the parent of the lib directory where your library lives. In my case, I ran ./configure --prefix=$PREFIX to ultimately install mylib in a non-standard location.

We might look for a directory named dist if building with Cabal.

The FFI gateway between my Haskell code and my C library is in a file named mylib.hs and compiles to mylib.o, whose path ghci needs to know in order to load all dependencies.

Finally, we invoke ghci. This particular program used hxt, the Haskell XML Toolbox, and mylib links against HDF5, the expat XML parser, and the single-precision FFTW.

For projects built with Cabal, the build system already knows all this information. With cabal-install, it's already possible to configure, build, test, and install Haskell packages. It'd be sweet to be able to easily load complex packages in ghci instead of having to resort to such hackery!

Friday, June 05, 2009

Waiting for Go-done

A coworker called this morning wanting to know how to get a list of files that do not contain the text 'Program complete' on any line. They run jobs in big batches, and each process writes its output to a separate file. The running times vary, and they wanted an easy way to see at a glance which processes are still running.

Running grep -v will print all lines that don't match the given pattern, but that doesn't help in this case because we want to treat the output files as though each contained a single line.

With the -c option, grep outputs the number of lines that matched. Say we have outputs named output1 through output4, and the odd-numbered jobs are finished. This would give us

$ grep -c 'Program complete' output*
output1:1
output2:0
output3:1
output4:0
The pattern requires quotes because it contains a space. Without the quotes, grep would search for Program in files named complete, output1, and so on.

The outputs for the processes still running are the ones containing zero matches, so let's look for those:

$ grep -c 'Program complete' output* | grep ':0$'
output2:0
output4:0
Remember that a dollar sign in a regular expression anchors the match to the end.

Quick cleanup with sed gives us the names of the outputs (backslash is the shell's line-continuation marker that lets us split long lines):

$ grep -c 'Program complete' output* | \
  grep ':0$' | \
  sed -e 's/:0$//'
output2
output4

UPDATE: Turns out there's a much easier way to do it. GNU grep has a --files-without-match option (aka -L), so the command is the simple

$ grep -L 'Program complete' output*
output2
output4

Thursday, June 04, 2009

Dear Congressman Griffith

Before entering office, you gave your solemn word to support the U.S. constitution. Article I, Section 8 of that instrument invests in the Congress oversight of the currency of the United States: “The Congress shall have power to … coin money, regulate the value thereof, and of foreign coin …”

As an aside, the English verb coin has a couple of meanings. One is to stamp metal with guarantees of weight and fineness. The other is to invent out of thin air, as in “coin a phrase.” The delegates in Philadelphia clearly intended the first sense, but others have substituted the latter via stealthy amendments.

I write to urge you to join with 186 (as of this writing) of your colleagues in the people's House and cosponsor HR 1207, the Federal Reserve Transparency Act.

In earlier correspondence, you passed the buck to the Financial Services Committee, writing that you will keep my views in mind "should this legislation reach the House floor for a vote." More than forty percent of your fellows have forsaken the slick politician's fence-sitting, non-committal, wait-and-see opportunism in favor of leadership by taking clear stands.

In the same letter, you assured me that you “support the highest level of accountability.” HR 1207's sunshine on the Federal Reserve, a body that acts in your name thanks to the oath of office you took willingly, would create accountability where secrecy and subterfuge have been the standard, and your active support would demonstrate your commitment to open, honest, accountable government.

Sincerely yours,
Greg Bacon

UPDATE: Mr. Griffith has cosponsored HR 1207!

Saturday, May 23, 2009

Saturday, May 16, 2009

Star Trek!

Our kids were at my mother-in-law's getting some grandma time, which meant Mommy and Daddy got to have a date night. I have a pretty cool wife, so she suggested going to see Star Trek!

When I was growing up, my dad and I enjoyed watching TOS and TNG (that's the original series and Star Trek: The Next Generation for those outside the know) together. As I've gotten older, the old episodes that were once so exciting have become bland and sterile. The movie definitely had more edge to it! Maybe it was the corny inflections, but I never pictured Shatner's Jim Kirk ever bailing from classic 'Vette just before it went over a cliff at 80mph.

Watching the backstory develop was fun—a healthy Captain Pike even!—but seeing them all so young gave it a Starship Troopers feel. My wife later remarked that Sulu drawing a sword on the drill platform was very Power Rangers. Any name would have been better than the decidedly lame "Red Matter." Star Trek always was mildly statist in its outlook, and I cringed when law enforcement asked young Jim, "What is your name, citizen?"

I'd read Bo's blog post about continuity errors beforehand, but either he missed something in the movie (which I find hard to believe) or he very subtly avoided giving a spoiler. Rereading... No! I made a bad assumption! He hadn't yet seen the movie at press time!

The movie was conscious of continuity issues and used what should have been a clumsy device to sweep them all under the rug: Nero traveled back in time and thus created a parallel reality with a different history. (Think: git checkout -b.) Having been prepped by Doc Brown's repeated warnings about the dangers of changing the past, it was easy to accept. Now the writers have nearly complete creative freedom with the sequels that are sure to come.

This sleight-of-script has another subtle benefit: audiences now get to appreciate the series from the perspective of Spock, who became a living lexical closure!

A great flick! My wife, who was never any sort of Trekkie, enjoyed it too, and we both look forward to future installments. As the plot was wrapping up, I thought to myself, 'An old friend is back.'

Afterward, we took a short walk for dinner at Red Robin. I've never had bad service there, but they'd definitely kicked it up a notch—and not in the phony, minimum-pieces-of-flair sense: attentive, smiling, friendly, helpful. If you think recessions are all bad news, quit allowing Krugman to fill your mind with junk-economics.

Wednesday, April 29, 2009

Whatever happened to “Question Authority”?

Sometimes a rout is still fun to watch, e.g., Don't Know Much About Capitalism by Tom Woods.
What it all boils down to is this: one side of our political spectrum favors the central planning of Iraq, while the other favors the central planning of Americans. We can only hope for the continued growth of a third side, one that rejects as unworthy of a free people all the superstitious nonsense about the magical powers of our overlords, whether that power is exercised at home or abroad.

Friday, April 24, 2009

Henson's 11

Tuesday, April 14, 2009

Thinking functionally

Carey's been learning functional programming with F#, and as a learning exercise he solved in F# Project Euler's Problem 1.

Consider the meat of a solution in Haskell (with which we'd get the answer via sum $ multiples 1000 [3,5]): Data.List's union function computes the union of two lists, e.g.,

Prelude Data.List> union [1..3] [3..6]
[1,2,3,4,5,6]
The types of expressions convey a lot about what they do, so let's pick apart the above definition:
*Main Data.List> :t foldl union []
foldl union [] :: (Eq a) => [[a]] -> [a]
*Main Data.List> foldl union [] [[1..3],[3..6]]
[1,2,3,4,5,6]
*Main Data.List> foldl union [] [[1..3],[3..6],[1..7]]
[1,2,3,4,5,6,7]
So the fold allows us to compute the union of an arbitrary number of lists. If this still seems puzzling, remember that the sum of a list of numbers is foldl (+) 0. Take a look at the graphic representation of fold to help your intuition.

The dot is function composition—chosen for its similar appearance to ∘ as used in many math texts, e.g., (f ∘ g)(x). Recall from algebra class that you understand composed functions by reading "inside-out."

So we know we're computing a union of lists, and from the problem statement, we want products of 3 and 5. So the rest must be generating those products.

Its name makes takeWhile's value obvious, but consider an example:

Prelude Data.List> takeWhile (<4) [1..10]
[1,2,3]
So that's capping the products at whatever the value of max is, but what about the goofiness inside?
*Main Data.List> :t flip (map . (*)) [1..]
flip (map . (*)) [1..] :: (Num a, Enum a) => a -> [a]
Although it may not be obvious yet, this is generating all multiples of a given n.

With flip, we reverse the operands of a binary function:

*Main Data.List> :t flip
flip :: (a -> b -> c) -> b -> a -> c
But what are we flipping?
*Main Data.List> :t map . (*)
map . (*) :: (Num a) => a -> [a] -> [a]
Point-free style looks unintelligible coming from an imperative background, but you'll see it all over in Haskell code. Someone once quipped that Haskell is to manipulating functions as Perl is to manipulating strings. We might equivalently write the above function as
*Main Data.List> :t \n xs -> map (n*) xs
\n xs -> map (n*) xs :: (Num a) => a -> [a] -> [a]
Note that backslash is lambda, i.e., the function above takes two arguments with its value being xs scaled by n.

This particular definition has issues. We have to build in the upper-bounding machinery because the function isn't lazy. Consider:

*Main Data.List> take 10 $ multiples 1000 [3,5]
[3,6,9,12,15,18,21,24,27,30]
Notice the absence of multiples of 5. They don't come until much later:
*Main Data.List> elemIndex 10 $ multiples 1000 [3,5]
Just 334
Also, union is overkill because we can make use of our knowledge that the multiples will emerge in increasing order: Notice that we no longer have to force an upper bound, and the merged result is nicer:
*Main> take 10 $ multiples [3,5]
[3,5,6,9,10,12,15,18,20,21]

Friday, April 10, 2009

Vanity search

At work, we're evaluating Safari Books Online. I knew they offered more than only O'Reilly titles, so I hoped to find Scott Chacon's Git Internals. No dice.

Maybe in need of a pick-me-up after such a harsh letdown, I searched for my own name. In the results were books that I tech-edited (Perl Developer's Dictionary and SAMS Teach Yourself Perl in 24 Hours), O'Reilly books that have my work, and a few where I'm mentioned in the acknowledgements—Real World Haskell being of recent note.

I was surprised to see a hit in Perl Debugged by Peter Scott and Ed Wright. In Section 3.5, the authors gave a list of people whose code readers ought to emulate, e.g., Larry Wall, Gisle Aas (author of LWP), Tom Christiansen, Nat Torkington, Mark Jason Dominus (author of Higher-Order Perl), Chip Salzenberg, Gurusamy Sarathy, and—both last and least—your humble host!

Tuesday, March 31, 2009

Practice

My wife and I are expecting our third child around the end of September. Odd thing about pregnancy: mommy urinates about fifty-seven jillion times a day.

I didn't sleep well tonight—despite having the kids and the dog in bed by 9:15! I woke up after midnight for no particular reason, and then I woke up a couple of hours later when Sam got up to go the bathroom. Going back to sleep again was not an option—unlike Sam whose breathing had already returned to deep and rhythmic—because my brain was in high gear thinking about technical issues at work, side projects, et alia.

Among the others was an untestable hypothesis: maybe having to wee in the wee hours is gentle preparation for the grueling six-week hazing period that is caring for a newborn.

Saturday, March 28, 2009

Metadream!

Sam and I were walking around in a dark, twisty hall. I had a flashlight but was having trouble keeping up with her. When I caught up (seems as though we were in an elevator), she told me she'd been evading me and planning to leave me in this place where no one would find me.

Such disturbing dream-moments jolt me awake. I sat up in bed, and Sam was sitting there with the lamp on. She asked what was wrong, and I told her about the dream. I don't remember going back to sleep.

I woke up this morning and realized I must have dreamed that I was dreaming.

Saturday, March 21, 2009

Digest tag population

In comp.lang.lisp, Ken Tilton relayed a fun exercise involving a two-tiered list of pet populations, selections, and an unusual sort order. He proposed it as a test of language mastery because of his requirement to write "in one go" a single-function solution.

This style of development would be highly unusual with Lisp. Having the whole language available at an interactive read-eval-print loop promotes an incremental, bottom-up approach. As Paul Graham explains, bottom-up design in Lisp is more than building up a library: experienced programmers modify the language itself to make expressing the problem more straightforward.

I wrote a solution in Haskell: Aspects need improvement. The name of the type-synonym PetTags is plural, which is often better expressed as a list type, e.g., [PetTag]. The sort comparison functions (used on lines 39 and 40) are inconsistent in expression. The definition feels clunky and verbose.

In comp.lang.haskell, Florian Kreidler made my code much more elegant:

A more natural Haskell development style would be writing a function, checking it for correctness, and repeating in tiny increments. In the code below, I first wrote flatten, then I wrote select to extract the desired animals, followed by largest to extract the top n by population, and finally I wove them together to create digestTagPopulation.

(Github has a feature request for embedding particular revisions of gists. That would have come in handy in this post.)