{{ $posts := .Pages }}
{{ $nposts := len $posts }}
{{ $nposts := sub $nposts 9 }}
<h1>{{ $nposts }}</h1>
{{ range first 999 (after 9 .Pages.ByLastmod.Reverse) }}
<p>{{ .Title }}</p>
{{ end }}
<h1> is for debugging.
If I replace 999 with $nposts, which I assume stores an integer, or at least it prints out like one in <h1>, I get the following error:
executing "main" at <first $nposts (after 9 .Pages.ByLastmod.Reverse)>: error calling first: sequence length must be non-negative
Which is strange, since $nposts is a positive number that defines the number of posts minus those 9 that are rendered in the previous section. Unless I messed something up.
I tried casting $nposts to int, but the result is the same.
First, I think you can replace all of your code with:
{{ range after 9 .Pages.ByLastmod.Reverse }}
<p>{{ .Title }}</p>
{{ end }}
Second, with 9 or more published (not draft or future) pages, I cannot reproduce the error. With fewer than 9 pages, $nposts is a negative number, and first -n is nonsensical.
If your code is in a template used by multiple sections, each section must have 9 or more pages to avoid the error.