depend.red 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. module depend; % Defining and checking expression dependency.
  2. % Author: Anthony C. Hearn.
  3. % Modifications by: Francis J. Wright <F.J.Wright@qmw.ac.uk>.
  4. % Copyright (c) 1996 The RAND Corporation. All rights reserved.
  5. fluid '(alglist!* depl!* frlis!*);
  6. % DEPL* is a list of dependencies among kernels.
  7. symbolic procedure depend u;
  8. depend0(u,t);
  9. symbolic procedure nodepend u;
  10. <<rmsubs(); depend0(u,nil)>>;
  11. rlistat '(depend nodepend);
  12. %symbolic procedure depend0(u,bool);
  13. % % We need to include both <id> and <id>_ in the list to provide for
  14. % % ROOT_OF expressions.
  15. % <<for each x in cdr u do depend1(car u,x,bool);
  16. % if idp car u
  17. % then (for each x in cdr u do depend1(y,x,bool))
  18. % where y=intern compress append(explode car u,'(!! !_))>>;
  19. symbolic procedure depend1(u,v,bool);
  20. begin scalar y,z;
  21. u := !*a2k u;
  22. v := !*a2k v;
  23. if u eq v then return nil;
  24. y := assoc(u,depl!*);
  25. % if y then if bool then rplacd(y,union(list v,cdr y))
  26. % else if (z := delete(v,cdr y)) then rplacd(y,z)
  27. if y then if bool
  28. then depl!*:= repasc(car y,union(list v,cdr y),depl!*)
  29. else if (z := delete(v,cdr y))
  30. then depl!* := repasc(car y,z,depl!*)
  31. else depl!* := delete(y,depl!*)
  32. else if null bool
  33. then lprim list(u,"has no prior dependence on",v)
  34. else depl!* := list(u,v) . depl!*
  35. end;
  36. symbolic procedure depends(u,v);
  37. if null u or numberp u or numberp v then nil
  38. else if u=v then u
  39. else if atom u and u memq frlis!* then t
  40. %to allow the most general pattern matching to occur;
  41. else if (lambda x; x and ldepends(cdr x,v)) assoc(u,depl!*)
  42. then t
  43. else if not atom u and idp car u and get(car u,'dname) then
  44. (if depends!-fn then apply2(depends!-fn,u,v) else nil)
  45. where (depends!-fn = get(car u,'domain!-depends!-fn))
  46. else if not atom u
  47. and (ldepends(cdr u,v) or depends(car u,v)) then t
  48. else if atom v or idp car v and get(car v,'dname) then nil
  49. % else dependsl(u,cdr v);
  50. else nil;
  51. symbolic procedure ldepends(u,v);
  52. % Allow for the possibility that U is an atom.
  53. if null u then nil
  54. else if atom u then depends(u,v)
  55. else depends(car u,v) or ldepends(cdr u,v);
  56. symbolic procedure dependsl(u,v);
  57. v and (depends(u,car v) or dependsl(u,cdr v));
  58. symbolic procedure freeof(u,v);
  59. not(smember(v,u) or v member assoc(u,depl!*));
  60. symbolic operator freeof;
  61. flag('(freeof),'boolean);
  62. % infix freeof;
  63. % precedence freeof,lessp; %put it above all boolean operators;
  64. % This following code, by Francis J. Wright, enhances the depend and
  65. % nodepend commands. If the first argument is an (algebraic) LIST
  66. % then change the dependency for each element of it, i.e.
  67. % (no)depend {y1, y2, ...}, x1, x2, ... maps to
  68. % (no)depend y1, x1, x2, ...; (no)depend y2, x1, x2, ...; ...
  69. % Also allow a sequence of such dependence sequences, where the
  70. % beginning of each new sequence is indicated by a LIST of one or more
  71. % dependent variables.
  72. symbolic procedure depend0(u, bool);
  73. % u = y,x1,x2,..., {yy1,yy2,...},xx1,xx2,..., OR
  74. % u = {y1,y2,...},x1,x2,..., {yy1,yy2,...},xx1,xx2,...,
  75. <<alglist!* := nil . nil; % We need to clear cache.
  76. while u do
  77. begin scalar v;
  78. % Make v point to the next dependent variable list or nil.
  79. v := cdr u;
  80. while v and not rlistp car v do v := cdr v;
  81. for each y in (if rlistp car u then cdar u else {car u}) do
  82. begin scalar x;
  83. x := u;
  84. while not((x := cdr x) eq v) do depend1(y,car x,bool);
  85. if idp y
  86. then <<y := intern compress append(explode y,'(!! !_));
  87. x := u;
  88. while not((x := cdr x) eq v) do
  89. depend1(y,car x,bool)>>
  90. end;
  91. u := v
  92. end>>;
  93. endmodule;
  94. end;