switch.red 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. module switch; % Support for switches and ON and OFF statements.
  2. % Author: Anthony C. Hearn.
  3. % Copyright (c) 1991 The RAND Corporation. All rights reserved.
  4. global '(!*switchcheck switchlist!*);
  5. % No references to RPLAC-based functions in this module.
  6. symbolic procedure on u; for each j in u do on1 j;
  7. symbolic procedure off u; for each j in u do off1 j;
  8. symbolic procedure off1 u; onoff(u,nil);
  9. symbolic procedure on1 u; onoff(u,t);
  10. symbolic procedure onoff(u,bool);
  11. begin scalar x,y;
  12. if not idp u then typerr(u,"switch")
  13. else if not flagp(u,'switch)
  14. % then if !*switchcheck
  15. then rerror(rlisp,25,list(u,"not defined as switch"));
  16. % else lpriw("*****",list(u,"not defined as switch"));
  17. x := intern compress append(explode '!*,explode u);
  18. if !*switchcheck and lispeval x eq bool then return nil
  19. else if y := atsoc(bool,get(u,'simpfg))
  20. then lispeval('progn . append(cdr y,list nil));
  21. if bool and x eq '!*!r!a!i!s!e then x := '!*raise; % Special case.
  22. set(x,bool)
  23. end;
  24. symbolic procedure switch u;
  25. % Declare list u as switches.
  26. for each x in u do
  27. begin scalar y;
  28. if not idp x then typerr(x,"switch");
  29. if not(x memq switchlist!*)
  30. then switchlist!* := x . switchlist!*;
  31. flag(list x,'switch);
  32. y := intern compress append(explode '!*,explode x);
  33. if not fluidp y and not globalp y then fluid list y
  34. end;
  35. deflist('((switch rlis)),'stat); % we use deflist since it's flagged
  36. % eval
  37. flag('(switch),'eval);
  38. put('off,'stat,'rlis);
  39. put('on,'stat,'rlis);
  40. flag ('(off on),'ignore);
  41. % Symbolic mode switches:
  42. switch backtrace,comp,defn,demo,echo,errcont,fastfor, % eoldelimp
  43. int,lessspace,msg,output,pret,quotenewnam,raise,time;
  44. put('eoldelimp,'simpfg,'((t (flag (list !$eol!$) 'delchar))
  45. (nil (remflag (list !$eol!$) 'delchar))));
  46. % Support for REDUCE 4.
  47. switch reduce4;
  48. put('reduce4,'simpfg,'((t (load!-package 'reduce4) (!%reduce4))));
  49. endmodule;
  50. end;