PostgreSQL 9.2 To Support JSON As A Core Type

Andrew Dunstan has a post in his Andrew’s PostgreSQL blog reporting that PostgreSQL 9.2 will support JSON as a core type. This is yet another reason to favor JSON as a universal log reporting format as I discussed in my Writing Log Files In JSON post.

Of course, as a Lisper I’d still use S-expressions for any of my own projects due to their flexibility and self-transforming capabilities. Still, if you’re going to have non-Lispers using those logs, JSON makes a lot of sense. Certainly more than the common “printf” style logs, and especially more than an XML abomination.

Posted in General | Leave a comment

Functional Thinking

Here’s an interesting talk about thinking in a functional way by Neal Ford. I’ve tagged this post as Lisp but Ford doesn’t use Lisp—he uses some weird mutation of Java, a little Groovy, and a little Scala. The point of the talk, he says, is not about functional programming languages but about learning to think functionally.

Be sure not expand the embedded video because the slides appear in the bigger box under the video.

Posted in Programming | Tagged | Leave a comment

Useful Emacs Commands Reference

Xah Lee has several useful reference pages, such as this one of HTML/XML Entities, that I use all the time. I have them bookmarked for easy reference so that when I, for example, need to know the Unicode character for ρ, I can just bring up the page in my browser to look it up. I’ve also been bookmarking pages from my blog that I describe as “notes to myself” for the same reason.

Over time I find that I have a bunch of pages with a lot of explanatory text and then a summary at the end that is what I’m really interested in. I decided to combine those summaries into a single document to make things easier to find. Since those notes-to-myself posts tended to generate a lot of comments (by Irreal standards) I thought I would make the page available in case anyone else found it useful.

The page is here if you’d like to bookmark it and I’ve also added a link to it over on the right under Links.

Posted in General | Tagged | 5 Comments

Emacs On Google+ And Strange Keybindings

Xah Lee announced on his Emacs Blog that he has started an Emacs stream on G+. If you’re interested in Emacs, you should check it out. You don’t have to be a G+ member to read the posts.

Also interesting in that post is a link to A Curious Look at GNU Emacs’s 1000+ Default Keybindings. In it, Lee looks at the default keybindings and finds many strange things. Some of the bindings are historical artifacts and not used anymore. Some are accessed with keys that don’t appear on any modern keyboards. It’s an entertaining post with lots of things I didn’t know before. There’s even a picture of the Symbolics Space Cadet keyboard that had some of those mysterious keys that are no longer extant.

Update: binding → bindings

Posted in General | Tagged | Leave a comment

Safety And The Lisp Read Function

For all my blathering about security, here’s a potential exploit in Common Lisp that I never thought about. William Halliburton has a nice explanation of Lisp’s read function and the assoicated read-macro #.. When read sees the sequence #. it will evaluate the next Lisp object that it reads. For example, given the following inputs to read the corresponding object is returned as the result of the read:

