lisp-macros.red 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. %
  2. % LISP-MACROS.RED - Various macros to make pure Lisp more tolerable
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 5 October 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % <PSL.INTERP>LISP-MACROS.RED.4, 22-Jul-82 10:51:11, Edit by BENSON
  12. % Added CASE, removed IF
  13. % still to come: Do, Let
  14. % <PSL.INTERP>LISP-MACROS.RED.5, 28-Dec-81 14:43:39, Edit by BENSON
  15. % Added SetF
  16. CompileTime flag('(InThisCase), 'InternalFunction);
  17. % Not a macro, but it belongs with these
  18. SYMBOLIC FEXPR PROCEDURE CASE U;
  19. %U is of form (CASE <integer exp> (<case-1> <exp-1>) . . .(<case-n> <exp-n>)).
  20. % If <case-i> is NIL it is default,
  21. % else is list of INT or (RANGE int int)
  22. BEGIN SCALAR CaseExpr,DEF,CaseLst,BOD;
  23. CaseExpr:=EVAL CAR U;
  24. L: IF NOT PAIRP(U:=CDR U) THEN RETURN EVAL DEF;
  25. CaseLst:=CAAR U; BOD:=CADAR U;
  26. IF NOT PAIRP CaseLst
  27. OR CAR CaseLst MEMQ '(OTHERWISE DEFAULT) THEN
  28. <<DEF:=BOD; GOTO L>>;
  29. IF InThisCase(CaseExpr,CaseLst) THEN RETURN EVAL BOD;
  30. GOTO L
  31. END;
  32. SYMBOLIC PROCEDURE InThisCase(CaseExpr,Cases);
  33. IF NOT PAIRP Cases Then NIL
  34. ELSE IF PAIRP Car Cases and Caar Cases EQ 'RANGE
  35. and CaseExpr>=Cadar Cases and CaseExpr<=Caddar Cases then T
  36. ELSE IF CaseExpr = Car Cases then T
  37. ELSE InThisCase(CaseExpr,Cdr Cases);
  38. macro procedure SetF U; %. General assignment macro
  39. ExpandSetF(cadr U, caddr U);
  40. lisp procedure ExpandSetF(LHS, RHS);
  41. begin scalar LHSOp;
  42. return if atom LHS then list('setq, LHS, RHS)
  43. else if (LHSOp := get(car LHS, 'Assign!-Op)) then
  44. LHSOp . Append(cdr LHS, list RHS) % simple substitution case
  45. else if (LHSOp := get(car LHS, 'SetF!-Expand)) then
  46. Apply(LHSOp, list(LHS, RHS)) % more complex transformation
  47. else if (LHSOp := GetD car LHS) and car LHSOp = 'MACRO then
  48. ExpandSetF(Apply(cdr LHSOp, list LHS), RHS)
  49. else StdError BldMsg("%r is not a known form for assignment",
  50. list('SetF, LHS, RHS));
  51. end;
  52. LoadTime DefList('((GetV PutV)
  53. (car RplacA)
  54. (cdr RplacD)
  55. (Indx SetIndx)
  56. (Sub SetSub)
  57. (Nth (lambda (L I X) (rplaca (PNTH L I) X) X))
  58. (Eval Set)
  59. (Value Set)), 'Assign!-Op);
  60. END;