lilypond-user
[Top][All Lists]
Advanced

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

Re: output some string


From: Gianmaria Lari
Subject: Re: output some string
Date: Fri, 15 Jun 2018 22:37:02 +0200



On Fri, 15 Jun 2018 at 20:12, Aaron Hill <address@hidden> wrote:
On 2018-06-15 09:40, Gianmaria Lari wrote:
> I'm trying to write some code in scheme. At the moment I do it using
> frescobaldi and I need some help for the output.
> The following code
>
> \version "2.19.81"
> #(define (f w) w)
> $(f "Hello")
>
>
> generates a pdf file containing "Hello".
>
> If my function f is called passing something that is not a string like
> in
> the following code
>
> \version "2.19.81"
> #(define (f w) w)
> $(f '(a b c))
>
>
> it doesn't work. How can I convert my data to a string?
>
> Thank you, g.
> P.S. I have been able to write in the Lilypond log using  #(define (f
> w)
> (write w))...

You might want to look at the `format` function:

https://www.gnu.org/software/guile/manual/html_node/Formatted-Output.html

This gives you quite a few options for formatting data and getting a
string.

`pretty-print` can also be useful if you want to dump an arbitrary
_expression_ to the output.  You have to jump through a few hoops, though,
to get its output as a string:

%%%%
   \version "2.19.81"
   #(define (pretty-print-to-string arg)
     (let ((o (open-output-string)) (s ""))
       (pretty-print arg o)
       (set! s (get-output-string o))
       (close-output-port o)
       s))
   $(pretty-print-to-string '(a b #(c d e) f . g))
%%%%


-- Aaron Hill


I tried pretty-print and it does the simple things I need. 
I also had a look to the format function but that's too much. I;ll probably need it in 10-15 years.... :)
Thanks a lot Aaron!

reply via email to

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