[Aimmath-commit] AIM/WEB-INF/maple Console.mpl,1.4,1.5
Brought to you by:
gustav_delius,
npstrick
|
From: <mo...@us...> - 2003-09-19 20:21:27
|
Update of /cvsroot/aimmath/AIM/WEB-INF/maple
In directory sc8-pr-cvs1:/tmp/cvs-serv4298
Modified Files:
Console.mpl
Log Message:
added two debugging utilities: ShowTable and ShowTableProc
Index: Console.mpl
===================================================================
RCS file: /cvsroot/aimmath/AIM/WEB-INF/maple/Console.mpl,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Console.mpl 30 Aug 2003 21:01:45 -0000 1.4
--- Console.mpl 19 Sep 2003 04:08:00 -0000 1.5
***************
*** 144,148 ****
elif assigned(p["Dir"]) and assigned(p["QuestionName"]) then
questionfile := cat(subject['RootDir'],"/",p["Dir"],"/questions/",
! p["QuestionName"],".m"):
question := traperror(eval(AimCache['Load',questionfile]));
if question = lasterror then
--- 144,148 ----
elif assigned(p["Dir"]) and assigned(p["QuestionName"]) then
questionfile := cat(subject['RootDir'],"/",p["Dir"],"/questions/",
! p["QuestionName"],".m"):
question := traperror(eval(AimCache['Load',questionfile]));
if question = lasterror then
***************
*** 361,362 ****
--- 361,460 ----
`aim/AssignedNames`;
end:
+
+ ######################################################################
+ #
+ # AIM classes are Maple tables, and often have entries which are
+ # themselves tables or lists of tables. Maple does a poor job of
+ # formatting them when you ask it to print them (it wordwraps
+ # everything). This routine prints any Maple table in a
+ # more structured manner to aid in debugging.
+ #
+ # Syntax: ShowTable(T)
+ # - prints any expression T. The other two arguments are used
+ # internally by the routine and normally should be ommitted
+ # by the user. The bodies of procedures are omitted.
+ #
+ ShowTable:=proc(T,_indent,startonnewline)
+ local i,indent,spaces;
+
+ indent:=0;
+ if nargs>1 then indent:=_indent; fi;
+ spaces:=cat(" "$indent);
+ if nargs>2 then
+ printf(cat("\n",spaces));
+ fi:
+
+ if type(T,procedure) then
+ ShowTable("proc() ... end");
+ elif type(T,list) then
+ if hastype(T,table) then
+ ShowTable("[");
+ for i to nops(T)-1 do
+ ShowTable(T[i],indent+2,true);
+ printf(",");
+ od:
+ ShowTable(T[-1],indent+2,true);
+ ShowTable("]",indent,true);
+ else
+ ShowTable(sprintf("%a",T));
+ fi:
+ elif type(T,table) then
+ ShowTable("table(");
+ for i in [indices(T)] do
+ ShowTable(sprintf("%a = ",op(i)),indent+2,true);
+ ShowTable(T[op(i)],indent+2);
+ od;
+ ShowTable(")",indent,true);
+ else
+ if type(T,string) then
+ printf("%s",T);
+ else
+ printf("%a",T);
+ fi:
+ fi:
+ end:
+
+ ######################################################################
+ #
+ # ShowTableProc(T) is exactly the same as ShowTable, except that the
+ # bodies of procedures are not ommitted when printing T
+ #
+ ShowTableProc:=proc(T,_indent,startonnewline)
+ local i,indent,spaces;
+
+ indent:=0;
+ if nargs>1 then indent:=_indent; fi;
+ spaces:=cat(" "$indent);
+ if nargs>2 then
+ printf(cat("\n",spaces));
+ fi:
+
+ if type(T,procedure) then
+ print(T);
+ elif type(T,list) then
+ if hastype(T,table) then
+ ShowTableProc("[");
+ for i to nops(T)-1 do
+ ShowTableProc(T[i],indent+2,true);
+ printf(",");
+ od:
+ ShowTableProc(T[-1],indent+2,true);
+ ShowTableProc("]",indent,true);
+ else
+ ShowTableProc(sprintf("%a",T));
+ fi:
+ elif type(T,table) then
+ ShowTableProc("table(");
+ for i in [indices(T)] do
+ ShowTableProc(sprintf("%a = ",op(i)),indent+2,true);
+ ShowTableProc(T[op(i)],indent+2);
+ od;
+ ShowTableProc(")",indent,true);
+ else
+ if type(T,string) then
+ printf("%s",T);
+ else
+ printf("%a",T);
+ fi:
+ fi:
+ end:
|