Many thanks, Aaron. A clear and helpful answer!
The “why” was simply an exercise in seeing if I could cleanup a LP file by using such syntactic sugar (to which the answer is no :-) ). Thanks again ..m. > On 19 Dec 2023, at 07:05, Aaron Hill <lilyp...@hillvisions.com> wrote: > > On 2023-12-17 9:33 pm, Mark Probert wrote: >> Hi. >> I'm struggling some with writing a music function for rests. Basically I >> want to be able to write something like >> \rel-rest( b', 1) > > Minor nit: Functions in LilyPond do not use parentheses and commas for > arguments in this way. You need only say something like the following to > invoke your function: > > %%%% > \rel-rest b' 1 > %%%% > >> which would place a dotted quarter rest on the indicated pitch (the >> equivalent of >> b'1\rest >> I'm starting with >> rel-rest = >> #(define-music-function (pit dur) (ly:pitch? ly:duration?) >> #{ >> #pit#dur\rest >> #}) >> but that gives me an error. >> Any suggestions? > > There are a few things the errors in the output log should be communicating. > >> Unbound variable: #{pit\#dur\\rest}# > > Firstly, whitespace is important in Scheme. Jamming together #pit#dur\rest > gives the parser little hope to understand what you mean. It thinks this > refers to a singular named thing, which in this context does not exist. > > So, give each part of that expression some room to breathe: > > ;;;; > #pit #dur \rest > ;;;; > > But then LilyPond is not satisfied that this represents a valid music > expression. When using variables, often the number sign (#) is correct, > however there are some spots when you need to use the dollar sign ($) instead. > > ;;;; > $pit $dur \rest > ;;;; > > Lastly, I am not sure why using the duration "1" as you indicated would > result in a dotted quarter rest. Did you mean "4." or is the point of the > music function to manipulate the inputs in some way? I am not sure I see the > connection/logic there, so you are going to be a bit on your own there. > > But with the modification indicated above, you can now do this: > > %%%% > { \rel-rest b' 4. } > > %% ...or even... > > { \rel-rest b'4. } > %%%% > > However, this feels like more typing than just using the \rest post-event, > apart from being prefixed. > > > -- Aaron Hill