Hi,

On Tue, Nov 23, 2021 at 5:36 PM Dimitris Marinakis <[email protected]>
wrote:

> Thank you both for the information.
>
> I wasn't aware of the formatted output to be honest.
>
> \markup #(format #f "result = ~a" (dostuff 47))
>
>
> This line of code doesn't make any sense to me currently but when I get
> into more complex stuff I'll try to understand it. Right now I'm trying to
> build up a sensibility for basic programming principles because this is my
> first attempt at programming. Lilypond is so important to me that I need to
> be able to craft some solutions by myself.
>
> Best,
> Dimitris
>

There’s a lot of useful information - including the usage of format - in
the Guile 1.8 manual:
https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/index.html

David N.


> On Wed, Nov 24, 2021 at 1:08 AM Aaron Hill <[email protected]>
> wrote:
>
>> On 2021-11-23 2:56 pm, Dimitris Marinakis wrote:
>> > Finally got to learn a bit of Scheme. I've made decent progress within
>> > the
>> > Scheme sandbox. Now I'm trying to integrate a few things within
>> > Lilypond.
>> >
>> > Let's say I have this function:
>> > #(define (dostuff x) (+ x 5))
>> >
>> > What would be the equivalent of #(display (dostuff 2)) but inside a
>> > Lilypond markup?
>> > So that if my Lilypond music code looks like that, I'll get the correct
>> > value from that function.
>> > {
>> > c^\markuptitle (placeholder) #2
>> > }
>> >
>> > I don't want the x argument to be displayed in the markup but rather
>> > the
>> > result of the function.
>> >
>> > It's OK if this has to be broken into multiple steps.
>>
>> One option is to format the output you want as a string and then include
>> that in \markup:
>>
>> ####
>> #(define (dostuff x) (+ x 5))
>> \markup #(format #f "result = ~a" (dostuff 47))
>> ####
>>
>> If you just need the value, you could use number->string.  But for
>> anything fancier, the formatted printing functionality is quite powerful
>> and worth learning:
>>
>> %%%%
>> \markup #(format #f "~{~a fish~^, ~}." '(one two red blue))
>> %%%%
>>
>>
>> -- Aaron Hill
>>
>

Reply via email to