Tag Archives: book

For Dummies

Farmville for Dummies Betting on Horse Racing for Dummies

Yes, they’re real books.

Genesis 1 vs Genesis 2

shrubberyGenesis is the first book of the Holy Bible. It is found in every translation of the Old Testament; it is canon in Christianity as well as Judaism. Setting aside external counter arguments (science), let us examine the Scripture itself. Citations are from NIV unless otherwise indicated. The NIV is not God’s literal word, but it is one of the better English translations available. In any case, the structure of Genesis is the same across translations; it would even be scholastically acceptable to use the KJV here.

In Genesis 1, God creates the world:

  1. Heaven and earth (Gen 1:1-2), light, day, and night (Gen 1:3-5)
  2. Sky (Gen 1:6-8)
  3. Land and sea (Gen 1:9-10), plants and trees (Gen 1:11-13)
  4. Sun, moon, and stars (Gen 1:14-19)
  5. Sea creatures and birds (Gen 1:20-23)
  6. Land creatures, both livestock and wild (Gen 1:24-25), then mankind (Gen 1:26-31)

In Genesis 2, God affirms his creation:

Thus the heavens and the earth were completed in all their vast array.

—Gen 2:1

By the seventh day God had finished the work he had been doing; so on the seventh day he rested from all his work. Then God blessed the seventh day and made it holy, because on it he rested from all the work of creating that he had done.

—Gen 2:2-3

After resting for a day, God groggily amends creation:

Now no shrub had yet appeared on the earth and no plant had yet sprung up, for the LORD God had not sent rain on the earth and there was no one to work the ground, but streams came up from the earth and watered the whole surface of the ground. Then the LORD God formed a man from the dust of the ground and breathed into his nostrils the breath of life, and the man became a living being.

—Gen 2:5-7

Was man created before shrubberies or after?

Update: Biblical scholars have arrived at the JPED hypothesis, that the Torah is a compilation of earlier works, known as J, E, P, and D. Much of the earlier material was redacted and transformed before it became the Torah. Thus contradictions were introduced, because different authors supplied different stories.

Review: Heraclitean Pride

book coverMagus Magnus’ Heraclitean Pride is a creative commentary on the recovered fragments of Heraclitus, a Greek philosopher known for an obsession with words (“logos”) and change (“amoibe”).

Magnus offers a refreshingly unique translation of Heraclitus with a variety of strategies for readers to engage the text. Most noticeably, Magnus deliberately articulates his commentary in short, stunted sentences, mimicking the extant Heraclitean quotes. Magnus is extremely playful, weaving philosophical and poetic thought in analytic and conversational rhetoric.

However, the core of Magnus’ commentary is word association, an analytical method more typical of child’s play. Magnus is a passionate lover of Heraclitus, but to some, Heraclitean Pride may read as a mockery of the original sayings. The stop-and-go form was, after all, a by-product of the burning, ripping, and simple loss of Heraclitus’ writings. In playing with text, Magnus invites many outsiders to philosophy, but risks losing fellow Heraclitus lovers, including classic logicians and historians. Heraclitus didn’t write. In. Stilted Greek. Heraclitus wrote in normal, flowing sentences, and what little has survived of his writings should not be toyed with as we see fit. The publisher, Furniture Press Books, may or may not have made a Freudian slip in the book cover of Heraclitean Pride, which reads in the lower-right corner, Magnus Pride.

DRM Strikes Again!

kopimiS. John Ross’ Risus is a really cool role-playing system made by Cumberland Games. They’re cool enough to give away the basic guide for free, and a solo campaign as well (PDF).

Unfortunately, they’re not cool enough to give away “Ring of Thieves” as an unprotected PDF. For the layman, that means PDF software will refuse to copy portions of the document. Modifying metadata isn’t allowed either.

Why is this a problem? Because I like to sort books by last name first on my Kindle. When I put the freely available “Ring of Thieves” on my Kindle, it fails to sort under Ross, John, or even S. As far as Kindle is concerned, the file has no author. Ordinarily, a little tweak by Calibre would fix this problem.

