Subject: Re: Code review: CL for SNA (Social Network Analysis)
From: (Rob Warnock)
Date: Wed, 21 Dec 2005 04:47:37 -0600
Newsgroups: comp.lang.lisp
Message-ID: <>
Christophe Rhodes  <> wrote:
| (Rob Warnock) writes:
| > (defun prefix-match-p (prefix line)
| >   (not (mismatch prefix line :end2 (length prefix) :test #'char-equal)))
| I think you need
| (defun prefix-match-p (prefix line)
|   (and (>= (length line) (length prefix))
|        (not (mismatch prefix line :end2 (length prefix) :test #'char-equal))))
| otherwise you run the risk of signalling an error, which isn't what
| you want, when the argument to END2 is larger than the length of the line.

Oops! Correct, good point.

| That can also be written
|   (defun prefix-match-p (prefix line)
|     (let ((mismatch (mismatch prefix line :test #'char-equal)))
|       (or (null mismatch) (= mismatch (length prefix)))))

O.k., but to my taste this is slightly simpler:

    (defun prefix-match-p (prefix line)
      (not (mismatch prefix line :end2 (min (length prefix) (length line))
				 :test #'char-equal)))


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607