mini-putd-getd.red 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. % MINI-PUTD-GETD.RED Small COPYD, GETD, PUTD
  2. on syslisp;
  3. Procedure Getd(fn);
  4. Begin scalar type;
  5. if Not IDP fn then return
  6. <<Prin2 "*** Can only GETD off ID's: ";
  7. Print fn;
  8. NIL>>;
  9. if FunBoundP fn then return NIL;
  10. if null(type:=Get(fn,'TYPE)) then type:='Expr;
  11. if FCodeP fn then return ( type . GetFcodePointer fn);
  12. If FLambdaLinkP fn then return (type .Get(fn,'!*LambdaLink));
  13. Prin2 "*** GETD should find a LAMBDA or CODE";
  14. print fn;
  15. return NIL;
  16. End;
  17. Procedure PutD(fn,type,body);
  18. Begin
  19. if Not IDP fn then return
  20. <<Prin2 "*** Can only define ID's as functions: ";
  21. Print fn;
  22. NIL>>;
  23. if FCodeP fn then
  24. <<Prin2 "*** Redefining a COMPILED function: ";
  25. Print fn>>
  26. else if not FunBoundP fn then
  27. <<prin2 " Redefining function ";
  28. print fn>>;
  29. Remprop(fn,'!*LambdaLink);
  30. Remprop(fn,'TYPE);
  31. MakeFUnBound fn;
  32. If LambdaP body then
  33. << Put(fn,'!*LambdaLink,body);
  34. MakeFlambdaLink fn>>
  35. else if CodeP body then
  36. MakeFcode(fn,body)
  37. else return <<Prin2 "*** Body must be a LAMBDA or CODE";
  38. prin1 fn; prin2 " "; print body; NIL>>;
  39. If not(type eq 'expr) then Put(fn,'TYPE,type);
  40. return fn;
  41. End;
  42. syslsp procedure code!-number!-of!-arguments cp;
  43. begin scalar n;
  44. return if codep cp then
  45. << n := !%code!-number!-of!-arguments CodeInf cp;
  46. if n >= 0 and n <= MaxArgs then n >>;
  47. end;
  48. off syslisp;
  49. End;