mini-easy-sl.red 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. % MINI-EASY-SL.RED --- Simple functions
  2. % 3.1 -- Some basic predicates
  3. % Note that the bodies open compile, so this is just for
  4. % interpreter entries
  5. Procedure Atom x;
  6. Atom x;
  7. procedure ConstantP U;
  8. Not PairP U and not IDP U;
  9. Procedure Null U;
  10. U eq NIL;
  11. % 3.2 -- Simple LIST stuff
  12. nexpr procedure List x;
  13. x;
  14. % 3.5 -- Function definition
  15. fexpr Procedure De(x);
  16. PutD(car x,'Expr,'LAMBDA . cdr x);
  17. fexpr Procedure Df(x);
  18. PutD(car x,'Fexpr,'LAMBDA . Cdr x);
  19. fexpr Procedure Dn(x);
  20. PutD(car x,'NExpr,'LAMBDA . cdr x);
  21. fexpr Procedure Dm(x);
  22. PutD(car x,'Macro,'LAMBDA . Cdr x);
  23. % 3.6 -- Variables and Binding
  24. Fexpr Procedure SETQ a;
  25. Set(car a,Eval Cadr a);
  26. % 3.7 -- Program function features
  27. fexpr procedure Progn x;
  28. EvProgn x;
  29. procedure EvProgn fl;
  30. Begin scalar x;
  31. While PairP fl do <<x:=Eval Car fl;
  32. fl:=Cdr fl>>;
  33. Return x;
  34. End;
  35. % 3.10 -- Boolean functions
  36. procedure EvCond fl;
  37. if not PairP fl then 'NIL
  38. else if not PairP car fl then EvCond cdr fl
  39. else if Eval car car fl then EvProgn cdr car fl
  40. else EvCond cdr fl;
  41. fexpr procedure Cond x;
  42. EvCond x;
  43. procedure Not U;
  44. U eq NIL;
  45. % 3.13 -- Composite
  46. Procedure append(U,V);
  47. if not PairP U then V
  48. else Cons(Car U,Append(Cdr U,V));
  49. Procedure MemQ(x,y);
  50. If Not PAIRP y then NIL
  51. else if x EQ car y then T
  52. else MemQ(x, cdr y);
  53. Procedure REVERSE U;
  54. Begin Scalar V;
  55. While PairP U do <<V:=CONS(Car U,V);
  56. U:=CDR U>>;
  57. Return V;
  58. End;
  59. % Simple EVAL support
  60. procedure Evlis x;
  61. if Not Pairp x then x
  62. else Eval(car x) . Evlis(cdr x);
  63. Fexpr Procedure Quote a;
  64. Car a;
  65. End;