Common Lisp, Scheme, Clojure, And Elisp Compared

A month ago we had a lively discussion here at Irreal on the question of whether or not Elisp sucks. As with most questions of this sort, there were champions of both positions: some felt that Elisp is a distinctly inferior Lisp and others felt that Elisp along with Emacs is better than the other Lisps and able to solve problems that the others could not easily deal with.

Doubtless these battles will continue to rage for as long as there are programmers but now Hyperpolyglot offers a very nice comparison of Common Lisp, Scheme, Clojure, and Elisp. By comparison I mean a table of operations and how each implements that operation, if at all.

One interesting take away for me was the extent to which Elisp mirrors Common Lisp’s operations. The table includes the functionality that we get from (require 'cl) so this isn’t too surprising but it does speak to another lively discussion that took place in the comments to Reversing An Emacs Lisp List In-Place: should Elisp automatically include the Common Lisp functionality?

If you’re not familiar with one or more of the Lisps compared in the chart, it’s a good place to get a feel for how they measure up to the ones you are familiar with. It can even serve as a cheat sheet if you use more than one of the Lisps and sometimes have trouble remembering which way to do some operation in the Lisp you’re using at the moment. It’s an interesting chart and fun to look if only for its entertainment value.

Posted in Programming | Tagged , , | 1 Comment

Spam Update

I’m seeing yet another spike in spam so I’ve reluctantly turned on moderation again. If NuCaptcha can plug the hole that appears to be allowing this spam I will, of course, turn it off again.

Interestingly, one mystery is solved. The second group of spammers that I wrote about yesterday—the ones who try to match appropriate comments to the post and then refer to Facebook pages—appear to have been a proof of concept. The Facebook links have been replaced by the usual links to commercial enterprises.

Posted in Administrivia | Tagged | Leave a comment

Spam Raises Its Head Again

After a period of virtually no forum spam I’m seeing a spike in the amount of spam. This may be because of the recent NuCaptcha break or it may be due to the spammers using a Mechanical Turk-like strategy of paying a small amount to have people to enter the codes by hand.

The spam falls into two groups. The first is just the normal junk consisting of little more than a link for Google to notice. They typically try to hide by getting added to older posts.

The second is more interesting. They try very hard to hide in plain sight by looking like legitimate comments. Comments are selected either by a keyword search or perhaps by the tags. The fit isn’t always perfect, of course. A post concerning Emacs, say, might get a comment that’s also about Emacs but about some other aspect completely. In some cases the comments are taken from Irreal (in at least one case, from the same post it appeared in) and others apparently from other blogs. The comments appear to be retyped—there are usually a lot of typos—rather than harvested programmatically.

Oddly, the spam in the second group, although clearly bogus, does not contain any links other than the poster’s Web URL, which always points to a nearly empty Facebook page for the commenter. These Facebook pages appear to be from Germany, the Netherlands, and other European countries. I can’t quite think what the point of it is. Has anyone else seen this? If so, do you have any idea what’s going on?

I’m going to ping NuCaptcha to see if they have a fix for the NuCaptcha break in the works. If not, I may have to turn on moderating again. I hate that and I’m sure you do too. If anyone has a good WordPress solution please leave a comment.

Posted in Administrivia | Tagged | Leave a comment

Quicklisp

After being inspired to finally start using ELPA to handle my Emacs packages, I decided to try out Zach Beane’s Quicklisp library manager for Common Lisp. Up until now, I’ve been using the manual method to get things into ASDF, a process that can be painful.

I haven’t had a lot of time to play around with it yet so this isn’t really a review but so far I’m pretty impressed. The first indication of quality was how easy the installation is. You just download the quicklisp.lisp file from the Quicklisp site and load it into whatever CL system you’re using. Quicklisp asks you to run (quicklisp-quicklisp:install) and it takes care of fetching the code and associated files, and building the necessary directories to hold everything. The process is reminiscent of the ELPA install: you just run a small piece of code and it does the rest.

If you think you might be interested in Quicklisp, Beane has a nice screencast that shows how it works and what it does. In the screencast he shows it working with SBCL, LispWorks, Clisp, and ECL. The installation and use are the same regardless of platform.

The nice thing about Quicklisp is that it makes it easy to load load libraries and keep them up to date. In the past, I sometimes hesitated to get a library because I knew it was going to be a lot of work. With Quicklisp, all I have to do is run (ql:quickload "some-library") and Quicklisp fetches the library and compiles it for me. It’s hard to see how it could be much easier.

Posted in Programming | Tagged | Leave a comment

ELPA

I’ve been meaning to install ELPA for a long time but never got around to it. Then Emacs 24 was on the horizon and I thought, “Why bother going through the pain of installing it when it will be included in Emacs 24 anyway?” Now, Xah Lee has shamed me into it by posting his Guide on the Emacs Package System.

It is astounding how easy the installation is. Simply cut a bit of Elisp from Lee’s page, paste it into an Emacs buffer, evaluate the buffer and you’re done. The Elisp that you paste retrieves the ELPA installer and executes it. The installer makes an elpa directory in ~/.emacs.d/, populates it with the necessary files including package.el, and adds some Elisp to your .emacs or init.el file to load the packages you install when Emacs starts.

Lee includes a section on what to do when you upgrade to Emacs 24. It mostly involves removing the ELPA code from your .emacs, deleting the ~/.emacs.d/elpa subdirectory, and reinstalling the packages you had loaded.

I did run into one problem. By default, ELPA uses the tromey.com/elpa package server but I wanted to use the more extensive Marmalade server. Lee has instructions on how to do that. You just add

(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))

