Re: Checksum (noob)
- From: Zach Beane <xach@xxxxxxxx>
- Date: 27 Dec 2006 17:57:06 -0500
"atgraham@xxxxxxxxx" <atgraham@xxxxxxxxx> writes:
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.
Document the proper parameters. If people violate the specification,
they rightly land in the debugger.
Also, "lst" is a bad name for a parameter that is a list. "list" would
be better, if no more suitable name is appropriate.
http://www.cs.northwestern.edu/academics/courses/325/readings/graham/graham-notes.html
has some examples of other things from ANSI Common Lisp to avoid.
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, ...
Not true.
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 lisp-indent-function 'common-lisp-indent-function) is a quick
way. You can make it more specific to CL buffers, but if you don't
edit a lot of elisp, you don't have to worry much about it. Google
should give you some examples with which to work.
I also noticed that gcl will accept a dotted list as a parameter to
checksum, but clisp will not. What's the correct behavior?
I don't see where in the hyperspec that a proper list is required, but
I didn't look especially hard.
Zach
.
- Follow-Ups:
- Re: Checksum (noob)
- From: Damien Kick
- Re: Checksum (noob)
- References:
- Checksum (noob)
- From: atgraham@xxxxxxxxx
- Checksum (noob)
- Prev by Date: Re: how to write a ''multiple characters' macro character' ?
- Next by Date: Re: Checksum (noob)
- Previous by thread: Checksum (noob)
- Next by thread: Re: Checksum (noob)
- Index(es):
Relevant Pages
|