Checksum (noob)
- From: "atgraham@xxxxxxxxx" <atgraham@xxxxxxxxx>
- Date: 27 Dec 2006 14:13:01 -0800
After a 10 year hiatus, I've begun experimenting with Lisp again.
Among other things, I've written a typical 8-bit modulo arithmetic
checksum routine, which would look like this in C++:
std::accumulate(lst.begin(), lst.end(),
0, std::minus<unsigned char>());
Lisp version:
(defun checksum (lst)
(logand (- 0 (apply '+ lst)) #xff))
I like it. However, I'm wondering if it's appropriate to be paranoid
about a user passing invalid parameters to such a function (lists of
lists, integers, etc.) and causing havoc at runtime.
I've been looking over Graham's book, and he stresses the importance of
indentation. Traditionally, I've shunned emacs, since it seems to get
*all* default behavior wrong, in every situation, and I don't have the
willpower to maintain a configuration. But I thought I would give it
another try, since it seems to have been designed specifically for
Lisp. Alas, it gets the indentation wrong, or at least it's different
than what Graham suggests (for example, in "if" expressions, it indents
the "then" differently than the "else"). Is there a configuration
parameter that I can use to fix it?
(setq indent-lisp-correctly t) ; wouldn't that be nice
I also noticed that gcl will accept a dotted list as a parameter to
checksum, but clisp will not. What's the correct behavior?
Aaron
.
- Follow-Ups:
- Re: Checksum (noob)
- From: Bill Atkins
- Re: Checksum (noob)
- From: Zach Beane
- Re: Checksum (noob)
- Prev by Date: Re: lisp and youtube
- Next by Date: Re: which one of these with-gensym implementations is better?
- Previous by thread: how to write a ''multiple characters' macro character' ?
- Next by thread: Re: Checksum (noob)
- Index(es):
Relevant Pages
|