But, the PDF is protected, so no metadata can be edited. I can’t even save to a new PDF and fix that one. I have a couple options:

  • Plead Cumberland Games to provide an unprotected version.
  • Install PDF unlocking software (they’re all crappy shareware).
  • Read the book on something other than my Kindle (why the fuck did I get one then?)
  • Figure out the decryption algorithm, and post it online anonymously.
  • Save to PostScript, then back to PDF.
  • Screencap every single page, then save the images to PDF.
  • Build a time machine and travel to whenever Congress learns that DRM is an aggravating inconvenience for honest users, a mere challenge for hackers.

Update: Someone has posted a Perl crypt script. Very hard to find, that. It does work, but I’m still having trouble editing metadata. Stupid Kindle refuses to sort by PDF author information.

PDFs Suck

A Google Books rendition of Charles Caleb Colton’s “Lacon”:

TEne&E are three difficulties in authorship; to write any thing worth the puhlishing-^to find lionest men to publish it?and to get sensible men to r6adit. Literature has now beconie a game

Apologies to Google and Colton: I doubt I could do any better scraping PDFs for text. ePUBs are better because HTML is better:

  • Always searchable
  • Always reflowable – important for mobile devices
  • Easily transformed into other formats
  • Easier to render
  • Small file size

Reading programming books on the Nook

Programming books are hard enough to read: cryptic jargon, poor phrasing, blatant omission of critical details… the list goes on. But it’s even harder to read technical books on the Nook (or any ereader for that matter), because of some limitations of HTML (ePubs are zipped XHTML files).

HTML was not designed for consideration of really small screens. Coders typically use an 80-character margin for easy viewing on medium and large screens. So when a code snippet is shown on the Web, it also assumes a medium or large screen. Textbooks are also pretty big surfaces for code. That’s why Real World Haskell and Practical Common Lisp don’t chop up their code blocks very much. Both the print versions and the electronic versions rely on a big surface for viewing–about 80 characters or more.

Not surprisingly, when this code is viewed on a Nook, the code is cut off. Here’s an example:


#!/usr/bin/env runhaskell

module Magic where

import Text.Printf

magic :: String
magic = unlines $ map magic
                magicN :: Int -> S
                magicN n
                        | n > 0 && n

main :: IO ()
main = putStr magic

This is not valid Haskell code. It’s not even readable Haskell code. What’s the rest of the n > 0 && n condition? What happens after that condition is met?

The solution is to instruct Nook (and any other HTML viewer) to wrap the code and set it to a reasonable size (10pt or less). Add the following to the ePub’s CSS:

