lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: define-grobs.scm properties not alphabetical


From: Carl D. Sorensen
Subject: Re: define-grobs.scm properties not alphabetical
Date: Thu, 25 Jun 2009 17:49:37 -0600



On 6/25/09 4:51 PM, "Mark Polesky" <address@hidden> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]