lilypond-user
[Top][All Lists]
Advanced

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

Re: Guile library function availability


From: Jean Abou Samra
Subject: Re: Guile library function availability
Date: Mon, 24 May 2021 19:53:14 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

Le 24/05/2021 à 19:21, Lukas-Fabian Moser a écrit :
Hi,

during my experiments with TextSpanners I stumbled upon the following:

\version "2.22"

\layout {
  \override NoteHead.after-line-breaking =
  #(lambda (grob) (pretty-print "I explode."))
}

{
  a4
}

explodes because pretty-print isn't available (the same happens for functions like "last" etc.)

In contrast, the following works:

\version "2.22"

{
  \override NoteHead.after-line-breaking =
  #(lambda (grob) (pretty-print "I work just fine."))

  a4
}

What's the reason for the different availability of scheme library functions between working in \layout {} vs. in music?

I never understood the whole thing fully (and it is at the heart of the problem that led to disabling LilyPond on WikiMedia), but output definitions have their own scope, which is implemented as a Guile module. pretty-print is defined by another Guile module, (ice-9 pretty-print), which is generally available in LilyPond code because it is loaded upon initialization of LilyPond (see init.ly). last is in (srfi srfi-1), which is also loaded by default.

If you want these functions in a \layout, you have to load the corresponding module by hand:

\layout {
  #(use-modules (ice-9 pretty-print))
  \override NoteHead.after-line-breaking =
  #(lambda (grob) (pretty-print "I explode."))
}

{
  a4
}

Don't ask me why this works then:

#(define myVar 5)

\layout {
  #(display myVar)
}

It would seem that assignments work a bit differently from loading modules, but I'm not looking at the code right now.

Hope that helps,
Jean



reply via email to

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