property-list.red 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. %
  2. % PROPERTY-LIST.RED - Functions dealing with property lists
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 17 August 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % <PSL.INTERP>PROPERTY-LIST.RED.11, 1-Mar-82 14:09:20, Edit by BENSON
  12. % Changed "move-to-front" to "exchange-with-previous"
  13. % <PSL.INTERP>PROPERTY-LIST.RED.7, 27-Feb-82 12:43:27, Edit by BENSON
  14. % Optimized GET and FLAGP, rearranges property list
  15. % Every ID in the system has a property list. It is obtained by the function
  16. % PROP(ID) and updated with the function SETPROP(ID, PLIST). These functions
  17. % are not in the Standard Lisp report, and are not intended for use in user
  18. % programs. A property list (whose format should also not be known to
  19. % user programs) is a list of IDs and dotted pairs (A-List entries). The
  20. % pairs are used by PUT and GET, and the IDs are used by FLAG and FLAGP.
  21. % Non-Standard Lisp functions used:
  22. % DELQIP -- EQ, destructive version of Delete (in EASY-NON-SL.RED)
  23. % ATSOC -- EQ version of ASSOC (in EASY-NON-SL.RED)
  24. % DELATQIP -- EQ, destructive version of DELASC (in EASY-NON-SL.RED)
  25. % EQCAR(A,B) -- PairP A and car A eq B (in EASY-NON-SL.RED)
  26. % NonIDError -- in TYPE-ERRORS.RED
  27. on SysLisp;
  28. syslsp procedure Prop U; %. Access property list of U
  29. if IDP U then SymPrp IDInf U
  30. else NonIDError(U, 'Prop);
  31. syslsp procedure SetProp(U, L); %. Store L as property list of U
  32. if IDP U then
  33. SymPrp IDInf U := L
  34. else
  35. NonIDError(U, 'SetProp);
  36. syslsp procedure FlagP(U, Indicator); %. Is U marked with Indicator?
  37. if not IDP U or not IDP Indicator then NIL
  38. else begin scalar PL, PreviousPointer;
  39. PL := SymPrp IDInf U;
  40. if null PL then return NIL;
  41. if car PL eq Indicator then return T;
  42. PreviousPointer := PL;
  43. PL := cdr PL;
  44. Loop:
  45. if null PL then return NIL;
  46. if car PL eq Indicator then return
  47. << Rplaca(PL, car PreviousPointer);
  48. Rplaca(PreviousPointer, Indicator);
  49. T >>;
  50. PreviousPointer := PL;
  51. PL := cdr PL;
  52. goto Loop;
  53. end;
  54. on FastLinks;
  55. syslsp procedure GetFnType U;
  56. get(U, 'TYPE);
  57. off FastLinks;
  58. syslsp procedure Get(U, Indicator); %. Retrieve value stored for U with Ind
  59. if not IDP U or not IDP Indicator then NIL
  60. else begin scalar PL, X, PreviousPointer;
  61. PL := SymPrp IDInf U;
  62. if null PL then return NIL;
  63. X := car PL;
  64. if PairP X and car X eq Indicator then return cdr X;
  65. PreviousPointer := PL;
  66. PL := cdr PL;
  67. Loop:
  68. if null PL then return NIL;
  69. X := car PL;
  70. if PairP X and car X eq Indicator then return
  71. << Rplaca(PL, car PreviousPointer);
  72. Rplaca(PreviousPointer, X);
  73. cdr X >>;
  74. PreviousPointer := PL;
  75. PL := cdr PL;
  76. goto Loop;
  77. end;
  78. off SysLisp;
  79. lisp procedure Flag(IDList, Indicator); %. Mark all in IDList with Indicator
  80. if not IDP Indicator then
  81. NonIDError(Indicator, 'Flag)
  82. else
  83. for each U in IDList do Flag1(U, Indicator);
  84. lisp procedure Flag1(U, Indicator);
  85. if not IDP U then
  86. NonIDError(U, 'Flag)
  87. else begin scalar PL;
  88. PL := Prop U;
  89. if not (Indicator memq PL) then SetProp(U, Indicator . PL);
  90. end;
  91. lisp procedure RemFlag(IDList, Indicator); %. Remove marking of all in IDList
  92. if not IDP Indicator then
  93. NonIDError(Indicator, 'RemFlag)
  94. else
  95. for each U in IDList do RemFlag1(U, Indicator);
  96. lisp procedure RemFlag1(U, Indicator);
  97. if not IDP U then
  98. NonIDError(U, 'RemFlag)
  99. else SetProp(U, DelQIP(Indicator, Prop U));
  100. lisp procedure Put(U, Indicator, Val); %. Store Val in U with Indicator
  101. if not IDP U then
  102. NonIDError(U, 'Put)
  103. else if not IDP Indicator then
  104. NonIDError(Indicator, 'Put)
  105. else begin scalar PL, V;
  106. PL := Prop U;
  107. if not (V := Atsoc(Indicator, PL)) then
  108. SetProp(U, (Indicator . Val) . PL)
  109. else
  110. RPlacD(V, Val);
  111. return Val;
  112. end;
  113. lisp procedure RemProp(U, Indicator); %. Remove value of U with Indicator
  114. if not IDP U or not IDP Indicator then NIL
  115. else begin scalar V;
  116. if (V := get(U, Indicator)) then
  117. SetProp(U, DelAtQIP(Indicator, Prop U));
  118. return V;
  119. end;
  120. lisp procedure RemPropL(L, Indicator); %. RemProp for all IDs in L
  121. for each X in L do RemProp(X, Indicator);
  122. END;