lilypond-user
[Top][All Lists]
Advanced

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

Re: output some string


From: Aaron Hill
Subject: Re: output some string
Date: Fri, 15 Jun 2018 11:11:08 -0700
User-agent: Roundcube Webmail/1.3.6

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



reply via email to

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