lilypond-user
[Top][All Lists]
Advanced

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

Questions about using Scheme with Lilypond


From: Tom Brennan
Subject: Questions about using Scheme with Lilypond
Date: Sun, 15 Nov 2020 15:03:17 -0500

I'd like to create a function that would allow me to create a `bookpart` from a list of arguments. E.g.,

```lilypond
\book {
\custom_bookpart "horn" \hn_movt_one \hn_movt_two
}
```

The reason is because I'd like to reuse header and page info, etc, without having to repeat those common variable names. I.e., replace this:

```lilypond
\book {
% clarinet
\bookpart {
\paper { ... }
\header {
...
instrument = \clarinet-name
}
\maestoso-clarinet-part
\scherzo-clarinet-part
}

% bassoon
\bookpart {
\paper { ... }
\header {
...
instrument = \bassoon-name
}
\maestoso-bassoon-part
\scherzo-bassoon-part
}
}
```

with this:

```lilypond
\book {
\part_bookpart \clarinet-name \maestoso-clarinet-part \scherzo-clarinet-part
\part_bookpart \horn-name \maestoso-hn-part \scherzo-hn-part
}
```


Is this kind of thing possible? I tried to create a music function, but I got hung up on a number of things:

1. You can't return a `bookpart` from a music function, and it looks like nothing happens when trying to return a `bookpart` from a scheme function/lambda, too:

```lilypond
custom_bookpart = #(lambda args #{ \bookpart {...} #})
\book {
#(custom_bookpart "horn" \hn_movt_one)
}
```

I guess I was under the impression that anything you can create in lilypond syntax can be created (also in some cases mutated?) in corresponding scheme code, but I'm having a hard time figuring out how to inspect the objects that result from various expressions (lilypond or scheme). E.g.,

```
custom_bookpart = #(lambda _ #{ \bookpart { ... } #})
#(display (custom_bookpart))
```

displays: #<Book>

Where do I find documentation about what a #<Book> is, and/or how do I inspect its properties, etc.? Can I mutate this (i.e., add/remove bookparts)? Why don't I get a #<BookPart> instead? It also seems like I should be able to use this function as an _expression_ in my book definition, but it doesn't work.

2. Applying variadic arguments (i.e., "splat"). E.g., in Clojure, you can do something like this:

```clojure
(defmacro foo [& body]
`(+ 1 ~@body))

(macroexpand '(foo 2 3 4))
=> (+ 1 2 3 4)
```

I tried using `custom_bookpart = #(lambda args ...)` like:
```lilypond
custom_bookpart = #(lambda args
#{
\bookpart {
\header { instrument = #(car args) }
#(cdr args)
}
#})
```

but you can't just throw a list in right there, right? It would need to be expanded, in the `apply` sense. I assume Guile has macros, like Clojure, but I don't know how to use them yet. Would that path lead me to success here, though?

Thanks
Tom

reply via email to

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