File: objectname.tex

package info (click to toggle)
sollya 7.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 13,864 kB
  • sloc: ansic: 117,441; yacc: 8,822; lex: 2,419; makefile: 870; cpp: 76
file content (128 lines) | stat: -rw-r--r-- 4,696 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
\subsection{objectname}
\label{labobjectname}
\noindent Name: \textbf{objectname}\\
\phantom{aaa}returns, given a \sollya object, a string that can be reparsed to the object\\[0.2cm]
\noindent Library name:\\
\verb|   sollya_obj_t sollya_lib_objectname(sollya_obj_t);|\\[0.2cm]
\noindent Usage: 
\begin{center}
\textbf{objectname}(\emph{obj}) : \textsf{any type} $\rightarrow$ \textsf{string}\\
\end{center}
\noindent Description: \begin{itemize}

\item \textbf{objectname}(\emph{obj}) queries the \sollya symbol table in order to recover the
   name of an identifier the object \emph{obj} is assigned to. If it succeeds, it
   returns a string containing the recovered identifier. In contrast, if it
   does not succeed, it returns a string simply containing a textual
   representation of~\emph{obj}.

\item The only condition for an identifier to be eligible to be returned by
   \textbf{objectname}(\emph{obj}) is to be accessible in the scope \textbf{objectname} is executed in,
   \emph{i.e.}, not to be shadowed by an identifier of the same name which does not
   hold the object \emph{obj}.

\item In any case, if the string returned by \textbf{objectname} is given to the \textbf{parse}
   command in the same scope, the original object \emph{obj} is recovered.

\item \textbf{objectname} is particularly useful in combination with \textbf{getbacktrace}, when
   the \sollya procedure stack is to be displayed in a fashion, where
   procedures are identified by their name and not their procedural content.

\item \textbf{objectname} may also be used to get a string representation of the free
   mathematical variable.

\item If an object is simply to be cast into a string, without trying to
   retrieve an identifier for it, \textbf{objectname} is not appropriate. In this case,
   it suffices to concatenate it to an empty string with the \textbf{@} operator.
\end{itemize}
\noindent Example 1: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> s = "Hello";
> objectname("Hello");
s
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 2: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> f = exp(x);
> g = sin(x);
> [| objectname(exp(x)), objectname(sin(x)), objectname(cos(x)) |];
[|"f", "g", "cos(x)"|]
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 3: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> o = { .f = exp(x), .I = [-1;1] };
> s1 = o@""; s1;
{ .f = exp(x), .I = [-1;1] }
> s2 = objectname({ .I = [-1;1], .f = exp(x)}); s2;
o
> parse(s1) == parse(s2);
true
> write("s2 = \"", s2, "\" parses to ", parse(s2), "\n");
s2 = "o" parses to { .f = exp(x), .I = [-1;1] }
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 4: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> n = 1664;
> objectname(n);
n
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 5: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> f = exp(x);
> g = sin(x);
> procedure test() {
      var f;
      var h;
      f = tan(x);
      h = cos(x);
      [| objectname(exp(x)), objectname(sin(x)), objectname(cos(x)), objectname(
tan(x)) |];
  };
> test();
[|"exp(x)", "g", "h", "f"|]
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 6: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> procedure apply_proc(p, a, b) {
      return p(a, b);
  };
> procedure show_trace_and_add(n, m) {
      var i, bt;
      bt = getbacktrace();
      write("Procedure stack:\n");
      for i from 0 to length(bt) - 1 do {
          write("   Procedure ", objectname((bt[i]).called_proc), " called with 
", length((bt[i]).passed_args), " arguments\n");
      };
      write("\n");
      return n + m;
  };
> procedure show_and_succ(u) {
        return apply_proc(show_trace_and_add, u, 1);
  };
> show_and_succ(16);
Procedure stack:
   Procedure show_trace_and_add called with 2 arguments
   Procedure apply_proc called with 3 arguments
   Procedure show_and_succ called with 1 arguments

17
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 7: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> f = exp(three_decker_sauerkraut_and_toadstool_sandwich_with_arsenic_sauce);
> g = sin(_x_);
> h = f(g);
> h;
exp(sin(three_decker_sauerkraut_and_toadstool_sandwich_with_arsenic_sauce))
> objectname(_x_);
three_decker_sauerkraut_and_toadstool_sandwich_with_arsenic_sauce
\end{Verbatim}
\end{minipage}\end{center}
See also: \textbf{parse} (\ref{labparse}), \textbf{var} (\ref{labvar}), \textbf{getbacktrace} (\ref{labgetbacktrace}), \textbf{proc} (\ref{labproc}), \textbf{procedure} (\ref{labprocedure}), \textbf{@} (\ref{labconcat})