On Fri, 15 Jun 2018 at 20:12, Aaron Hill <[email protected]> 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!
_______________________________________________ lilypond-user mailing list [email protected] https://lists.gnu.org/mailman/listinfo/lilypond-user