to your .emacs or init.el file and execute it. Unfortunately, the package-archives variable doesn’t exist in the package.el that got downloaded. The Marmalade site (Lee has a link to it) points to a slightly never version that does have it so I just installed that instead. No problems so far and I saved the old version in case there are any.

One of the nice things about ELPA is that it stores everything in your ~/.emacs.d/elpa subdirectory so it’s easy to keep my machines in sync since ~/.emacs.d is under Git. All in all, a big win for me.

Posted in General | Tagged | 12 Comments

TSA: Worse Than You Thought

Jon Corbett over at TSA Out of Our Pants is making his displeasure with the TSA felt and in the process has become a real thorn in their side. After being denied access to his flight when he refused to either enter the scanner or submit to having his genitals groped, he filed suit in November 2010. That suit is now headed for the supreme court: Corbett will shortly file a petition for a writ of certiorari.

Most Irreal readers are aware of the issues involved here and know that what the TSA provides is not security but security theater. I’m sure, therefore, that most of those readers will, like me, consider Corbett a hero.

Now Corbett has outdone himself. On March 6 he posted a video of himself taking a metal object through the scanners (at two different airports) without being detected. The video explains how he did it and why anyone could do the same. That, he claims, renders the billion dollars spent on the scanners wasted. The TSA was to quick to respond in a blog post at tsa.gov. The response was, to say the least, underwhelming. While they did everything they could to disparage Corbett (including refusing to refer to him by name) they didn’t actually dispute his claims. The comments to the post are hilarious in their evisceration of the response.

Now Corbett is reporting that the TSA is threatening the mainstream media not to cover the story. A South Florida reporter told Corbett that the TSA “strongly cautioned” him not to cover the story. As I wrote in my last post on the TSA they have a unique ability to combine heavy-handedness with incompetence. This latest event serves as yet another example.

Corbett is taking donations to help fund his appeal to the Supreme Court. If you can afford a few dollars stop by his site and contribute. The rest of the country will be grateful.

Update: Ken over at Popehat follows up on the cautioning of the reporter(s). BoingBoing also covers the story and has some entertaining comments.

Posted in General | Tagged | Leave a comment

Script Kiddies At Work

Kura over at SYSLOG has a really great animation showing the origins of SSH attacks on a single server during a 24 hour period. It’s another reminder, if you needed one, to lock down your machines. It’s pretty obvious these are just scripts trying a range of IP addresses but that makes it worse in a way. These aren’t targeted attacks. They’re automated scripts looking for a vulnerable machine. It’s easy to think, “I’m not a high profile site so no one will bother with me” but these guys will bother anyone foolish enough to leave the door open.

The animation is less than a minute but still fascinating. Recommended.

Posted in General | Tagged | 1 Comment

JSON Versus S-Expressions (Again)

I’ve written several posts concerning the relative merits of JSON vs S-expressions (1, 2, 3, 4) and concluded that while s-expressions are more powerful and flexible, JSON might be a better choice because it’s supported by virtually all programming languages. A couple of days ago, Eli Bendersky published a post that reached similar conclusions. While his conclusions pretty much align with mine his reasoning does not and I disagree with it.

