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
129
130
131
132
133
134
135
136
137
138
139
|
\documentclass{article}
\usepackage{axiom}
\begin{document}
\title{\$SPAD/src/algebra error.spad}
\author{Robert S. Sutor}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{package ERROR ErrorFunctions}
<<package ERROR ErrorFunctions>>=
)abbrev package ERROR ErrorFunctions
++ Author: Robert S. Sutor
++ Date Created: 29 May 1990
++ Date Last Updated: 29 May 1990
++ Description:
++ ErrorFunctions implements error functions callable from the system
++ interpreter. Typically, these functions would be called in user
++ functions. The simple forms of the functions take one argument
++ which is either a string (an error message) or a list of strings
++ which all together make up a message. The list can contain
++ formatting codes (see below). The more sophisticated versions takes
++ two arguments where the first argument is the name of the function
++ from which the error was invoked and the second argument is either a
++ string or a list of strings, as above. When you use the one
++ argument version in an interpreter function, the system will
++ automatically insert the name of the function as the new first
++ argument. Thus in the user interpreter function
++ \spad{f x == if x < 0 then error "negative argument" else x}
++ the call to error will actually be of the form
++ \spad{error("f","negative argument")}
++ because the interpreter will have created a new first argument.
++
++ Formatting codes: error messages may contain the following
++ formatting codes (they should either start or end a string or
++ else have blanks around them):
++ \spad{%l} start a new line
++ \spad{%b} start printing in a bold font (where available)
++ \spad{%d} stop printing in a bold font (where available)
++ \spad{ %ceon} start centering message lines
++ \spad{%ceoff} stop centering message lines
++ \spad{%rjon} start displaying lines "ragged left"
++ \spad{%rjoff} stop displaying lines "ragged left"
++ \spad{%i} indent following lines 3 additional spaces
++ \spad{%u} unindent following lines 3 additional spaces
++ \spad{%xN} insert N blanks (eg, \spad{%x10} inserts 10 blanks)
++
++ Examples:
++ 1. \spad{error "Whoops, you made a %l %ceon %b big %d %ceoff %l mistake!"}
++ 2. \spad{error ["Whoops, you made a","%l %ceon %b","big",
++ "%d %ceoff %l","mistake!"]}
ErrorFunctions() : Exports == Implementation where
Exports ==> with
error: String -> Exit
++ error(msg) displays error message msg and terminates.
error: List String -> Exit
++ error(lmsg) displays error message lmsg and terminates.
error: (String,String) -> Exit
++ error(nam,msg) displays error message msg preceded by a
++ message containing the name nam of the function in which
++ the error is contained.
error: (String,List String) -> Exit
++ error(nam,lmsg) displays error messages lmsg preceded by a
++ message containing the name nam of the function in which
++ the error is contained.
Implementation ==> add
prefix1 : String := "Error signalled from user code: %l "
prefix2 : String := "Error signalled from user code in function %b "
doit(s : String) : Exit ==
throwPatternMsg(s,nil$(List String))$Lisp
-- there are no objects of type Exit, so we'll fake one,
-- knowing we will never get to this step anyway.
"exit" pretend Exit
error(s : String) : Exit ==
doit concat [prefix1,s]
error(l : List String) : Exit ==
s : String := prefix1
for x in l repeat s := concat [s," ",x]
doit s
error(fn : String,s : String) : Exit ==
doit concat [prefix2,fn,": %d %l ",s]
error(fn : String, l : List String) : Exit ==
s : String := concat [prefix2,fn,": %d %l"]
for x in l repeat s := concat [s," ",x]
doit s
@
\section{License}
<<license>>=
--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
-- - Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
--
-- - Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in
-- the documentation and/or other materials provided with the
-- distribution.
--
-- - Neither the name of The Numerical ALgorithms Group Ltd. nor the
-- names of its contributors may be used to endorse or promote products
-- derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@
<<*>>=
<<license>>
<<package ERROR ErrorFunctions>>
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}
|