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

The Emacs set-variable Command

I learned a new Emacs command today. What do you do when you want to set an Emacs variable? Until today my answer was 【Meta+:】 and then

(setq some-variable some-value)

That works well and there’s nothing wrong with it but it’s often faster to use 【Meta+xset-variable instead. When you do that, Emacs will prompt you for the variable and its value. One of the reasons that this may be faster is that you can 【Tab】 to complete variable names.

Posted in General | Tagged | Leave a comment

AT&T To Cap Unlimited Data Plans

The Wall Street Journal is reporting that AT&T is going to cap unlimited data plans. Truth to tell, it’s not much of a change because they were already slowing download speeds for the top 5% of their bandwidth consumers. Now they will slow download speeds for anyone exceeding 3 gigs/5 gigs for 3G/4G users. In view of the study that I wrote about last week that showed there is essentially no difference between the data usage of “the top 5 percent” and the top tier of the metered users, it’s hard to see how this is justified.

I wouldn’t be surprised to see some push back. After all, AT&T sold their customers an unlimited data plan and charged more for it. At the time there was no talk of capping the plans or slowing speeds. Just pay us the extra money please. That arguably amounts to a contract to provide the unlimited service as sold. It certainly amounts to a moral obligation.

If AT&T feels that they can’t make money with their current plans then they’re free not to offer them but they’re not free to simply abrogate those contracts—even partially—simply for their own convenience. And certainly not as a device to force all their customers onto a tiered plan as the researchers that I wrote about last week suspect. Back in the old days, everyone hated Ma Bell. This is the kind of behavior that reminds us why.

Update: According to a Wired Gadget Lab article, the change was in response to customer complaints that the “top 5% rule” was catching people who were using no more data than the tiered customers, who weren’t being throttled.

Posted in General | Leave a comment

Yegge On Dynamic Languages

I stumbled upon a nice talk that Steve Yegge gave at Stanford in 2008. The talk, entitled Dynamic Languages Strike Back, debunks some of the myths about the performance, optimization, and tools for dynamic languages such as Python, Ruby, Perl, and even our favorites such as Lisp and Scheme.

Yegge argues that despite the claims of static typing partisans, you can get better performance and optimization with dynamic languages. That requires a some work, much of it yet to be done, but we are already making great strides. The idea is that you have much better information about program behavior at run time than you do at compile time so better decisions can be made. Yegge remarks that the Java byte compiler, for example, does all sorts of optimization but at run time the VM converts the byte stream back to a tree and throws out all the optimizations in favor of its own, which are superior. The talk is worth listening to just to hear him expound on this point.

Yegge predicts that the languages we have today and their relative popularity will remain pretty much constant for the foreseeable future. It’s too hard for new languages to gain traction even if they are better and many developers today know only one language and resist learning another, suggesting the static ranking.

During the question period, someone asked if we are any better off today than we were with the Lisp machines. Yegge said he didn’t think so and remarked that the only Lisp machine left today is Emacs and despite the fact that Elisp isn’t the world’s best Lisp it still provides an amazingly powerful environment.

This is a great talk and I recommend it to anyone interested in dynamic languages. It’s about 68 minutes so plan accordingly.

Posted in Programming | Leave a comment