[Top][All Lists]

[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: Tue, 21 Jan 2020 22:31:55 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

A few annotations:

David Kastrup <address@hidden> writes:

> Kieren MacMillan <address@hidden> writes:
>> As the next step, I want to turn this into a function and display the
>> result in a markup. Result: I spend several hours searching
>> documentation, trying different functions, and getting one (or more!)
>> errors per attempt, but no success. I literally cannot figure out how
>> to turn this into a string, save hand-coding a recursion/map that
>> takes each element of the list and appends it onto a string… and if
>> that’s actually the "correct"/"best" way to do it, then I deeply
>> question my desire to code in Scheme+Lilypond at all.  ;)
> You are letting yourself getting infected by Mike's coding style.  Mike
> is a genius that will reinvent three wheels in the time it takes to
> learn about one.
> Try the following:
> \version "2.19.83"
> some-music = { a'4 bes' b' aes' g' cis' d' ees' fis' f' e' c' }
> #(display (let ((res (music-pitches some-music)))
>          (map ly:pitch-semitones (map ly:pitch-diff (cdr res) res))))

Of course you can also do
#(display (let ((res (map ly:pitch-semitones (music-pitches some-music))))
             (map - (cdr res) res)))

Namely first convert to semitones and then do the difference.

> buzz =
> #(define-scheme-function (mus) (ly:music?)
>   (map number->string
>    (let ((res (music-pitches mus)))
>     (map ly:pitch-semitones (map ly:pitch-diff (cdr res) res)))))
> \markup \right-column \with-color #red { \buzz \some-music }

You may want to do this as a markup list command instead.  Combining
both suggestions:

\version "2.19.83"

some-music = { a'4 bes' b' aes' g' cis' d' ees' fis' f' e' c' }

#(display (let ((res (map ly:pitch-semitones (music-pitches some-music))))
           (map - (cdr res) res)))

#(define-markup-list-command (buzz layout props mus) (ly:music?)
  (interpret-markup-list layout props
    (map number->string
      (let ((res (map ly:pitch-semitones (music-pitches mus))))
        (map - (cdr res) res)))))

\markup \right-column \with-color #red { \buzz \some-music \vspace #3 }
\markup \right-column \with-color #red { \buzz { c' d' e' c' } }

>> So someone please tell me what simple thing I’m missing here. In the
>> worst case scenario, you just give me a fish and I can eat for a
>> little while longer (read: not give up); best case senario, you teach
>> me (and anyone else reading this list, now or in the future in the
>> future) how to fish.

As musicians, we know that simplicity in execution is the way to go, but
getting there takes practice.  Being able to do it the hard way is the
first step.

David Kastrup

reply via email to

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