reset.red 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. % 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. %
  5. % The command RESETREDUCE works through the history of previous
  6. % commands, and clears any values which have been assigned, plus any
  7. % rules, arrays and the like. It also sets the various switches to
  8. % their initial values. It is not complete, but does work for most
  9. % things that cause a gradual loss of space. It would be relatively
  10. % easy to make it interactive, so allowing for selective resetting.
  11. symbolic procedure resetreduce;
  12. begin
  13. scalar mode,statno,comm;
  14. % Set all switches back to initial values
  15. % These may vary from system to system!!
  16. !*algint:=nil; !*allbranch:=t; !*allfac:=t; !*backtrace:=nil;
  17. !*comp:=nil; !*complex:=nil; !*convert:=t;
  18. !*cramer:=nil; !*cref:=nil; !*defn:=nil; !*demo:=nil;
  19. !*div:=nil; !*echo:=nil; !*errcont:=nil; !*exp:=t;
  20. !*ezgcd:=nil; !*factor:=nil; !*failhard:=nil;
  21. !*fort:=nil; !*gcd:=nil; !*heugcd:=nil; !*ifactor:=nil;
  22. !*int:=t; !*intstr:=nil; !*lcm:=t; !*list:=nil;
  23. !*mcd:=t; !*modular:=nil; !*msg:=t; !*nat:=t;
  24. !*nero:=nil; !*nolnr:=nil; !*numval:=nil; !*output:=t;
  25. !*overview:=nil; !*period:=t; !*pgen:=nil; !*pgwd:=nil;
  26. !*plap:=nil; !*precise:=nil; !*pret:=nil; !*pri:=t;
  27. !*pwrds:=t; !*quotenewnam:=t;!*raise:=t; !*rat:=nil;
  28. !*ratarg:=nil; !*rational:=nil; !*rationalize:=nil;
  29. !*ratpri:=t; !*reduced:=nil; !*revpri:=nil; !*savestructr:=nil;
  30. !*solvesingular:=t;!*time:=nil; !*timings:=nil; !*trallfac:=nil;
  31. !*trfac:=nil; !*trint:=nil; !*rounded := nil;
  32. % Now work down previous inputs
  33. foreach stat in inputbuflis!* do <<
  34. statno:=car stat;
  35. mode:=cddr stat;
  36. comm:=cadr stat;
  37. % princ "Dealing with input "; princ statno;
  38. % princ " in mode "; print mode;
  39. % prin2t comm;
  40. % princ "car comm="; prin2t car comm;
  41. if mode='algebraic then algreset(comm)
  42. else if mode='symbolic then symbreset(comm)
  43. >>;
  44. inputbuflis!*:=nil
  45. end;
  46. symbolic procedure algreset(comm);
  47. begin scalar forallfn;
  48. if atom comm then return nil;
  49. forallfn:='forall;
  50. if car comm='setk then remprop(cadadr comm,'avalue)
  51. else if car comm='arrayfn then
  52. foreach y in cdaddr comm do <<
  53. remprop(cadadr y,'dimension);
  54. remprop(cadadr y,'rvalue);
  55. remprop(cadadr y,'rtype) >>
  56. else if car comm='progn then foreach y in cdr comm do algreset(y)
  57. else if car comm='prog then foreach y in cdr comm do algreset(y)
  58. else if car comm='setq then nil
  59. else if car comm='go then nil
  60. else if car comm='cond then
  61. foreach y in cdr comm do <<
  62. algreset(car comm); algreset(cadr comm) >>
  63. else if car comm='flag then eval('remflag . (cdr comm))
  64. else if car comm='de then remd cadr comm
  65. else if car comm='let then
  66. foreach xx in cdadr comm do clear car cdaddr xx
  67. else if car comm='clear then nil
  68. else if car comm='forall and caadr cadddr cadr comm = 'let then
  69. foreach xx in cdadr cadddr cadr comm do
  70. forallfn list(cadr cadadr comm,cadr cadr cdadr comm,
  71. list('clear, list('list, caddr cadr xx)))
  72. % else I do not know what to do!!
  73. end;
  74. symbolic procedure symbreset(comm);
  75. <<
  76. if car comm='setq then set(cadr comm,nil)
  77. else if car comm='progn then foreach y in cdr comm do symbreset(y)
  78. else if car comm='flag then eval('remflag . (cdr comm))
  79. else if car comm='de then remd cadr comm
  80. % else I do not know what to do!!
  81. >>;
  82. put('resetreduce,'stat,'endstat);
  83. end;