pattdefn.red 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. module pattdefn; %Notational conveniences and low level routines for the
  2. % UNIFY code.
  3. % Author: Kevin McIsaac.
  4. % Changes by Rainer M. Schoepf 1991.
  5. fluid('(freevars op r p i upb
  6. identity expand acontract mcontract comb count symm ))$
  7. % Binding routines. These would be more efficient with a more direct
  8. % mechanism.
  9. symbolic procedure bind(u, v); %push the value of v onto the
  10. put(u,'binding,v.get(u,'binding))$ %binding stack of u
  11. symbolic procedure binding(u); %Top most binding on stack
  12. (lambda x; if x then car x) get(u,'binding)$
  13. symbolic procedure unbind(u); %pop binding off stack
  14. put(u,'binding, cdr get(u,'binding))$
  15. symbolic procedure newenv(u); % Mark a new environment.
  16. bind(u, 'unbound)$ % Give UNIFY lexical scoping.
  17. symbolic procedure restorenv(u); % Should include error checks?
  18. unbind(u)$
  19. symbolic procedure pm!:free(u); % Is u a pm unbound free variable?
  20. binding(u) eq 'unbound$
  21. symbolic procedure bound(u); % Is u a pm bound free variable?
  22. (lambda x; x and (x neq 'unbound)) binding u;
  23. symbolic procedure meq(u,v);
  24. (lambda x;
  25. % (if (x and (x neq 'unbound)) then x else u) eq meval v )
  26. (if (x and (x neq 'unbound)) then x else u) = v)
  27. binding u;
  28. % This has been fixed.
  29. % symbolic procedure meval(u);
  30. % if eqcar(u,'minus) and numberp cadr u then -cadr u else u;
  31. % Currently Mval does nothing. It should be defined so that nosimp
  32. % functions are handled properly. By leaving it out the PM will not
  33. % dynamically change pattern it is working on. I.e.,
  34. % m(f(1,2,3+c),f(?a,?b,?a+?b+?c)) will now return True. If the code
  35. % commented out is restored then this will give the expected result.
  36. % However m(f(1_=natp 1),f(?a_=natp ?a)), where natp(?x) :- t, will not
  37. % work.
  38. symbolic procedure mval(u); u;
  39. %===> if not atom u then (reval bsubs(car u)) . cdr u
  40. %===> else bsubs u;
  41. symbolic procedure bsubs(u);
  42. % Replaces free atoms by their bindings. Would be nice to mark
  43. % expressions that no longer contain bunbound free variables
  44. if null u then u
  45. else if atom u then if bound(u) then binding u else u
  46. else for each j in u collect bsubs j;
  47. symbolic procedure ident(op);
  48. get(op,'identity)$
  49. symbolic procedure genp(u);
  50. atom u and (get(u,'gen) or mgenp(u))$
  51. symbolic procedure mgenp(u);
  52. atom u and get(u,'mgen)$
  53. symbolic procedure suchp u; %Is this a such that condition?
  54. not atom u and car u eq 'such!-that$
  55. % False if any SUCH conditions are in wich all free variable are bound
  56. % does not simplify to T. Should we return free expressions partially
  57. % simplified?
  58. symbolic procedure chk u;
  59. null u or u eq t or
  60. (lambda x;
  61. if freexp(x) then
  62. (lambda y; if null y then nil
  63. else if y eq t then list x
  64. else x.y) chk(cdr u)
  65. else if reval(x) eq t then chk(cdr u) else nil) bsubs car u$
  66. symbolic procedure findnewvars u;
  67. if atom u then if genp u then list u else nil
  68. else for each j in u conc findnewvars j;
  69. symbolic procedure freexp u;
  70. if atom u then pm!:free u else freexp car u or freexp cdr u;
  71. symbolic procedure genexp u;
  72. if atom u then genp u else genexp car u or genexp cdr u;
  73. endmodule;
  74. end;