equal.red 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. %
  2. % EQUAL.RED - EQUAL, EQN and friends
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 19 August 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % <PSL.KERNEL>EQUAL.RED.2, 21-Sep-82 10:38:28, Edit by BENSON
  12. % Made HalfWordsEqual, etc. internal
  13. % EQ is handled by the compiler and is in KNOWN-TO-COMP-SL.RED
  14. CompileTime flag('(HalfWordsEqual VectorEqual WordsEqual), 'InternalFunction);
  15. on SysLisp;
  16. syslsp procedure Eqn(U, V); %. Eq or numeric equality
  17. U eq V or case Tag U of % add bignums later
  18. FLTN:
  19. FloatP V and
  20. FloatHighOrder FltInf U eq FloatHighOrder FltInf V
  21. and FloatLowOrder FltInf U eq FloatLowOrder FltInf V;
  22. FIXN:
  23. FixNP V and FixVal FixInf U eq FixVal FixInf V;
  24. BIGN:
  25. BigP V and WordsEqual(U, V);
  26. default:
  27. NIL
  28. end;
  29. % Called LispEqual instead of Equal, to avoid name change due to Syslisp parser
  30. syslsp procedure LispEqual(U, V); %. Structural equality
  31. U eq V or case Tag U of
  32. VECT:
  33. VectorP V and VectorEqual(U, V);
  34. STR, BYTES:
  35. StringP V and StringEqual(U, V);
  36. PAIR:
  37. PairP V and
  38. LispEqual(car U, car V) and LispEqual(cdr U, cdr V);
  39. FLTN:
  40. FloatP V and
  41. FloatHighOrder FltInf U eq FloatHighOrder FltInf V
  42. and FloatLowOrder FltInf U eq FloatLowOrder FltInf V;
  43. FIXN:
  44. FixNP V and FixVal FixInf U eq FixVal FixInf V;
  45. BIGN:
  46. BigP V and WordsEqual(U, V);
  47. WRDS:
  48. WrdsP V and WordsEqual(U, V);
  49. HalfWords:
  50. HalfWordsP V and HalfWordsEqual(U, V);
  51. default:
  52. NIL
  53. end;
  54. syslsp procedure EqStr(U, V); %. Eq or string equality
  55. U eq V or StringP U and StringP V and StringEqual(U, V);
  56. syslsp procedure StringEqual(U, V); % EqStr without typechecking or eq
  57. begin scalar Len, I;
  58. U := StrInf U;
  59. V := StrInf V;
  60. Len := StrLen U;
  61. if Len neq StrLen V then return NIL;
  62. I := 0;
  63. Loop:
  64. if I > Len then return T;
  65. if StrByt(U, I) neq StrByt(V, I) then return NIL;
  66. I := I + 1;
  67. goto Loop;
  68. end;
  69. syslsp procedure WordsEqual(U, V);
  70. begin scalar S1, I;
  71. U := WrdInf U;
  72. V := WrdInf V;
  73. if not ((S1 := WrdLen U) eq WrdLen V) then return NIL;
  74. I := 0;
  75. Loop:
  76. if I eq S1 then return T;
  77. if not (WrdItm(U, I) eq WrdItm(V, I)) then return NIL;
  78. I := I + 1;
  79. goto Loop;
  80. end;
  81. syslsp procedure HalfWordsEqual(U, V);
  82. begin scalar S1, I;
  83. U := HalfWordInf U;
  84. V := HalfWordInf V;
  85. if not ((S1 := HalfWordLen U) eq HalfWordLen V) then return NIL;
  86. I := 0;
  87. Loop:
  88. if I eq S1 then return T;
  89. if not (HalfWordItm(U, I) eq HalfWordItm(V, I)) then return NIL;
  90. I := I + 1;
  91. goto Loop;
  92. end;
  93. syslsp procedure VectorEqual(U, V); % Vector equality without type check
  94. begin scalar Len, I;
  95. U := VecInf U;
  96. V := VecInf V;
  97. Len := VecLen U;
  98. if Len neq VecLen V then return NIL;
  99. I := 0;
  100. Loop:
  101. if I > Len then return T;
  102. if not LispEqual(VecItm(U, I), VecItm(V, I)) then return NIL;
  103. I := I + 1;
  104. goto Loop;
  105. end;
  106. off SysLisp;
  107. LoadTime PutD('Equal, 'EXPR, cdr GetD 'LispEqual);
  108. END;