putd-getd.red 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. %
  2. % PUTD-GETD.RED - Standard Lisp function defining functions
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 18 August 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % <PSL.KERNEL>PUTD-GETD.RED.3, 13-Jan-83 19:09:47, Edit by PERDUE
  12. % Removed obsolete code from PUTD in response to Bobbie Othmer's bug report
  13. % <PSL.KERNEL>PUTD-GETD.RED.2, 24-Sep-82 15:01:38, Edit by BENSON
  14. % Added CODE-NUMBER-OF-ARGUMENTS
  15. % <PSL.INTERP>PUTD-GETD.RED.3, 19-Apr-82 13:10:57, Edit by BENSON
  16. % Function in PutD may be an ID
  17. % <PSL.INTERP>PUTD-GETD.RED.4, 6-Jan-82 19:18:47, Edit by GRISS
  18. % Add NEXPR
  19. % DE, DF and DM are defined in EASY-SL.RED
  20. % If the function is interpreted, the lambda form will be found by
  21. % GET(ID, '!*LambdaLink).
  22. % If the type of a function is other than EXPR (i.e. FEXPR or MACRO or NEXPR),
  23. % this will be indicated by GET(ID, 'TYPE) = 'FEXPR or 'MACRO or 'NEXPR
  24. % PutD makes use of the fact that FLUID and GLOBAL declarations use the
  25. % property list indicator TYPE
  26. % Non-Standard Lisp functions used:
  27. % function cell primitives FUnBoundP, etc. found in FUNCTION-PRIMITVES.RED
  28. % CompD -- in COMPILER.RED
  29. % ErrorPrintF, VerboseTypeError, BldMsg
  30. % Error numbers:
  31. % 1100 - ill-formed function expression
  32. % 1300 - unknown function type
  33. % +5 in GetD
  34. lisp procedure GetD U; %. Lookup function definition of U
  35. IDP U and not FUnBoundP U and ((get(U, 'TYPE) or 'EXPR) .
  36. (if FLambdaLinkP U then get(U, '!*LambdaLink) else GetFCodePointer U));
  37. lisp procedure RemD U; %. Remove function definition of U
  38. begin scalar OldGetD;
  39. if (OldGetD := GetD U) then
  40. << MakeFUnBound U;
  41. RemProp(U, 'TYPE);
  42. RemProp(U, '!*LambdaLink) >>;
  43. return OldGetD;
  44. end;
  45. fluid '(!*RedefMSG % controls printing of redefined
  46. !*UserMode); % controls query for redefinition
  47. LoadTime
  48. << !*UserMode := NIL; % start in system mode
  49. !*RedefMSG := T >>; % message in PutD
  50. fluid '(!*Comp % controls automatic compilation
  51. PromptString!*);
  52. lisp procedure PutD(FnName, FnType, FnExp); %. Install function definition
  53. %
  54. % this differs from the SL Report in 2 ways:
  55. % - function names flagged LOSE are not defined.
  56. % - " " which are already fluid or global are defined anyway,
  57. % with a warning.
  58. %
  59. if not IDP FnName then
  60. NonIDError(FnName, 'PutD)
  61. else if not (FnType memq '(EXPR FEXPR MACRO NEXPR)) then
  62. ContError(1305,
  63. "%r is not a legal function type",
  64. FnType,
  65. PutD(FnName, FnType, FnExp))
  66. else if FlagP(FnName, 'LOSE) then
  67. << ErrorPrintF("*** %r has not been defined, because it is flagged LOSE",
  68. FnName);
  69. NIL >>
  70. else begin scalar VarType, PrintRedefinedMessage, OldIN, PromptString!*,
  71. QueryResponse;
  72. if not FUnBoundP FnName then
  73. << if !*RedefMSG then PrintRedefinedMessage := T;
  74. if !*UserMode and not FlagP(FnName, 'USER) then
  75. if not YesP BldMsg(
  76. "Do you really want to redefine the system function %r?",
  77. FnName)
  78. then return NIL
  79. else Flag1(FnName, 'USER) >>;
  80. if CodeP FnExp then
  81. << MakeFCode(FnName, FnExp);
  82. RemProp(FnName, '!*LambdaLink) >>
  83. else if IDP FnExp and not FUnBoundP FnExp then return
  84. PutD(FnName, FnType, cdr GetD FnExp)
  85. else if !*Comp then
  86. return CompD(FnName, FnType, FnExp)
  87. else if EqCar(FnExp, 'LAMBDA) then
  88. << put(FnName, '!*LambdaLink, FnExp);
  89. MakeFLambdaLink FnName >>
  90. else return ContError(1105,
  91. "Ill-formed function expression in PutD",
  92. PutD(FnName, FnType, FnExp));
  93. if FnType neq 'EXPR then put(FnName, 'TYPE, FnType)
  94. else RemProp(FnName, 'TYPE);
  95. if !*UserMode then Flag1(FnName, 'USER) else RemFlag1(FnName, 'USER);
  96. if PrintRedefinedMessage then
  97. ErrorPrintF("*** Function %r has been redefined", FnName);
  98. return FnName;
  99. end;
  100. on Syslisp;
  101. syslsp procedure code!-number!-of!-arguments cp;
  102. begin scalar n;
  103. return if codep cp then
  104. << n := !%code!-number!-of!-arguments CodeInf cp;
  105. if n >= 0 and n <= MaxArgs then n >>;
  106. end;
  107. END;