Hi Kieren! On Tue, Jan 21, 2020 at 1:52 PM Kieren MacMillan <kieren_macmil...@sympatico.ca> wrote: > > Hi all, > > Here’s a perfect example of why I keep stumbling (and stopping) when trying > to learn Scheme+Lilypond… =\ > > With Mike S’s help — read: he did it all, actually! (though I fully > understand every part of the code) — I have the following: > > %%% SNIPPET BEGINS > \version "2.19.83" > > some-music = { a'4 bes' b' aes' g' cis' d' ees' fis' f' e' c' } > > #(define (zip . xss) (apply map list xss)) > > #(display > (let* ((res (map > (lambda (foo) (ly:pitch-semitones (ly:music-property foo > 'pitch))) > (ly:music-property some-music 'elements))) > (top (reverse (cdr (reverse res)))) > (bottom (cdr res))) > (map (lambda (h) (- (cadr h) (car h))) (zip top bottom))) > ) > %%% SNIPPET ENDS > > Works great. Just what I want at this stage in the (multi-stage) procedure > I’m trying to code. > > 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. ;) > > 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. > > Thanks, > Kieren.
Try this: %% SNIPPET BEGINS \version "2.19" some-music = { a'4 bes' b' aes' g' cis' d' ees' fis' f' e' c' } #(define (zip . xss) (apply map list xss)) #(define-markup-command (pitch-info layout props args) (ly:music?) (let* ((res (map (lambda (foo) (ly:pitch-semitones (ly:music-property foo 'pitch))) (ly:music-property some-music 'elements))) (top (reverse (cdr (reverse res)))) (bottom (cdr res)) (ls (map (lambda (h) (- (cadr h) (car h))) (zip top bottom))) (markups (map (lambda (elt) (make-simple-markup (number->string elt))) ls))) (interpret-markup layout props #{ \markup \line #markups #}))) \markup \pitch-info #some-music %%% SNIPPET ENDS Hope this gets you started with whatever dodecaphonic plans you have... David