weight.red 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module weight; % Asymptotic command package.
  2. % Author: Anthony C. Hearn.
  3. % Copyright (c) 1991 RAND. All rights reserved.
  4. % Modified by F.J. Wright@Maths.QMW.ac.uk, 18 May 1994,
  5. % mainly to return the previous settings rather than nothing.
  6. fluid '(asymplis!* wtl!*);
  7. flag('(k!*),'reserved);
  8. % Asymptotic list and weighted variable association lists.
  9. symbolic procedure weight u;
  10. % Returns previous weight list for the argument variables, omitting
  11. % any unweighted variables. Returns the current weight without
  12. % resetting it for any argument that is a variable rather than a
  13. % weight equation, and with no arguments returns all current
  14. % variable weights.
  15. makelist if null car u then
  16. for each x in wtl!* collect {'equal, car x, cdr x}
  17. else <<
  18. % Make sure asymplis!* is initialized.
  19. if null atsoc('k!*,asymplis!*)
  20. then asymplis!* := '(k!* . 2) . asymplis!*;
  21. rmsubs();
  22. % Build the output list while processing the input:
  23. for each x in u join
  24. begin scalar y,z;
  25. if eqexpr x then <<
  26. z := reval caddr x;
  27. if not fixp z or z<=0 then typerr(z,"weight");
  28. x := cadr x >>;
  29. y := !*a2kwoweight x;
  30. x := if (x := atsoc(y,wtl!*)) then {{'equal, car x, cdr x}};
  31. if z then wtl!* := (y . z) . delasc(y,wtl!*);
  32. return x
  33. end
  34. >>;
  35. symbolic procedure wtlevel n;
  36. begin scalar oldn;
  37. % Returns previous wtlevel; with no arg returns current wtlevel
  38. % without resetting it.
  39. oldn := (if x then cdr x - 1 else 1)
  40. where x = atsoc('k!*,asymplis!*);
  41. if car n then <<
  42. n := reval car n;
  43. if not fixp n or n<0 then typerr(n,"weight level");
  44. if n<oldn then rmsubs();
  45. if n neq oldn
  46. then asymplis!*:= ('k!* . (n+1)) . delasc('k!*,asymplis!*)>>;
  47. return oldn
  48. end;
  49. rlistat '(weight wtlevel);
  50. % but preserve current mode as mode of result:
  51. flag('(weight wtlevel), 'nochange);
  52. % algebraic let k!***2=0;
  53. endmodule;
  54. end;