In Praise of Lisp (was Re: Emacs auto-modes and tabs)
Jason Stephenson
jason at sigio.com
Thu Apr 17 10:10:39 EDT 2003
Erik Price wrote:
>
>
> (Someday (but not too soon (well, maybe)) I will have to learn
> ((e(?))Lisp. It seems quite infectious. (But (I have heard that) it is
> very elegant.)) ;)
I know some people think Lisp is ugly. These people don't like all the
parenthesis and some don't like the conventional indentation style. I,
however, think that well-formatted Lisp code is quite visually appealing
on the screen, and visual appeal is as good a reason as any to use a
language. (I think it is better than the reasons most people give when
asked why they wrote something in one language or another.) Here's an
old function from my ~/.emacs to illustrate:
(defun munge-buffer ()
"Strip carriage returns from buffer; replace with linefeeds."
(interactive)
(save-excursion
(let ((count 0) (file "UNIX"))
(goto-char (point-min))
(while (search-forward "\r" nil t)
(replace-match "\n" nil t)
(set count (1+ count))
(if (= (char-after (point)) ?\n)
(progn
(delete-char 1)
(set count (1+ count)
file "MS-DOS"))
(setq file "MacOS")))
(message "file type: %s; %d characters replaced." file count))))
Lisp is also a very powerful language. You can do anything in Lisp that
you can do in any other language and sometimes with fewer lines of code.
Lisp is a "functional" programming language. It's big on functions.
Pretty much everything you see in a Lisp program is either a function or
it is data. There are no operators. Check out the (if (= ... in the code
above for an example. There are also objects available in Common Lisp
(via CLOS).
I think learning Lisp improved my programming overall. Having learned it
before learning C, I had no problem with function pointers. It also
seems to me that a Lisp project requires a bit of up-front thought and
planning to decide what funtions are needed and how to organize them.
This has spilled over into my work in other languages, even my quick and
dirty Perl hacks. (No, I'm not really into one-liners.:) I'm not saying
everyone will get the same results with Lisp, but I highly recommend
playing with it. It never hurts to stretch the mind every now and then.
It might also teach you some new tricks, such as closures, that you can
apply in other languages. You'll also want to learn to use the variable
function argument facility of other languages once you get used to
processing lists in Lisp.
I just wish that I had more time to do things in Lisp. I mostly write
Lisp-ish or OO Perl these days. Though the last several months have seen
me hacking mostly on PHP for a client's web site. I have read that a lot
of the initial code used in the Yahoo! stores was written in Lisp.
More information about the gnhlug-discuss
mailing list