Monthly Archives: June 2014

The less familiar parts of Lisp for beginners — summary R

I’ve written a few posts about features of the Lisp language that a newcomer arriving from C++ might not have encountered.  I’m going through them alphabetically, so here is a summary page of the functions beginning with the letter R:

random

read-preserving-whitespace

read-delimited-list

read-from-string

read-line

readtable-case

reduce

reinitialize-instance

remove-method

remprop

restart-bind

restart-case

rotatef

row-major-aref

The less-familiar parts of Lisp for beginners — shadow

Next on our list is the shadow function.  This function affects symbols in packages, so if those concepts are unclear to you you might want to read this earlier article.  This function interns a new symbol with the supplied name in the given package if that symbol doesn’t already exist in that package directly (i.e. not through inheritance).  If the symbol exists through inheritance alone, the symbol interned by shadow has the effect of shadowing the inherited symbol in the package.

The less-familiar parts of Lisp for beginners — set-syntax-from-char

The function set-syntax-from-char allows the programmer to copy a read-macro from one character in a particular readtable and duplicate it on possibly a different character in another readtable.  To understand what this means, you may want to review the earlier discussion of readtables.

Here is an example.  It’s not something I would recommend doing in real code, it’s just here for demonstration purposes.  If I want to write some code which contains a lot of strings with embedded double-quote marks, I might be tempted to come up with a new string delimiter to use in that case.  In this code, I copy the meaning of ” into the underscore.  I can then write my code using double-quotes in some places, and underscores in others.  A string that begins with an underscore can only be ended with another underscore, not the double-quote, so this allows me to embed double-quote characters easily in a string.

Naturally, this novel string syntax would break at load time, so we have to use eval-when to modify the readtable before forms using this syntax are read.  Also, note that the colorization is wrong in the code, because SLIME doesn’t know about this new string format, and thinks that I have an unterminated string in my code.  Here’s the code:
set-syntax-from-char.lisp

(eval-when (:compile-toplevel :load-toplevel :execute)
  (set-syntax-from-char #\_ #\"))

(defun demonstrate ()
  (format t "Here is a string: ~S~%" "abcd")
  (format t "Here is another string: ~S~%" _ab"cd_))

Producing the output:
*slime-repl sbcl*
CL-USER> (demonstrate)
Here is a string: "abcd"
Here is another string: "ab\"cd"
NIL

Unreachable server

While I was away on vacation, the server hosting this blog become unresponsive, twice.

The first failure was a kernel oops shortly after mounting my backup disc

kernel BUG at mm/slab.c:3109!

invalid opcode: 0000 [#1] PREEMPT SMP

It was several days before somebody with a key could get to the computer and restart it.  A week later, shortly before I returned from vacation, the machine become unreachable again.  This time, when I came into the house, I could hear a continuous audible alarm from the UPS.  I reset that, and the machine came up and worked normally.

So, two apparently unrelated problems knocking the machine offline when I wasn’t around to handle it.  I checked my SMART logs for the backup disc, there’s no sign that it’s a hardware issue, and the UPS logs are entirely empty of anything incriminating.

If I figure out the causes of either of these failures, I’ll update this post.

Update #1: 2014-06-20

The UPS triggered its alarm again this morning, and the server lost power.  The UPS is an APC Back-UPS ES 750, and a continuous tone indicates that the battery is missing or has failed.  I’ve replaced the battery, and hope that the issue does not repeat.