Tuesday, November 4, 2014

Stumbling Blocks, One-character Wide

Lisp, the programming language, is one of the oldest still in use. It has many variants, or "dialects", as the programming language people like to call them: Common Lisp, Elisp (specifically for the Emacs text editor), Scheme, and Clojure are popular ones. Because of macros, because of the (relatively) straightforward syntax—throw parentheses around everything—and because of sheet hype, the people who love Lisp love it almost fanatically.

I'm trying to be one of those people. I threw in with Common Lisp because of Peter Siebel's excellent book, Practical Common Lisp; I can't say it hasn't been without some bumps.

Case in point: what is 'a'? Encodings and character sets aside, what is it, really? The intuitive answer is, "it's a letter", or, more computery-sounding, "it's a character". With lisp, it isn't always so clear, however: it could be a character, yes, or it could be a string of length: 1. Lisp has both characters and strings, rare in my experience: either you have strings as a fundamental data type, or you have characters and fashion strings as an array or vector of characters. But having both: that's something I'll have to get used to. (EDIT: Nope, I'm wrong. And this entire post is an example of how far I have to go in understanding Common Lisp.)

Likewise, numbers can be confusing. Perl has a "DWIM" ("Do What I Mean") ethos behind it, and is usually pretty good at guessing what you mean, at the cost of some runtime cycles. One place where it's so good at doing what I mean, it tripped me up in my initial attempts to learn Lisp. If the perl interpreter sees something that looks like a number, it treats it like a number, espcecially if you're trying to do numeric things with it like sorting or arithmetic.

Lisp, or at least Common Lisp, doesn't do that. It sees a "7" somewhere, and it might be a number. Or it might be a character.

I can tell this is something that's going to bite me again before I gain proficiency.

cheers,
Adam

No comments:

Post a Comment