indxprin.red 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. module indxprin; % Functions for special print.
  2. % Author: Eberhard Schruefer;
  3. fluid '(!*nat !*nero !*revpri obrkp!* orig!* pline!* posn!* ycoord!*
  4. ymax!* ymin!* fancy!-pos!* fancy!-line!*);
  5. global '(!*eraise spare!*);
  6. symbolic procedure indvarprt u;
  7. if null !*nat then <<prin2!* car u;
  8. prin2!* "(";
  9. if cddr u then inprint('!*comma!*,0,cdr u)
  10. else maprin cadr u;
  11. prin2!* ")" >>
  12. else begin scalar y; integer l;
  13. l := flatsizec flatindxl u+length cdr u-1;
  14. if l>(linelength nil-spare!*)-posn!* then terpri!* t;
  15. %avoid breaking of an indexed variable over a line;
  16. y := ycoord!*;
  17. prin2!* car u;
  18. for each j on cdr u do
  19. <<ycoord!* := y + if atom car j then 1 else -1;
  20. if ycoord!*>ymax!* then ymax!* := ycoord!*;
  21. if ycoord!*<ymin!* then ymin!* := ycoord!*;
  22. prin2!* if atom car j then car j else cadar j;
  23. if cdr j then prin2!* " ">>;
  24. ycoord!* := y
  25. end;
  26. symbolic procedure rembras u;
  27. if !*nat and (atom u or null get(car u,'infix))
  28. then <<prin2!* " ";
  29. maprin u>>
  30. else <<prin2!* "(";
  31. maprin u;
  32. prin2!* ")">>;
  33. put('form!-with!-free!-indices,'tag,'form!-with!-free!-indices);
  34. put('form!-with!-free!-indices,'prifn,'indxpri1);
  35. put('form!-with!-free!-indices,'fancy!-setprifn,'indxpri);
  36. flag('(form!-with!-free!-indices),'sprifn);
  37. put('indvarprt,'expt,'inbrackets);
  38. symbolic procedure xindvarprt(l,p);
  39. % Thanks to Herbert Melenk.
  40. fancy!-level
  41. ( if not(get('expt,'infix)>p) then
  42. fancy!-in!-brackets(
  43. {'xindvarprt,mkquote l,0}, '!(,'!))
  44. else
  45. begin scalar w,x,b,s;
  46. w:=fancy!-prefix!-operator car l;
  47. if w eq 'failed then return w;
  48. l := xindxlfix cdr l;
  49. while l and w neq 'failed do
  50. <<if b then fancy!-prin2!*("{}",0);
  51. b := t;
  52. if atom car l
  53. then (if s eq '!^
  54. then x := car l . x
  55. else <<if s then
  56. <<w := fancy!-print!-indexlist1(reversip x,s,nil);
  57. fancy!-prin2!*("{}",0)>>;
  58. x := {car l};
  59. s := '!^>>)
  60. else (if s eq '!_
  61. then x := cadar l . x
  62. else <<if s then
  63. <<w := fancy!-print!-indexlist1(reversip x,s,nil);
  64. fancy!-prin2!*("{}",0)>>;
  65. x := {cadar l};
  66. s := '!_>>);
  67. l := cdr l>>;
  68. w := fancy!-print!-indexlist1(reversip x,s,nil);
  69. return w
  70. end);
  71. symbolic procedure xindxlfix u;
  72. if null u then nil
  73. else if atom car u then xindxfix car u . xindxlfix cdr u
  74. else {'minus,xindxfix cadar u} . xindxlfix cdr u;
  75. symbolic procedure xindxfix x;
  76. % x: atom -> xindxfix:atom
  77. begin scalar xx;
  78. xx := explode x;
  79. while xx and car xx = '!! do xx := cdr xx;
  80. return if xx and numberp(xx := compress xx) then xx
  81. else x;
  82. end;
  83. endmodule;
  84. end;