reset.red 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. module reset; % Code to reset REDUCE to the initial state.
  2. % John Fitch, Codemist Ltd 1988 <jpff@maths.bath.ac.uk>
  3. % Given to the REDUCE community for what it is worth.
  4. % Revised August 1995 for Reduce 3.6.
  5. %
  6. create!-package('(reset),'(contrib misc));
  7. % The command RESETREDUCE works through the history of previous
  8. % commands, and clears any values which have been assigned, plus any
  9. % rules, arrays and the like. It also sets the various switches to
  10. % their initial values. It is not complete, but does work for most
  11. % things that cause a gradual loss of space. It would be relatively
  12. % easy to make it interactive, so allowing for selective resetting.
  13. symbolic procedure resetreduce;
  14. begin
  15. scalar mode,statno,comm;
  16. % Set all switches back to initial values
  17. % These may vary from system to system!!
  18. !*algint:=nil; !*adjprec:=nil; !*allbranch:=nil; !*allfac:=t;
  19. !*arbvars:=nil; !*asterisk:=t; !*backtrace:=nil;
  20. !*balanced_mod:=nil; !*bfspace:=nil; !*combineexpt:=nil;
  21. !*combinelogs:=nil; !*comp:=nil; !*complex:=nil;
  22. !*compxroots:=nil; !*cramer:=nil; !*cref:=nil; !*defn:=nil;
  23. !*demo:=nil; !*dfprint:=nil; !*div:=nil; !*echo:=nil;
  24. !*errcont:=nil; !*evallhseqp:=nil; !*exp:=t;
  25. !*expandexpt:=t; !*expandlogs:=nil; !*ezgcd:=nil;
  26. !*factor:=nil; !*fastfor:=nil; !*force:=nil; !*fort:=nil;
  27. !*fortupper:=nil; !*fullprec:=nil;!*fullprecision:=nil;
  28. !*fullroots:=nil; !*gcd:=nil; !*heugcd:=nil; !*horner:=nil;
  29. !*ifactor:=nil; !*int:=nil; !*intstr:=nil; !*lcm:=t;
  30. !*lessspace:=nil; !*limitedfactors:=nil; !*list:=nil;
  31. !*listargs:=nil; !*lower:=t; !*mcd:=t; !*modular:=nil;
  32. !*msg:=t; !*multiplicities:=nil; !*nat:=t;
  33. !*nero:=nil; !*noarg:=t; !*noconvert:=nil; !*nonlnr:=nil;
  34. !*nosplit:=t; !*numval:=t; !*output:=t; !*period:=t;
  35. !*pgwd:=nil; !*plap:=nil; !*precise:=t;
  36. !*pret:=nil; !*pri:=t; !*pwrds:=t;
  37. !*quotenewnam:=t; !*raise:=nil; !*rat:=nil; !*ratarg:=nil;
  38. !*rational:=nil; !*rationalize:=nil; !*ratpri:=t;
  39. !*reduced:=nil; !*revpri:=nil; !*rlisp88:=nil; !*rootmsg:=nil;
  40. !*roundall:=t; !*roundbf:=nil; !*rounded:=nil; % !*savedef:=nil;
  41. !*savestructr:=nil; !*solvesingular:=nil; !*time:=nil;
  42. !*trallfac:=nil; !*trfac:=nil; !*trint:=nil; !*trroot:=nil;
  43. % Now work down previous inputs
  44. foreach stat in inputbuflis!* do <<
  45. statno:=car stat;
  46. mode:=cadr stat;
  47. comm:=caddr stat;
  48. % princ "Dealing with input "; princ statno;
  49. % princ " in mode "; print mode;
  50. % prin2t comm;
  51. % princ "car comm="; prin2t car comm;
  52. if mode='algebraic then algreset(comm)
  53. else if mode='symbolic then symbreset(comm)
  54. >>;
  55. inputbuflis!*:=nil
  56. end;
  57. symbolic procedure algreset(comm);
  58. begin scalar forallfn;
  59. if atom comm then return nil;
  60. forallfn:='forall;
  61. if car comm='setk then remprop(cadadr comm,'avalue)
  62. else if car comm='arrayfn then
  63. foreach y in cdaddr comm do <<
  64. remprop(cadadr y,'dimension);
  65. remprop(cadadr y,'rvalue);
  66. remprop(cadadr y,'rtype) >>
  67. else if car comm='progn then foreach y in cdr comm do algreset(y)
  68. else if car comm='prog then foreach y in cdr comm do algreset(y)
  69. else if car comm='setq then nil
  70. else if car comm='go then nil
  71. else if car comm='cond then
  72. foreach y in cdr comm do <<
  73. algreset(car comm); algreset(cadr comm) >>
  74. else if car comm='flag then eval('remflag . (cdr comm))
  75. else if car comm='de then remd cadr comm
  76. else if car comm='let then
  77. foreach xx in cdadr comm do clear car cdaddr xx
  78. else if car comm='clear then nil
  79. else if car comm='forall and caadr cadddr cadr comm = 'let then
  80. foreach xx in cdadr cadddr cadr comm do
  81. forallfn list(cadr cadadr comm,cadr cadr cdadr comm,
  82. list('clear, list('list, caddr cadr xx)))
  83. % else I do not know what to do!!
  84. end;
  85. symbolic procedure symbreset(comm);
  86. <<
  87. if car comm='setq then set(cadr comm,nil)
  88. else if car comm='progn then foreach y in cdr comm do symbreset(y)
  89. else if car comm='flag then eval('remflag . (cdr comm))
  90. else if car comm='de then remd cadr comm
  91. % else I do not know what to do!!
  92. >>;
  93. put('resetreduce,'stat,'endstat);
  94. endmodule;
  95. end;