pre {
	font-family: Andale Mono, "Courier New", Courier, monospace;
	font-size: 80%;

	overflow-x: auto;
	white-space: -moz-pre-wrap !important;
	white-space: -pre-wrap;
	white-space: -o-pre-wrap;
	white-space: pre-wrap;
	word-wrap: break-word;

Now the code is readable. Choppy, at least you can see all of it.

#!/usr/bin/env runhaskell

module Magic where

import Text.Printf

magic :: String
magic = unlines $ map magicN [1..7]
                magicN :: Int -> String
                magicN n
                        | n > 0 && n <
8 && n /= 4 = "09 f9 11 02 9d
74 e3 5b d8 41 56 c5 63 56 88 " ++ printf
"%02x" (0xbc + n)
                        | otherwise                = "
                 [ redacted ]                  "

main :: IO ()
main = putStr magic

Update: I received a Kindle for Christmas (will blog Kindle vs Nook soon). It turns out the Kindle automatically wraps PRE tags, and the above CSS ruins that wrap. To reiterate, Nook books require explicit PRE wrapping, but that same explicit wrapping destroys Kindle’s excellent autowrap.

Syntactic barriers to learning Common Lisp

lisp logoFunctional programming is blessed to have several hardy languages. I have only tried two: Haskell and Common Lisp. From the few tutorials I’ve completed, it seems that Haskell is easy to learn, and Lisp hard to learn.

This difference is, I believe, due to Lisp’s various and sundry dialects, implementations, and macros. In Haskell, there are two major ways to specify local variables: let and where. Common Lisp has at least four: let, let*, flet, and labels. CL has a retarded number of loop constructs. I’m currently reading a sample chapter from Land of Lisp. Here is a code snippet:

(defun find-islands (nodes edge-list)
  (let ((islands nil))
    (labels ((find-island (nodes)
	       (let* ((connected (get-connected (car nodes) edge-list))
		      (unconnected (set-difference nodes connected)))
		 (push connected islands)
		 (when unconnected
		   (find-island unconnected)))))
      (find-island nodes))

The defun syntax is intuitive; it’s like any other language’s function creator. And let makes sense: create some local variables and use them in sub-expressions. But labels baffles me. Would let have sufficed? Why or why not? After googling for a while (there is NO useable, complete Common Lisp reference document, and that includes HyperSpec and the Simplified Common Lisp Reference), I stumbled on a half-readable description of labels.

LABELS is special form for local function binding.

I could have told you that.

Bindings can be recursive and can refer to each other.

So labels is just like defun, defvar, and friends?

Each binding contains function name, arguments, and function body.

It seems that labels is just a special way to do defun locally. If Lisp is so powerful, why doesn’t Barkski do this:

(defun find-islands (nodes edge-list)
  (let ((islands nil))
    (defun find-island (nodes)
      (let* ((connected (get-connected (car nodes) edge-list))
	     (unconnected (set-difference nodes connected)))
	(push connected islands)
	(when unconnected
	  (find-island unconnected))))
    (find-island nodes)

Nested functions don’t require special syntax in Haskell, Python, or Lua. Why should they in the premier functional language? I think the answer is that CL allows nested defuns, but lispers aren’t happy with that–they want a closure they can use in if, cond, and other non-code-block areas. A combination of let and lambda would do just that, but macro-addiction dictates that a new syntax be created. Now we have labels.

So that’s defun, let, and labels. Then there’s let*. Apparently let* is similiar to flet, which is similiar to labels , which is similar to let, except that I’ve forgotten where the fuck I was going with that. These macros are simply variations of let, some more powerful than others.

Land of Lisp does explain these macros, but if they weren’t used in the code, they wouldn’t have to be explained. Or, Barski could have used a separate example for each macro, but that would have taken more pages. There must be a balance between code simplicity and time to get the game running. I understand his dilemma. But if he errs to often on the side of code obscurity, then readers will simply close the book. I don’t know if I can write an informative and entertaining programming tutorial as well as Barski does, but I know what I like in one, and it’s not a never-ending stream of new syntax. I’m still going to buy the book, and I’m still going to love it. It’s just going to take longer for me to parse than I had expected.

Practical Common Lisp Rolling Review

book coverAs I follow the exercises in Practical Common Lisp (PCL) by Peter Seibel, I’ll post the experiences here. Let’s get started.

The Book Itself

is available in dead-tree format and as a series of HTML files. My new Nook is hungry for ePubs, so I downloaded each PCL chapter, dragged and dropped into Sigil, and tweaked the resulting ePub. Sigil has a horrible bug which shoves code blocks way down pages, so my copy of PCL isn’t looking too great. But I plan to write a CL program to restore its former glory.

Chapter 1

is an introduction designed to welcome programmers to Lisp. A short summary would be: DON’T PANIC. The intro is humorous and intriguing.

Chapter 2

Shit just got real. Now PCL ushers the reader to install Lisp in a box (really Lispbox). Back in 2005, Lispbox was surely a godsend for the budding Common Lisper, but in 2010 it’s not only aged, it’s broken. I’ve already blogged about the pain and agony of setting up a CL system, and I won’t repeat myself. Suffice to say MacPorts is only half a saving grace for Mac users. I’m currently using Aquamacs and Aquamacs SLIME with MacPorts CLISP and Quicklisp besides. My .emacs is pastebinned.

PCL covers the basics of Emacs shortcut keys then jumps to the Lisp interpreter. SLIME is quite helpful in this endeavor, compiling, running, debugging my code for me. I like the PCL’s Hello World is not a program but an expression entered into the REPL. Since half the work will be done there, it’s a good idea to get acquainted with ol’ Reppy.

PCL dives into writing defun’s; introduces the debugger; details the proper loading of source files and optional compilation of same, and ends with a NASA anecdote. A geek such as I couldn’t hope for much more than this chapter.

Chapter 3

The first practical chapter. PCL invites the reader to construct a simple music database, introducing Lisp syntacs and semantics along the way. I completed save-db, load-db, … up to update and delete-rows. I’m happy to report that Seibel’s code is clear and concise. PCL suggests using a combination of select and where to simulate a SQL query, with the effect that I almost believe I’m using a real database.

The section, “Removing Duplication and Winning Big” is not easy to skim over, so I’m stuck there for now. It covers Lisp macros, a topic I’ve only heard in reverent whispers.

I’ll let you in on a secret: I’m concurrently reading Real World Haskell. There are notable differences between Haskell and Common Lisp.

Haskell vs Common Lisp

Haskell has one official version (GHC) available on multiple platforms, free, and open source. Common Lisp has no official version. There are Windows-only versions, commercial versions, Linux-only versions with broken makefiles, and CL install kits that once served a purpose but now only serve to mock the senseless diversity of CL implementations.

Installing a complete Haskell environment is simple and painless. Installing Common Lisp took me on a journey.

GHC incorporates new features in each version. Common Lisp’s lack of an official version means that each flavor includes and omits important features. E.g., some come with multithreading, some don’t. ANSI can’t be as responsive as the Haskell community, so the Common Lisp standard will likely not benefit from new features anytime soon.

Haskell stores functions and variables in the same space. Common Lisp does not; it requires ' and #' to pass functions around.

Haskell syntax is light and uniform. By PCL Ch. 3, Common Lisp syntax is starting to slow me down.

Haskell has monads. Common Lisp has macros. More on that when I learn precisely what they are and how to use them.

Haskell’s error messages are somewhat esoteric. Common Lisp’s are more readable.

GHCi’s REPL has enough features to satisfy most programmers. Common Lisp REPLs often fail to include expression history, backspace functionality, and other obvious REPL features. CL REPLs are so crippled that Emacs/SLIME is a necessity.

Both Haskell and Common Lisp syntax are unique, requiring special effort to understand. I believe this is because BASIC syntax is more natural. STEP 1 STEP 2 STEP 3 is intuitive for humans. On the other hand, linear procedures aren’t very powerful. Functional languages have power because they break out of the STEP 1 STEP 2 STEP 3 routine: Spaghetti code is the result of a procedural programmer attempting to do more complex work.

Back to PCL

I’m not sure exactly when I need to #' functions in Common Lisp. While following the PCL exercises, I’ve left out #' for lambdas, and my code gives the same results as Seibel’s. It stands to reason that lambdas don’t need to be #'ed since they self-evaluate. Allegro and CLISP don’t need #' for lambdas, but I’m not sure about other CLs. In any case, I’d like to see a note about this in PCL. Also, I wonder why multiple quote syntaxes exist: ', `, and quote.

Common Lisp Syntax

Look at the code for generating a database query. There are SIX different symbols, each with their own purpose and usage.

(defmacro where (&rest clauses)
  `#'(lambda (cd)
    (and ,@(make-comparison-expr-list clauses))))

The ampersand in &rest is CL’s way of handling function arguments. &key would interpret the arguments as a property list, while &rest stores all the arguments in clauses.

The #' references the lambda without evaluating it. That is, pound (#) references an unevaluated (') lambda object.

The comma (,) and at (@) work together to force evaluation inside the unevaluated (`#') lambda expression. The lambda would have been prefaced with '#', but ,@ only works inside the backtick quote (`).

No poofters.

LibraryThing a Good Idea

The interface needs some work, but the website is a good idea. List the books you’ve read. You can then look at virtual shelves, rate books, review books, and connect with people who have read similar books.

Check out the books I’m reading.

P.S. LibraryThing has a limit of 200 books unless you purchase a membership (lifetime is only $25).