Hello Walt,

the type of function tells the parser what return type it expects from a 
function evaluation. A music function has to return music (which means that 
the parser will know before evaluation that some music would be there), a 
scheme function any type of scheme object. A void function is a spectial 
function that does not return anything (or more correctly that the parser 
knows to evaluate, but to do nothing with the return).

In your case you expect the function to return a toplevel header object, but 
you are telling the parser to ignore it, so you do not get anything from it. 
If you were to replace this by a scheme function the returned header would be 
properly handled by the parser.

One way to make use of the void function here would be to avoid relying on 
returning a header and having the parser apply it correctly, and instead do 
your own logic:

\version "2.24.4"

hdr =
#(define-void-function (name) (string?)
   (if (not $defaultheader)
       (set! $defaultheader #{ \header { } #}))
   (module-define! $defaultheader 'title name))

\hdr "test"

%\header { title = test }

\score {
{c4 d e f}
}


This might for example be useful when you want to change the global header 
from within a book or score.

Cheers,
Valentin

Am Dienstag, 1. Oktober 2024, 23:06:43 MESZ schrieb Walt North:
> I may be thinking about define-void-function incorrectly.  Here is a
> trimmed down example of what I was trying to do.  I want to have a
> callable function that sets up my \header.
> 
> There are other ways I could go about this to get what I want - but I
> originally thought this would be easy way to go and put the function in
> an include file. And if I can get this to work there are some things I
> could use the same type of approach on.
> 
> Here is the trimmed down same.  It does not produce any heading.
> 
> 
> Walt North
> 
> 
> \version "2.24.4"
> 
> hdr =
> #(define-void-function (name) (string?)
>     #{
>       \header {
>       title = #name
>       }
>     #})
> 
> \hdr "test"
> 
> %\header { title = test }
> 
> \score {
> {c4 d e f}
> }

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to