\subsection{getbacktrace}
\label{labgetbacktrace}
\noindent Name: \textbf{getbacktrace}\\
\phantom{aaa}returns the list of \sollya procedures currently run\\[0.2cm]
\noindent Library name:\\
\verb|   sollya_obj_t sollya_lib_getbacktrace();|\\[0.2cm]
\noindent Usage: 
\begin{center}
\textbf{getbacktrace}() : \textsf{void} $\rightarrow$ \textsf{list}\\
\end{center}
\noindent Description: \begin{itemize}

\item The \textbf{getbacktrace} command allows the stack of \sollya procedures that are
   currently run to be inspected. When called, \textbf{getbacktrace} returns an
   ordered list of structures, each of which contains an element
   \verb|passed_args| and an element \verb|called_proc|. The element \verb|called_proc|
   contains the \sollya object representing the procedure being run. The
   element \verb|passed_args| contains an ordered list of all effective
   arguments passed to the procedure when it was called. The procedure called
   last (\emph{i.e.}, on top of the stack) comes first in the list returned
   by \textbf{getbacktrace}. When any of the procedure called takes no arguments, the
   \verb|passed_args| element of the corresponding structure evaluates to an empty
   list.

\item When called from outside any procedure (at toplevel), \textbf{getbacktrace} returns
   an empty list.

\item When called for a stack containing a call to a variadic procedure that was
   called with an infinite number of effective arguments, the corresponding
   \verb|passed_args| element evaluates to an end-elliptic list.
\end{itemize}
\noindent Example 1: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> procedure testA() {
        "Current backtrace:";
        getbacktrace();
  };
> procedure testB(X) {
        "X = ", X;
        testA();
  };
> procedure testC(X, Y) {
        "X = ", X, ", Y = ", Y;
        testB(Y);
  };
> testC(17, 42);
X = 17, Y = 42
X = 42
Current backtrace:
[|{ .passed_args = [| |], .called_proc = proc()
{
"Current backtrace:";
getbacktrace();
return void;
} }, { .passed_args = [|42|], .called_proc = proc(X)
{
"X = ", X;
testA();
return void;
} }, { .passed_args = [|17, 42|], .called_proc = proc(X, Y)
{
"X = ", X, ", Y = ", Y;
testB(Y);
return void;
} }|]
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 2: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> getbacktrace();
[| |]
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 3: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> procedure printnumargs(X) {
        var L, t;
        "number of arguments: ", X;
        L = getbacktrace();
        "Backtrace:";
        for t in L do {
          "  " @ objectname(t.called_proc) @ ", ", t.passed_args;
        };
  };
> procedure numargs(l = ...) {
        "l[17] = ", l[17];
        printnumargs(length(l));
  };
> procedure test() {
        numargs @ [|25, 26, 27 ...|];
  };
> test();
l[17] = 42
number of arguments: infty
Backtrace:
  printnumargs, [|infty|]
  numargs, [|25, 26, 27...|]
  test, [| |]
\end{Verbatim}
\end{minipage}\end{center}
See also: \textbf{proc} (\ref{labproc}), \textbf{procedure} (\ref{labprocedure}), \textbf{objectname} (\ref{labobjectname}), \textbf{bind} (\ref{labbind}), \textbf{@} (\ref{labconcat})
