On 6/25/09 4:51 PM, "Mark Polesky" <markpole...@yahoo.com> wrote:

> 
> 
> Here are 2 versions of the same procedure.
> Is the second one *too* concise and cryptic?
> - Mark

I actually like the general format of the second one better.

But I'd rewrite it a bit:  It's a string-compare-<? function, so keep the
-<, and it's a predicate, so it should have a ?

(define (ly:string-compare-<? a b ci)
  (let ((mismatch (first-diff-chars a b ci)))
    (cond ((not mismatch) #f)   ; a and b are equal
          ;; now I know mismatch is not #f, so I can use it safely
          ((not (car mismatch)) #t) ; a is an initial substring of b
          ((not (cdr mismatch)) #f) ; b is an initial substring of a
          (else                     ; a and b have different characters
             ((if ci ly:char-ci<? ly:char<?)
                   (car mismatch) (cdr mismatch)))))))

Whenever I write a (cond ), I like to be able to express the outcome of each
alternative in language that is easily understood.  In some cases, the code
itself does it.  In this case, because first-diff-chars is a function with
a difficult return, I needed to remember the different outcomes of
first-diff-chars.  Then I wanted a cond clause for each possible outcome,
so that's why I wrote it this way.

HTH,

Carl



_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to