Bendersky approaches the question from the standpoint of parsimony and says that while JSON is a win over XML because it’s more “fat free,” you can’t go further and replace JSON with sexprs to get rid of even more fat because there’s no easy way to handle dictionary structures. He says that the equivalent S-expression to the JSON expression

'[["oranges", 2], ["apples", 6], ["pears" 5]]'

is

'((ORANGES 2) (APPLES 6) (PEARS 5))

which is indeed less punctuation but that as soon as you have the JSON expression

'{"oranges": 2, "apples": 6, "pears": 5}'

S-expressions lose because there’s no way to express a dictionary structure with sexprs without adding abstraction.

That’s certainly not true. Here, for example, is a Common Lisp reader macro that does just that.

(defun |#H-reader| (stream sub-char numarg)
  (declare (ignore sub-char numarg))
  (let* ((kv (read stream t nil t))
         (h (make-hash-table :test 'equal :size (* 2 (length kv)))))
    (mapc (lambda (p)
            (destructuring-bind (key value) p
              (setf (gethash (symbol-name key) h) value)))
          kv)
    h))

(set-dispatch-macro-character #\# #\H #'|#H-reader|)

Notice how short and easy it is to write. Now we can treat that sexpr as a dictionary simply by prepending #H.

CL-USER> (setq dict #H((oranges 2) (apples 6) (pears 5)))
#<HASH-TABLE :TEST EQUAL size 3/31 #x3020009740CD>
CL-USER> (gethash "APPLES" dict)
6
T

Or we can prepend ' and treat it as an association list or simply an unordered list.

“But I don’t use Lisp” I hear you say. I could respond that your choice to use a less powerful language is not my problem but I won’t do that precisely because that’s the reason JSON may make more sense: it’s supported in all programming languages.

Bendersky remarks that he can read

'{"oranges": 2, "apples": 6, "pears": 5}'

directly into Python or Javascript and get his dictionary-like structure. As I showed above, you can do that in Lisp too. Now what about all those other languages? How is JSON more natural and direct in, say, C++ than an S-expression? Sure, there are JSON libraries for them but that’s adding abstraction and if we can do it for JSON we can also do it for S-expressions.

I believe JSON may be a better solution because it represents a sort of lowest acceptable common denominator. It’s simple, everyone understands it, and there are libraries for every imaginable language. But that doesn’t mean it’s better in some absolute or esthetic sense. It isn’t. S-expressions are more powerful (because of the duality of code and data), more flexible, and have less syntactic sugar.

In any event, Bendersky’s post is interesting and makes some good points. You should really take a look and decide whether you agree with him or not.

Update: mapcar → mapc. The mapcar works, of course, but there’s no reason to build the list of values and then throw it away.

Update 2: associative array → association list

Posted in General | Tagged , | 1 Comment

DMR Stories

Mike Maney over at Maney Digital has a very nice tribute up for Dennis Ritchie. While he was at the Mobile World Congress in Barcelona, Maney talked to some of dmr’s colleagues and captured their words on his Flip. The production values, as he admits, are not great but it is great to hear people who knew and worked with dmr tell stories about him and what he was like. It’s not long at all, so take 4 minutes and give it a look.

Posted in General | 1 Comment

Reversing An Emacs Lisp List In-Place

Yesterday, Xah Lee put up a post that showed how to reverse arrays and lists in various languages, including Emacs Lisp. His Elisp examples worked only for arrays so I added one for lists in the comments. Later I realized that although it was pretty efficient it wasn’t really a solution because it built a separate list.

Here’s a less efficient method that does do the reverse in-place

(let ((list '(a b c d e f g)))
  (do ((i 0 (1+ i))
       (j (1- (length list)) (1- j)))
      ((>= i j) list)
    (rotatef (nth i list) (nth j list))))

If you’re not familiar with (or don’t like) the do macro, here’s the same strategy rendered with a while.

(let* ((list '(a b c d e f g)) (l 0) (r (1- (length list))))
  (while (< l r)
    (rotatef (nth l list) (nth r list))
    (incf l)
    (decf r))
  list)

We can also use rotatef to reverse an array

(let ((vec ["a" "b" "c" "d" "e" "f" "g"]))
  (do ((i 0 (1+ i))
       (j (1- (length vec)) (1- j)))
      ((>= i j) vec)
    (rotatef (aref vec i) (aref vec j))))

Of course, all this is a bit silly because Elisp already has this covered. The best and fastest way to reverse a list in-place is

(let ((list '(a b c d e f g)))
  (nreverse list))
Posted in Programming | Tagged , | 5 Comments