lilypond-user
[Top][All Lists]
Advanced

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

Re: [Scheme coding] turning a list into a markup/string


From: David Kastrup
Subject: Re: [Scheme coding] turning a list into a markup/string
Date: Wed, 22 Jan 2020 10:58:56 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Kieren MacMillan <address@hidden> writes:

> HOLD THE PRESSES!!
>
> I think I have it:
>
> %%%%  SNIPPET BEGINS
> \version "2.19.83"
>
> some-music = { a'4 bes' b' aes' g' cis' d' ees' fis' f' e' c' }
>
> #(define-markup-list-command (diffints layout props mus) (ly:music?)
>    (interpret-markup-list layout props
>      (map (lambda (d) (string-append (if (positive? d) "+" "") 
> (number->string d)))
>        (let ((muspst (map ly:pitch-semitones (music-pitches mus))))
>          (map - (cdr muspst) muspst)))))
>
> \markup \line \with-color #red \diffints #some-music
> \markup \line  \with-color #red \diffints ##{ c' d' e' c' #}
> %%%%  SNIPPET ENDS
>
> Comments and code critique appreciated.

I'd use (lambda (d) (format "~@d" d)) here myself but it does differ in
writing +0 (in case that's undesired).  If one wants to avoid an
unnecessary string-append, one can go
(lambda (d) (let ((s number->string d))
              (if (positive? s) (string-append "+" s) s)))

but of course that is not exactly saving space.

-- 
David Kastrup



reply via email to

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