aboutsummaryrefslogtreecommitdiff
path: root/Tools/MathematicaMisc
diff options
context:
space:
mode:
authorianhin <ianhin>2006-02-23 03:15:12 +0000
committerianhin <ianhin>2006-02-23 03:15:12 +0000
commit4c8fa0a57c89a705a1cd5e6722e9672bde3e248e (patch)
treef3eca706012ecb00dfa3b56fc1ed01bdbcda8b0c /Tools/MathematicaMisc
parentd550b283a8f585585150969a65b506d7149ddc69 (diff)
Added functions to verify that objects have the correct type. Helpful
in error checking the user's input and catching bugs as soon as possible. Also introduced the function InfoMessage to control the screen output that Kranc produces. The user can set the level of output required by SetDebugLevel with Quiet, Terse, Info or Full.
Diffstat (limited to 'Tools/MathematicaMisc')
-rw-r--r--Tools/MathematicaMisc/Errors.m45
1 files changed, 42 insertions, 3 deletions
diff --git a/Tools/MathematicaMisc/Errors.m b/Tools/MathematicaMisc/Errors.m
index b7c38b2..8edde3a 100644
--- a/Tools/MathematicaMisc/Errors.m
+++ b/Tools/MathematicaMisc/Errors.m
@@ -4,9 +4,21 @@ BeginPackage["Errors`"];
PrintError::usage = "";
ThrowError::usage = "";
KrancError::usage = "";
+VerifyString;
+VerifyStringList;
+VerifyList;
+InfoMessage;
+
+Quiet = 0;
+Warnings = 1
+Terse = 2;
+Info = 3;
+Full = 4;
Begin["`Private`"];
+debugLevel = Terse;
+
removeBits[l_] :=
Module[{s, t},
@@ -22,9 +34,12 @@ PrintStructure[x_]:=
PrintStructure[l_List, prefix_, suffix_] :=
Module[{},
- Print[prefix, "{"];
- Map[PrintStructure[#, " " <> prefix, ","] &, l];
- Print[prefix, "}"]];
+ If[StringLength[ToString[l] <> prefix] > 50,
+ Print[prefix, "{"];
+ Map[PrintStructure[#, " " <> prefix, ","] &, l];
+ Print[prefix, "}"],
+
+ Print[prefix, ToString[l,OutputForm]]]];
PrintStructure[s_, prefix_, suffix_] :=
Print[prefix, s, suffix];
@@ -49,6 +64,30 @@ ThrowError[objects__] :=
s2 = removeBits[s];
Throw[KrancError[{objects}, s2], KrancError]];
+
+VerifyString[s_] :=
+ If[! StringQ[s],
+ ThrowError["Not a string:", s]];
+
+VerifyStringList[l_] :=
+ If[! MatchQ[l, {___String}],
+ ThrowError["Not a list of strings:", l]];
+
+
+VerifyList[l_] :=
+ If[!Head[l] === List,
+ ThrowError["Not a list:", l]];
+
+
+InfoMessage[level_, message__] :=
+ Module[{args = {message}},
+ If[level <= debugLevel,
+ Map[PrintStructure, args]];
+ ];
+
+SetDebugLevel[level_] :=
+ debugLevel = level;
+
End[];
EndPackage[];