home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / SEQIMAGE.ICN < prev    next >
Text File  |  1991-07-13  |  2KB  |  63 lines

  1. ############################################################################
  2. #
  3. #    Name:    seqimage.icn
  4. #
  5. #    Title:    Produce string image of Icon result sequence
  6. #
  7. #    Author:    Ralph E. Griswold
  8. #
  9. #    Date:    June 10, 1988
  10. #
  11. ############################################################################
  12. #  
  13. #     The procedure Seqimage{e,i,j} produces a string image of the
  14. #  result sequence for the expression e. The first i results are
  15. #  printed. If i is omitted, there is no limit. If there are more
  16. #  than i results for e, ellipses are provided in the image after
  17. #  the first i.  If j is specified, at most j results from the end
  18. #  of the sequence are printed after the ellipses.  If j is omitted,
  19. #  only the first i results are produced.
  20. #  
  21. #     For example, the expressions
  22. #  
  23. #     Seqimage{1 to 12}
  24. #     Seqimage{1 to 12,10}
  25. #     Seqimage{1 to 12,6,3}
  26. #  
  27. #  produce, respectively,
  28. #  
  29. #     {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
  30. #     {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...}
  31. #     {1, 2, 3, 4, 5, 6, ..., 10, 11, 12}
  32. #  
  33. #  
  34. #  Warning:
  35. #
  36. #     If j is not omitted and e has a infinite result
  37. #  sequence, Seqimage does not terminate.
  38. #  
  39. ############################################################################
  40.  
  41. procedure Seqimage(L)
  42.    local seq, result, i, j, resid
  43.  
  44.    seq := ""
  45.    i := @L[2]
  46.    j := @L[3]
  47.    while result := image(@L[1]) do
  48.       if *L[1] > \i then {
  49.          if /j then {
  50.             seq ||:= ", ..."
  51.             break
  52.             }
  53.          else {
  54.             resid := [", " || result]
  55.             every put(resid,", " || image(|@L[1]))
  56.             if *resid > j then seq ||:= ", ..."
  57.             every seq ||:= resid[*resid -j + 1 to *resid]
  58.             }
  59.          }
  60.       else seq ||:= ", " || result
  61.    return "{" || seq[3:0] || "}" | "{}"
  62. end
  63.