(+ 1 (/ 8 4)) → (+ 1 (/ 8 4))
#.(+ 1 (/ 8 4)) → 3
(+ 1 #.(/ 8 4)) → (+ 1 2)

That’s pretty neat but as Halliburton points out it also poses a security threat because a user can use it to execute arbitrary code in a Lisp program that naively reads data from the user.

Follow the link for a more complete explanation of the #. read-macro, an example of using it for an exploit, and a simple safe-read function that prevents the problem.

If you’d like to play around with read and #. to see how they act and what they return, here’s a function that acts as a REPL without the evaluation that you can use.

(defun rpl ()
  "A REPL without the evaluate. Type (quit) to exit."
  (princ "rpl> ")
  (let ((obj (read)))
    (prin1 obj)
    (terpri)
    (unless (equal obj '(quit))
      (rpl))))
Posted in Programming | Tagged | 1 Comment

Blogging With Emacs—Another Method

Today, someone on Hacker News pointed to an old post on Blogging With Emacs over at Work In Progress. Since some of my readers had expressed an interest in how I use Emacs and Org-mode to blog, I thought there might be some interest in seeing how someone else does the same thing.

The blog’s author takes a very different approach to blogging with Emacs than I do. First of all he uses Jekyll to generate a static site rather than using WordPress. That means that he doesn’t have the wonderful org2blog at his disposal but he solves that problem by using Org mode’s project publishing facility. I’ve never used that part of Org mode but it seems to be pretty nice. Bernt Hansen has a nice writeup on Publishing and Exporting with Org mode that you should read if you want to use this facility.

The Work In Progress post is interesting and shows how easily Emacs can handle different work flows to solve the same problem. My only quibble with the post is in the first sentence where he says, “I don’t want to waste time explaining why I use Emacs all day, every day, and eschew more traditional development environments.” I would argue that Emacs is the traditional editor—or at least that Emacs shares that honor with Vi. Yes, yes, I know all about ed but let’s be serious.

By the way, DJCB over at EMACS-FU also has an old post on using Org mode to blog, this time with Blogger. As always, there’s a lot to learn at EMACS-FU.

Posted in Blogging | Tagged , | Leave a comment

Working With Matching Lines In Emacs

This is another note to myself. For some reason I have a hard time remembering the handful of commands that do things to the lines in a buffer that match a regular expression. The table below are the ones that I know about but have a hard time remembering. If you have any similar commands that you find useful, leave a comment.

Command Alias Action
keep-lines delete-non-matching-lines Delete lines not matching regexp
flush-lines delete-matching-lines Delete lines matching regexp
how-many count-matches Count lines matching regexp
occur list-matching-lines Show lines matching regexp in another buffer
highlight-lines-matching-regexp hi-lock-line-face-buffer Highlight lines matching regexp

Update Phil reminds me of highlight-lines-matching-regexp, which I meant to include but forgot. (See what I mean?) He also mentions multi-occur (just like occur but it acts on multiple buffers) and multi-occur-in-matching-buffers (like multi-occur but you specify the buffers with a regexp), which he says he finds particularly useful.

Posted in General | Tagged | 8 Comments

The Popularity Of Programming Languages

TIOBE Software has published its list of programming language popularity for January 2012 and awarded Objective-C the TIOBE Programming Language Award for 2011. The award is given for the language with the most growth in market share for the year. Objective-C’s growth is driven, of course, by the popularity of the iPhone and iPad and their App Store infrastructure.

There aren’t a lot of surprises. Java is in first place (but losing share) and C is second and gaining share. Surprisingly, Python lost a significant amount of share and dropped from 5th place last year to 8th this year. Lisp has positive growth and maintained its 13th place from last year.

I don’t take the list too seriously but it does, as TIOBE says, give programmers a view of what languages are “important” at the moment and an indication of whether or not their skills need updating. Other than that the list is interesting on its own terms. Who would have thought, for instance, that Objective Pascal is in 11th place ahead of Ruby in 12th?

Posted in Programming | Leave a comment

The Emacs count-lines-region Command

I’ve been working on a Lisp program that generates combinations of certain objects. During development, I like to print them out to see what, exactly, is getting generated. Often, I’ll realize that I also need to know how many objects got generated. Because I’m using slime, all the output is going into an Emacs buffer so I have all the normal Emacs tools available.

I didn’t know a command for counting lines but I was pretty sure there would be one and after a quick trip to the built-in documentation I found count-lines-region, which was just what I needed. All I had to do was mark the output and call count-lines-region. Happily, there’s even a shortcut for it so I can just mark the region and type 【Meta+=】 to get a line count of the output.

Posted in General | Tagged | 3 Comments

Common Lisp Pitfalls

Here is a list of Common Lisp pitfalls compiled by Jeff Dalton. They were originally posted to comp.lang.lisp in 1995. If, like me, you’re a Lisp programmer but you don’t write in Common Lisp everyday, it’s probably a good idea to read over this list now and then to remind yourself of the gotchas that are lurking in Common Lisp.

Posted in Programming | Tagged | Leave a comment