Checksum (noob)



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

.



Relevant Pages

  • Re: Checksum (noob)
    ... checksum routine, which would look like this in C++: ... Lisp version: ... lists, integers, etc.) and causing havoc at runtime. ... Alas, it gets the indentation wrong, or at least it's different ...
    (comp.lang.lisp)
  • Re: Python syntax in Lisp and Scheme
    ... > depth relative to the global context. ... transform python's 'globally context' dependent indentation block structure ... markup into into C/Pascal-style delimiter pair block structure markup. ... I don't understand why this is any different to e.g. ')))))' in Lisp. ...
    (comp.lang.python)
  • Re: Python syntax in Lisp and Scheme
    ... > depth relative to the global context. ... transform python's 'globally context' dependent indentation block structure ... markup into into C/Pascal-style delimiter pair block structure markup. ... I don't understand why this is any different to e.g. ')))))' in Lisp. ...
    (comp.lang.lisp)
  • Re: Amazon used lisp & C exclusively?
    ... ignore the parens and pay attention to the indentation. ... I think this is true for people where Lisp tends to click naturally, ... to get rid of the parantheses in a person's mind. ...
    (comp.lang.lisp)
  • Re: Amazon used lisp & C exclusively?
    ... The parens are for the lisp parser and your text editor. ... ignore the parens and pay attention to the indentation. ... Parantheses still in the same manner as you are using the other ...
    (comp.lang.lisp)