Hi,

I've run into a surprising edge case with \applyContext.
The example score below has Stem.length overridden in the layout block.
\applyContext is called before and after the first note, logging the value
of Stem.length to the standard output. I would expect both instances to
print the value set by the override, i.e. 0. But instead, the first call
prints the ly:stem::pure-calc-length function, i.e. the default value of
Stem.length.

If the first \applyContext call happens only after the first note, 0 is
printed as expected.
If the override is placed at the beginning of the music block rather than
in the layout block, an \applyContext call before the first note also sees
the new value as expected.

What am I missing? Why isn't the value set by \override in the layout block
visible at the very beginning of the score?

% MWE beginning ----------------
\version "2.24.1"

displayStemLength =
#(lambda (context)
   (let* ((grob-def (ly:context-grob-definition context 'Stem))
          (length (ly:assoc-get 'length grob-def)))
     (display "+ ")
     (display length)
     (newline)))

\score {
  \relative c'' {
    \applyContext #displayStemLength
    g4
    \applyContext #displayStemLength
    g
  }
  \layout {
    \override Stem.length = #0
  }
}
% MWE end --------------

Best regards,
Jakub

Reply via email to