loops.red 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. module loops; % Looping forms other than the FOR statement.
  2. % Author: Anthony C. Hearn
  3. % Copyright (c) 1987 The RAND Corporation. All rights reserved.
  4. fluid '(!*blockp);
  5. global '(cursym!*);
  6. % ***** REPEAT STATEMENT *****
  7. symbolic procedure repeatstat;
  8. begin scalar !*blockp,body,bool;
  9. if flagp('until,'delim) then bool := t
  10. else flag('(until),'delim);
  11. body:= xread t;
  12. if not bool then remflag('(until),'delim);
  13. if not(cursym!* eq 'until) then symerr('repeat,t);
  14. return list('repeat,body,xread t);
  15. end;
  16. symbolic macro procedure repeat u;
  17. begin scalar body,bool,lab;
  18. body := cadr u; bool := caddr u;
  19. lab := gensym();
  20. return mkprog(nil,list(lab,body,
  21. list('cond,list(list('not,bool),list('go,lab)))))
  22. end;
  23. put('repeat,'stat,'repeatstat);
  24. flag('(repeat),'nochange);
  25. symbolic procedure formrepeat(u,vars,mode);
  26. begin scalar !*!*a2sfn;
  27. !*!*a2sfn := 'aeval!*;
  28. return list('repeat,formc(cadr u,vars,mode),
  29. formbool(caddr u,vars,mode))
  30. end;
  31. put('repeat,'formfn,'formrepeat);
  32. % ***** WHILE STATEMENT *****
  33. symbolic procedure whilstat;
  34. begin scalar !*blockp,bool,bool2;
  35. if flagp('do,'delim) then bool2 := t else flag('(do),'delim);
  36. bool := xread t;
  37. if not bool2 then remflag('(do),'delim);
  38. if not(cursym!* eq 'do) then symerr('while,t);
  39. return list('while,bool,xread t)
  40. end;
  41. symbolic macro procedure while u;
  42. begin scalar body,bool,lab;
  43. bool := cadr u; body := caddr u;
  44. lab := gensym();
  45. return mkprog(nil,list(lab,list('cond,list(list('not,bool),
  46. list('return,nil))),body,list('go,lab)))
  47. end;
  48. put('while,'stat,'whilstat);
  49. flag('(while),'nochange);
  50. symbolic procedure formwhile(u,vars,mode);
  51. begin scalar !*!*a2sfn;
  52. !*!*a2sfn := 'aeval!*;
  53. return list('while,formbool(cadr u,vars,mode),
  54. formc(caddr u,vars,mode))
  55. end;
  56. put('while,'formfn,'formwhile);
  57. endmodule;
  58. end;