Tag Archives: Lisp

Code for “The Book”

If you read the excellent Beautiful Code: Leading Programmers Explain How They Think (O’Reilly, 2007), you probably remember the chapter contributed by Brian Hayes entitled Writing Programs for “The Book”.

The thrust of the chapter is that, somewhere, not necessarily in an earthly library, there exists a book containing the best possible algorithms for computing functions or programs. Much of the artistry and craftsmanship in programming concerns the search for those ideal algorithms.

That chapter just reverberated with me (“Yes! That’s what I’m trying to do!”) and I’m reminded of it every time I’m writing new functions. In particular, finding ways to cover the entire argument domain of a function and not overflow the result or experience large errors in the case of approximations.

I really like the Lisps for these types of functions because of the “infinite” precision math that can be used. It makes it possible to come up with functions that just work without having to worry so much about overflow protection. If performance isn’t good enough, then you can worry about how to speed it up.

Getting Started with Lisp/Scheme/Clojure

Ya know, this point just keeps slapping me in the face. It seems that people don’t stop trying to use Lisp because they don’t like the language. A lot of people stop because they don’t like the programming environment. Looking around the Q&A sites there seem to be many more questions about setting up a programming environment for the Lisp family of languages than there are for the more mainstream languages like Java and C++. Well, here are my suggestions.

Continue reading

Ideas for Simulated Evolution

Note: This is a re-post of an earlier entry recovered from a different blogging system.

After entering and running the evolution.lisp example from Land of Lisp, I have some ideas for additional traits.

Here is a short list of a few.

  1. Size, Carnivorous Animals. Add a feature to allow the animals to be of different sizes. Larger animals would expend energy faster. When two animals occupy, the same cell, the larger would try to eat the smaller, taking it’s energy. The smaller could try to flee. Chance of successful hunting/fleeing would be based on the size difference. For example, if the larger animal is only slightly larger, the smaller animal would have a pretty good chance of escaping. As the hunter gets larger, the chance of succeeding becomes larger.
  2. Speed. With a higher energy expenditure per turn, animals could move more than one cell at a time. Perhaps this would be a modifying factor in fleeing from hunters too.
  3. Sex. If two animals of the same size occupy the same cell and have enough energy between them, they could reproduce and shuffle their genetic material in the offspring. Number of offspring might be another variation depending on energy.
  4. Plant Toxicity. Immature plants would be poisonous. The animals would require some sense(s) to detect the maturity of a plant before eating it.
  5. Vision. One of the senses to detect plant maturity might be vision with variations in acuity at distance (to see plants further away) and color (for detecting plant maturity).

Of course, a nicer user interface would be a good thing too.

Why did emacs “stick” this time?

Note: This is a re-post of an earlier entry recovered from another blogging system.

After innumerable attempts and false starts, I am now using emacs on a regular basis. What is different about this latest effort?

It’s a bit of a puzzler, but after thinking about it a bit, here are a few things that might be different this time.

  1. Repeated Exposure. Maybe after all of the other attempts, I am finally “ready” to grasp emacs.;-)
  2. Lisp Cabinet. This time, I installed emacs using Lisp Cabinet and it “just worked”. There was not the usual configuration and setup hassle. And it supports several Lisps, Clojure, and Racket.
    The color scheme is nice. Indentation is automatic (in Lisp anyway). It is intended to work with Windows. It just seems easier to use.
  3. Land of Lisp. I started using emacs to work through the examples in Land of Lisp. The examples are long enough that they require actually learning some of the command keystrokes, but short enough that it doesn’t feel like a typing lesson.
    A few years ago I worked through Practical Common Lisp, but it didn’t stick. In fact, I referred back to the early part of PCL to recall some of the emac keystrokes I needed to enter the LoL stuff. I used (the no longer supported) Lisp-in-a-Box for a bit, but it didn’t stick. The Lispbox project has tried to take up the slack, but it didn’t work for me when I tried it and I went down the usual configuration rabbit hole without getting it to work as I wanted, then gave up. (Again.)

So, after years of starts and stops and unmeasurable amounts of frustration, I’m finally getting comfortable with emacs.