sfgen.red 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. module sfgen; % Handy functions used by the special functions package.
  2. % Author: Chris Cannam.
  3. exports sq2bf!*,bfprin!:roundup,sf!*eval;
  4. symbolic procedure sf!*assoc(compare,val,alist);
  5. (if null alist then nil
  6. else if not lispeval list(compare,car car alist,val)
  7. then car alist
  8. else sf!*assoc(compare,val,cdr alist));
  9. symbolic procedure sf!*multi!*assoc!*comparator(compare,vals,entry);
  10. (if null entry
  11. then (null vals)
  12. else (not null vals)
  13. and (lispeval list(compare,list('quote,car vals),
  14. list('quote,car entry)))
  15. and (sf!*multi!*assoc!*comparator(compare,cdr vals,cdr entry)));
  16. symbolic procedure sf!*multi!*assoc(compare,vals,alist);
  17. (if null alist then nil
  18. else if sf!*multi!*assoc!*comparator(compare,vals,car car alist)
  19. then car alist
  20. else sf!*multi!*assoc(compare,vals,cdr alist));
  21. symbolic procedure sf!*do!*eval(expression);
  22. begin scalar prepre, result;
  23. prepre := precision 0;
  24. precision (prepre + 3);
  25. result := aeval expression;
  26. precision prepre;
  27. return result;
  28. end;
  29. % It's a finite state automaton! It's a big nested if..then..else
  30. % construct! It's repulsive repetitive code! It's easy to compile
  31. % and run quickly! It's longer than it needs to be! It's all of
  32. % this and more...! (But at least it works.)
  33. symbolic procedure sf!*eval(name,args);
  34. begin scalar part1, part2, result;
  35. args := cdr args;
  36. if (part1 := assoc((name . !*complex),sf!-alist))
  37. then if (part2 := sf!*assoc('lessp,c!:prec!:(),cdr part1))
  38. then if (result :=
  39. sf!*multi!*assoc('evalequal,args,cdr part2))
  40. then result := cdr result
  41. else if !*savesfs
  42. then setq(cdr part2,
  43. (args . (result := sf!*do!*eval(name . args)))
  44. . cdr part2)
  45. else result := sf!*do!*eval(name . args)
  46. else if !*savesfs
  47. then setq(cdr part1,
  48. (c!:prec!:()
  49. . list ((args .
  50. (result := sf!*do!*eval(name . args)))))
  51. . cdr part1)
  52. else result := sf!*do!*eval(name . args)
  53. else if !*savesfs
  54. then sf!-alist :=
  55. ((name . !*complex) .
  56. list ((c!:prec!:() .
  57. list ((args .
  58. (result := sf!*do!*eval(name . args))
  59. ))))) . sf!-alist
  60. else result := sf!*do!*eval(name . args);
  61. return result;
  62. end;
  63. algebraic procedure complex!*off!*switch;
  64. if symbolic !*complex then
  65. if symbolic !*msg then
  66. << off msg; off complex; on msg >>
  67. else off complex
  68. else t;
  69. algebraic procedure complex!*restore!*switch(fl);
  70. if not fl then
  71. if symbolic !*msg then
  72. << off msg;
  73. if symbolic !*complex then
  74. off complex
  75. else on complex;
  76. on msg >>
  77. else if symbolic !*complex then
  78. off complex
  79. else on complex;
  80. endmodule;
  81. end;