Consider the following code.

```
%!TEX program = lualatex
\documentclass[tikz]{standalone} 

\begin{document}

\pgfmathsetmacro{\sumk}{0}

\foreach \k in {1,2,...,10}{
  \pgfmathsetmacro{\sumk}{\k+\sumk}
  \directlua {print(\k,\sumk)}
}

\end{document}

```

In this simple example, I want to sum recursively from 1 to 10. This is just done to reproduce my problem: accessing a variable which is set within the loop in next loop iteration, and possibly accessing it also after the loop ended.

My expected output would be (in the log, written with lua `print`)

```
1   1.0
2   3.0
3   6.0
4   10.0
5   15.0
6   21.0
7   28.0
8   36.0
9   45.0
10  55.0

```

However, it is

```
1   1.0
2   2.0
3   3.0
4   4.0
5   5.0
6   6.0
7   7.0
8   8.0
9   9.0
10  10.0

```

Can a macro defined within the loop be reused later?