Re: [Scheme coding] turning a list into a markup/string
On Wed, Jan 22, 2020 at 8:26 AM Simon Albrecht wrote: > On 21.01.20 22:05, Kieren MacMillan wrote: > > I’m pretty sure I would have taken quite a while to find my way to > "make-simple-markup" > > > Note that > > (make-simple-markup "foo") > > is equivalent to > > (markup #:simple "foo") > > in other words it’s the spelled-out version of what’s usually accessed > through the markup macro in Scheme. > > HTH, Simon > And the Scheme functions are consistently named relative to the markup functions. make-concat-markup, make-column-markup, etc. DN > >
Re: [Scheme coding] turning a list into a markup/string
On 21.01.20 22:05, Kieren MacMillan wrote: I’m pretty sure I would have taken quite a while to find my way to "make-simple-markup" Note that (make-simple-markup "foo") is equivalent to (markup #:simple "foo") in other words it’s the spelled-out version of what’s usually accessed through the markup macro in Scheme. HTH, Simon
Re: [Scheme coding] turning a list into a markup/string
Hi David (N), > Exactly. Even though I took Mike's original more or less as-is and > just added a couple of things, I still got my fair share of errors. > With my memory I *always* end up looking up a few things. Well, that makes me feel a little better… Given the speed, complexity, and completeness of your [Scheme] responses, I’ve always just assumed you wave your hand, say something like “These aren’t the droids you’re looking for”, and it’s done! Onward and upward! Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
On Wed, Jan 22, 2020 at 1:33 AM Urs Liska wrote: > > Am Dienstag, den 21.01.2020, 20:11 -0500 schrieb Kieren MacMillan: > > or the life of me, I can’t quite figure out where exactly such a > > construct would appear in the code. Everywhere I try throws > > [different] errors. =( > > I can promise you, it will be that way for a very long time. > But I can also promise you that at some point (and if you continue at > that pace that may be rather sooner than later) the errors will stop > scaring you and rather point you in the right direction. > > Remember when Mike coded the original function for you? He typed > something in to express an idea - and I think *every* such attempt > failed on first try. However, the error message made it immediately > clear to him where the mistake would be, he counted parenthesis and > directly fixed it. > Exactly. Even though I took Mike's original more or less as-is and just added a couple of things, I still got my fair share of errors. With my memory I *always* end up looking up a few things. The console messages help enormously. As does syntax highlighting. I'm awful at counting parentheses, and luckily I never have to do it. Best, David
Re: [Scheme coding] turning a list into a markup/string
Kieren MacMillan writes: > Hi David, > >> I'd use (lambda (d) (format "~@d" d)) here myself > > Good to learn that tool! > >> but it does differ in writing +0 (in case that's undesired). > > It is. > >> 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))) > > I assume you’re missing a set of parentheses? Shouldn’t it rather be > > (lambda (d) (let ((s (number->string d))) > > ? Oops. Yes. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Hi Urs, > I can promise you, it will be that way for a very long time. Everyone on this list is so encouraging… ;) > But I can also promise you that at some point (and if you continue at > that pace that may be rather sooner than later) the errors will stop > scaring you and rather point you in the right direction. I’m starting to feel that shift already. > Remember when Mike coded the original function for you? He typed > something in to express an idea - and I think *every* such attempt > failed on first try. To be honest, he was typing and talking and coding so fast, I thought a wormhole had opened up in the space-time continuum. I blinked and he was done. ;) > I'm sure https://scheme-book.ursliska.de/scheme/expressions.html will > not give you any new information, but it may be worth reviewing it. The > topic was the "click" moment for me ... > Also, https://scheme-book.ursliska.de/scheme/concepts.html and > following/below might contain useful perspectives for you. I’m going to read (or at least skim) through the whole book, and get back to you with thoughts (as you requested some time ago; apologies for the delay). Thanks, Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Hi Aaron, > Instead of string-append and number->string, try (format #f "~@d" d). > > ~d formats an integer as a decimal value > @ includes "+" for positive values > > One caveat is it formats zero as "+0". > > Perhaps: (lambda (d) (if (zero? d) "0" (format #f "~@d" d))) That’s great — thanks! Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Hi David, > I'd use (lambda (d) (format "~@d" d)) here myself Good to learn that tool! > but it does differ in writing +0 (in case that's undesired). It is. > 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))) I assume you’re missing a set of parentheses? Shouldn’t it rather be (lambda (d) (let ((s (number->string d))) ? Thanks, Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Kieren MacMillan 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
Re: [Scheme coding] turning a list into a markup/string
At 17:03 21/01/2020 -0500, Kieren MacMillan wrote: ... it seemed a wonderfully magical start out of the gate, but we were ultimately unable to take it to the goal-line. Also, I mixed my sporting metaphors in that sentence; oh well. That's nothing: a moment ago we had someone playing football whilst fishing up a mountain! Brian Barker
Re: [Scheme coding] turning a list into a markup/string
Am Dienstag, den 21.01.2020, 20:11 -0500 schrieb Kieren MacMillan: > or the life of me, I can’t quite figure out where exactly such a > construct would appear in the code. Everywhere I try throws > [different] errors. =( I can promise you, it will be that way for a very long time. But I can also promise you that at some point (and if you continue at that pace that may be rather sooner than later) the errors will stop scaring you and rather point you in the right direction. Remember when Mike coded the original function for you? He typed something in to express an idea - and I think *every* such attempt failed on first try. However, the error message made it immediately clear to him where the mistake would be, he counted parenthesis and directly fixed it. I'm sure https://scheme-book.ursliska.de/scheme/expressions.html will not give you any new information, but it may be worth reviewing it. The topic was the "click" moment for me ... Also, https://scheme-book.ursliska.de/scheme/concepts.html and following/below might contain useful perspectives for you. HTH Urs
Re: [Scheme coding] turning a list into a markup/string
On 2020-01-21 7:02 pm, Kieren MacMillan wrote: 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. Instead of string-append and number->string, try (format #f "~@d" d). ~d formats an integer as a decimal value @ includes "+" for positive values One caveat is it formats zero as "+0". Perhaps: (lambda (d) (if (zero? d) "0" (format #f "~@d" d))) -- Aaron Hill
Re: [Scheme coding] turning a list into a markup/string
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. Thanks, Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Hi again (too soon?), I’m trying to make the positive intervals have a + in front of them. Q1. My intuition tells me I need to use a lambda function with append. Does that seem like a reasonable approach? Regardless, assume for argument’s sake that it is… For the life of me, I can’t quite figure out where exactly such a construct would appear in the code. Everywhere I try throws [different] errors. =( The following doesn’t throw an error, and I know why, and I know why it outputs what it does — so I’m not quite as stupid as I feel (and maybe appear?): %%% \version "2.19.83" some-music = { a'4 bes' b' aes' g' cis' d' ees' fis' f' e' c' } #(display ((lambda (d) (append d d)) (map number->string (let ((muspst (map ly:pitch-semitones (music-pitches some-music (map - (cdr muspst) muspst) %%% So this leads to my real question: Q2. What is a good way to change #(display (map number->string (let ((muspst (map ly:pitch-semitones (music-pitches some-music (map - (cdr muspst) muspst so that it outputs (+1 +1 -3 -1 -6 +1 +1 +3 -1 -1 -4) ? Thanks, Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Kieren MacMillan writes: > Hi David, > >> # goes into Scheme, and #{ goes into music mode then. > > Yes, that makes sense in retrospect. > >> If you write #{ then # goes into Scheme and Scheme has no idea what { >> is supposed to be. >> > > And tells you so, in no uncertain terms. ;) Oh, that would be better than what I'd expect. Which would rather be throwing a tantrum and making a big mess. But the first words of the tantrum might still make some sense if you manage focusing on them. >> I've not fundamentally changed LilyPond's design. > > Sorry… That was not meant to be a comment on your work I didn't really take it to be. It was just pointing out that I am more of an improver than a designer. Two days ago Han-Wen was looking over my shoulder and pointed out helpfully where I wrote \override NoteHead.style = #'mensural instead of \override NoteHead style = #'mensural or possibly \override Notehead #'style = #'mensural and it was really jarring for me to realise just how quietly I have been treading. The LilyPond Han-Wen has been familiar with will still answer him in the accustomed manner. In Stanisław Lem's "Pilot Pirx" series there is a story "Terminus" where a repair robot hammering lead as a sealant does it repeating Morse sequences of previous cosmonauts who perished in a catastrophe it was part of, and Commander Pirx on a whim knocks some question into the mindless sequences of the robot and gets responses. > — just pointing out that Scheme is daunting enough to start learning > without hearing that the main thing you’re planning to wrestle with > (at least in the short term) is made up of "icky things". > >> I've not really had much of a wrestling match with markup and their >> commands yet. > > Perhaps once I’m more comfortable with Scheme I can start to wrestle > with them, and you can "tag in" when I’m pinned. Let's see where we get when. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Hi David, > # goes into Scheme, and #{ goes into music mode then. Yes, that makes sense in retrospect. > If you write #{ then # goes into Scheme and Scheme has no idea what { is > supposed to be. And tells you so, in no uncertain terms. ;) > I've not fundamentally changed LilyPond's design. Sorry… That was not meant to be a comment on your work — just pointing out that Scheme is daunting enough to start learning without hearing that the main thing you’re planning to wrestle with (at least in the short term) is made up of "icky things". > I've not really had much of a wrestling match with markup and their commands > yet. Perhaps once I’m more comfortable with Scheme I can start to wrestle with them, and you can "tag in" when I’m pinned. Thanks so much for all your help! Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Kieren MacMillan writes: > Hi David, > >> Well, ##{ c' d' e' c' #} would work. > > In the "Nearly, But Not Quite There" category: I tried > > #{ c' d' e' c' #} > > which, of course, failed. I didn’t think to prepend a second #. # goes into Scheme, and #{ goes into music mode then. If you write #{ then # goes into Scheme and Scheme has no idea what { is supposed to be. >> Markups are icky things. > > That is, perhaps, not the best thing to admit to someone on the first > rung of the "Learning To Program In Scheme For Lilypond" ladder… I've not fundamentally changed LilyPond's design. I streamlined and generalised a lot of stuff where things appear to make a whole lot more sense now and have quite less of a tendency to bleed internals all over you if you poke them wrong. But consistent and logical is not the same as simple even though it helps, and I've not really had much of a wrestling match with markup and their commands yet. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Hi David, > Well, ##{ c' d' e' c' #} would work. In the "Nearly, But Not Quite There" category: I tried #{ c' d' e' c' #} which, of course, failed. I didn’t think to prepend a second #. > Markups are icky things. That is, perhaps, not the best thing to admit to someone on the first rung of the "Learning To Program In Scheme For Lilypond" ladder… Cheers, Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Thomas Morley writes: > Am Di., 21. Jan. 2020 um 23:13 Uhr schrieb David Kastrup : >> >> Thomas Morley writes: > >> > David, you remember my suggestion to generate that "General Code >> > Reference" with an Index ... ? >> >> Yes, that may have helped. But it may also have delivered a haystack. >> >> I think we probably need a "good programming" corpus, but the snippets >> are supposed to be that. Navigating them still is too hard. > > If you think of the "Snippets Manual" or the LSR, then I doubt they > are best suited to what I think we need. > Their snippets are too much targeted at delivering ready to use tools > for actual typesetting work. > > As an example: > music-map has the problem that you can't really stop it recursing > deeper. One reason why you wrote map-some-music and for-some-music. > Alas, I always need to get to their doc-strings again, to understand > the differences and which one to use for which case. Like in Scheme, map returns something, for doesn't. I think that early designs had more arguments, requiring even more doc-string lookup to get them right. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Thomas Morley writes: > Am Di., 21. Jan. 2020 um 23:13 Uhr schrieb David Kastrup : >> >> Thomas Morley writes: > >> > David, you remember my suggestion to generate that "General Code >> > Reference" with an Index ... ? >> >> Yes, that may have helped. But it may also have delivered a haystack. >> >> I think we probably need a "good programming" corpus, but the snippets >> are supposed to be that. Navigating them still is too hard. > > If you think of the "Snippets Manual" or the LSR, then I doubt they > are best suited to what I think we need. > Their snippets are too much targeted at delivering ready to use tools > for actual typesetting work. > > As an example: > music-map has the problem that you can't really stop it recursing > deeper. One reason why you wrote map-some-music and for-some-music. > Alas, I always need to get to their doc-strings again, to understand > the differences and which one to use for which case. > And ofcourse their docstrings are not in any manual, afaict. > > Sometimes I look in our regression-tests, which contains nice coding > examples, but you can't expect average user to look there. > And sometimes even the regression-test don't say anything, as an > example for no info at all: > $ git grep "ly:broadcast" > lily/dispatcher-scheme.cc:LY_DEFINE (ly_broadcast, "ly:broadcast", > scm/define-music-callbacks.scm: (ly:broadcast > (ly:context-event-source context) > > Leading to IR entry: > > Function: ly:broadcast disp ev > Send the stream event ev to the dispatcher disp. > > Which is ununderstandable without any context. Yes. The CG might have a bit of info there, but if it is there, it is likely very sketchy and does not really help a lot. > Cheers, > Harm Well, to some degree my "why don't you use $x" kind of advice results from having had to fight through the code base in order to be able to refactor parts I had to fix into something I could understand. So I have bit of a semantic network in my head that may give me a hunch what to grep for in order to tackle some class of problem. That's pretty lousy as a way of getting information suited to the task. I don't like the bus factor impact that makes me have. Gives me a bad conscience. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Am Di., 21. Jan. 2020 um 23:13 Uhr schrieb David Kastrup : > > Thomas Morley writes: > > David, you remember my suggestion to generate that "General Code > > Reference" with an Index ... ? > > Yes, that may have helped. But it may also have delivered a haystack. > > I think we probably need a "good programming" corpus, but the snippets > are supposed to be that. Navigating them still is too hard. If you think of the "Snippets Manual" or the LSR, then I doubt they are best suited to what I think we need. Their snippets are too much targeted at delivering ready to use tools for actual typesetting work. As an example: music-map has the problem that you can't really stop it recursing deeper. One reason why you wrote map-some-music and for-some-music. Alas, I always need to get to their doc-strings again, to understand the differences and which one to use for which case. And ofcourse their docstrings are not in any manual, afaict. Sometimes I look in our regression-tests, which contains nice coding examples, but you can't expect average user to look there. And sometimes even the regression-test don't say anything, as an example for no info at all: $ git grep "ly:broadcast" lily/dispatcher-scheme.cc:LY_DEFINE (ly_broadcast, "ly:broadcast", scm/define-music-callbacks.scm: (ly:broadcast (ly:context-event-source context) Leading to IR entry: Function: ly:broadcast disp ev Send the stream event ev to the dispatcher disp. Which is ununderstandable without any context. Cheers, Harm
Re: [Scheme coding] turning a list into a markup/string
Kieren MacMillan writes: > Hi David, > >> The line below it is a 2.21.0 feature that cannot be used from a >> LilyPond for which we have an installer. > > Ah. Thanks. (Note: feature/version disconnection is another thing that > caused my past Scheme efforts to stumble, leading to becoming > discouraged in my efforts.) > >> I wasn't aware that the line above is problematic but I see how it >> could. Maybe write #some-music instead. > > That works great. Is there a similar fix for the next input line? > > \markup \right-column \with-color #red { \buzz { c' d' e' c' } } Well, ##{ c' d' e' c' #} would work. Basically, almost everything that is not either a markup or markup list in 2.20 has to start with # . And I am not sure that the second line will survive eternally: it's discomfortingly close to markup list syntax and thus would be tricky to implement once markup commands get more intelligent predicate interpretation, like music functions do now. It's conceivable when { gets read to check whether the predicate would accept '() (the simplest markup list) and only get into music mode when it doesn't. Markups are icky things. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Hi David, > The line below it is a 2.21.0 feature that cannot be used from a > LilyPond for which we have an installer. Ah. Thanks. (Note: feature/version disconnection is another thing that caused my past Scheme efforts to stumble, leading to becoming discouraged in my efforts.) > I wasn't aware that the line above is problematic but I see how it > could. Maybe write #some-music instead. That works great. Is there a similar fix for the next input line? \markup \right-column \with-color #red { \buzz { c' d' e' c' } } Thanks, Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Kieren MacMillan writes: > Hi David, > >> I am glacially slow for almost everything because I am ridiculously >> afraid of wasting time doing something wrong. That turns to work out >> better for teaching than getting anything done myself. > > That may be the best two-sentence description of me I’ve ever read. =) > >> And music-pitches is also convenient to know. > > That’s the main one that jumped out at me as "Well, if I had known > about that one…!" (For the record: Harm used event-chord-pitches in > his attempt at my problem, and it seemed a wonderfully magical start > out of the gate, but we were ultimately unable to take it to the > goal-line. Also, I mixed my sportsing metaphors in that sentence; oh > well.) > > Am I correct that music-functions.scm is the best dust-covered > repository of arcane knowledge in which one can find "music-pitches" > and a description of what it does? It's not really dust-covered since it is frequently changed, but since most of its contents continue to scroll by programmers occasionally, there is some chance that much of it has had a chance to converge to a reasonably smooth state. Which does not mean that all of that is well-documented. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Thomas Morley writes: > Hi Kieren, hi David, > > Am Di., 21. Jan. 2020 um 22:45 Uhr schrieb David Kastrup : > >> And music-pitches is also convenient to know. > > David, you remember my suggestion to generate that "General Code > Reference" with an Index ... ? Yes, that may have helped. But it may also have delivered a haystack. I think we probably need a "good programming" corpus, but the snippets are supposed to be that. Navigating them still is too hard. > Kieren showed me the problem in Salzburg and I suggested quick'n dirty > event-chord-pitches, music-pitches feels a bit cleaner, though. It's newer I think. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Kieren MacMillan writes: > Hi David, > >> 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. > > Ah! Perhaps I was on the right path with the first part of what I gave > to Mike (which used the ly:pitch-semitones function). > >> #(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' } } > > I get errors when I try to compile that: > > error: syntax error, unexpected MUSIC_IDENTIFIER > \markup \right-column \with-color #red { \buzz >\some-music \vspace #3 } > … > > Am I missing something? I cut-and-paste your code [from email into > Frescobaldi] several times… The line below it is a 2.21.0 feature that cannot be used from a LilyPond for which we have an installer. I wasn't aware that the line above is problematic but I see how it could. Maybe write #some-music instead. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Hi David, > I am glacially slow for almost everything because I am ridiculously > afraid of wasting time doing something wrong. That turns to work out > better for teaching than getting anything done myself. That may be the best two-sentence description of me I’ve ever read. =) > And music-pitches is also convenient to know. That’s the main one that jumped out at me as "Well, if I had known about that one…!" (For the record: Harm used event-chord-pitches in his attempt at my problem, and it seemed a wonderfully magical start out of the gate, but we were ultimately unable to take it to the goal-line. Also, I mixed my sportsing metaphors in that sentence; oh well.) Am I correct that music-functions.scm is the best dust-covered repository of arcane knowledge in which one can find "music-pitches" and a description of what it does? Thanks, Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Hi David, > 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. Ah! Perhaps I was on the right path with the first part of what I gave to Mike (which used the ly:pitch-semitones function). > #(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' } } I get errors when I try to compile that: error: syntax error, unexpected MUSIC_IDENTIFIER \markup \right-column \with-color #red { \buzz \some-music \vspace #3 } … Am I missing something? I cut-and-paste your code [from email into Frescobaldi] several times… Thanks, Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Hi Kieren, hi David, Am Di., 21. Jan. 2020 um 22:45 Uhr schrieb David Kastrup : > And music-pitches is also convenient to know. David, you remember my suggestion to generate that "General Code Reference" with an Index ... ? Kieren showed me the problem in Salzburg and I suggested quick'n dirty event-chord-pitches, music-pitches feels a bit cleaner, though. Cheers, Harm
Re: [Scheme coding] turning a list into a markup/string
Kieren MacMillan writes: > Hi David, > >> Mike is a genius that will reinvent three wheels >> in the time it takes to learn about one. > > That might be a little bit of the pot calling the kettle black…? ;) I am glacially slow for almost everything because I am ridiculously afraid of wasting time doing something wrong. That turns to work out better for teaching than getting anything done myself. > Oh! So much to learn in there. Thank you. > > Any idea which (if either) is more expensive, yours or Mike’s (well, > {Mike+David N.}’s)? Clearly Mike's, but you are not likely to be able to notice a difference for most applications. Either will be quite faster than parsing the music in the first place. >> I find it great that you understand everything that Mike does here > > In fact, I may have sent him down this particular path by suggesting > that we do essentially what I would do with a list of numbers in > maxima: > >diff(nums) := rest(nums,1) - rest(nums,-1) > > He probably just took that idea and ran with it to the [Lily-Scheme] > goal-line. That may be. Running is so little effort to him that he can just take a route and follow it. >> you are well-prepared to figure out what I am doing, and what may >> be hidden away in some of the internals of the read-made tools I use. > > What tools are those exactly? The main one is (map - (cdr res) res) which relies on map (more exactly the (srfi srfi-1) version of it that LilyPond input may depend on) working with a function taking more than one argument, and not minding if the corresponding lists have different length (it just runs until the shortest is exhausted). And music-pitches is also convenient to know. >> it is seminal for me to tackle problems with the simplest means I can >> manage. > > I live (and die?) by the belief that "Every elegant question has an > elegant answer". =) I guess in this case the answer is more blunt than elegant. It refuses to acknowledge the refinement of the problem. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
A few annotations: David Kastrup writes: > Kieren MacMillan 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: > > %%% SNIPPET BEGINS > \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 } > > %%% SNIPPET ENDS You may want to do this as a markup list command instead. Combining both suggestions: %%% SNIPPET BEGINS \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' } } %%% SNIPPET ENDS >> 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
Re: [Scheme coding] turning a list into a markup/string
Hi David, > Mike is a genius that will reinvent three wheels > in the time it takes to learn about one. That might be a little bit of the pot calling the kettle black…? ;) > Try the following: > > %%% SNIPPET BEGINS > \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 > > 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 } > > %%% SNIPPET ENDS Oh! So much to learn in there. Thank you. Any idea which (if either) is more expensive, yours or Mike’s (well, {Mike+David N.}’s)? > For teaching how to fish from scratch, Mike's demonstration may be > better-suited. > My solution is more a demonstration of what you can do > when you know your way around the fishing grounds. There are definitely multiple plateaus in every learning mountain climb… > I find it great that you understand everything that Mike does here In fact, I may have sent him down this particular path by suggesting that we do essentially what I would do with a list of numbers in maxima: diff(nums) := rest(nums,1) - rest(nums,-1) He probably just took that idea and ran with it to the [Lily-Scheme] goal-line. > you are well-prepared to figure out what I am doing, and what may > be hidden away in some of the internals of the read-made tools I use. What tools are those exactly? > it is seminal for me to tackle problems with the simplest means I can manage. I live (and die?) by the belief that "Every elegant question has an elegant answer". =) Thanks! Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Hi David, > \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 Okay, that’s basically what I was going to do "in the worst case situation". 1. I *was* hoping there was a "list->markup" macro/function somewhere… ;) 2. I have to admit that the final "build", i.e. > (markups (map >(lambda (elt) (make-simple-markup (number->string elt))) >ls))) > (interpret-markup layout props #{ \markup \line #markups #}))) is more compact than I had feared'; is usually true of the [good] Scheme code I come across. 3. I’m pretty sure I would have taken quite a while to find my way to "make-simple-markup" and "interpret-markup" — thanks for showing me that part of the fishing tackle box! > Hope this gets you started with whatever dodecaphonic plans you have... =) This dodecaphonic stuff is just an offshoot of one of my Salzburg sessions, which I’m using (because of its familiarity and proximity) as a way to jumpstart my Scheme learning process. Don’t worry: I’m not [currently] planning to rebuild Abjad in Scheme. ;) Thanks! Kieren. Kieren MacMillan, composer (he/him/his) ‣ website: www.kierenmacmillan.info ‣ email: i...@kierenmacmillan.info
Re: [Scheme coding] turning a list into a markup/string
Kieren MacMillan writes: > 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. ;) 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: %%% SNIPPET BEGINS \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 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 } %%% SNIPPET ENDS > 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. For teaching how to fish from scratch, Mike's demonstration may be better-suited. My solution is more a demonstration of what you can do when you know your way around the fishing grounds. I find it great that you understand everything that Mike does here: that's really involved stuff, and understanding it means that you are well-prepared to figure out what I am doing, and what may be hidden away in some of the internals of the read-made tools I use. At my advanced age, I tend to run into "eyes glaze over" territory pretty fast, so it is seminal for me to tackle problems with the simplest means I can manage. -- David Kastrup
Re: [Scheme coding] turning a list into a markup/string
Hi Kieren! On Tue, Jan 21, 2020 at 1:52 PM Kieren MacMillan 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