home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / DOC / TR.IMPL / s6.1 < prev    next >
Text File  |  1994-01-25  |  4KB  |  86 lines

  1. @SubSection
  2.     @Tag { cross }
  3.     @Title { The cross reference abstraction }
  4. @Begin
  5. @PP
  6. In developing the cross reference abstraction, it seemed best to begin
  7. with the database application, since it is the simplest.  Database
  8. relations are naturally mapped into Lout definitions:
  9. @ID @Code {
  10. "def @Reference"
  11. "    named @Tag {}"
  12. "    named @Author {}"
  13. "    named @Title {}"
  14. "    named @Journal {}"
  15. "{}"
  16. }
  17. The set of all invocations of @Code "@Reference" is a relation whose
  18. attributes are the parameters, and whose tuples are the invocations.  To
  19. complete the correspondence, we need only declare that the @Code "@Tag"
  20. parameter is special, serving as the key attribute.
  21. @PP
  22. Following the database model, we next need a notation for retrieving the
  23. invocation with a given tag:
  24. @ID @Code "@Reference&&kingston91"
  25. This @I {cross reference} is like an arrow pointing to the invocation.  To
  26. access its attributes, we write
  27. @ID @Code "@Reference&&kingston91 @Open { @Author, @Title }"
  28. The @Code "@Open" operator evaluates its right parameter in an
  29. environment which includes the exported parameters of its left.
  30. @PP
  31. An invocation is chosen to be a running header because of its proximity
  32. to the place where it is used, rather than by its tag.  Such proximity
  33. is naturally expressed by two special tags, {@Code preceding} and
  34. {@Code following}; for example, @Code "@Sym&&following" will point to
  35. the closest following invocation of @Code "@Sym" in the final printed
  36. document.  This is much simpler conceptually than reference to the
  37. internal state of the document formatter at a critical moment, the usual
  38. approach to running headers.
  39. @PP
  40. It turns out that the above design solves all the cross referencing
  41. problems encountered in practice except one, which may be typified by
  42. the problem of finding the number of the page on which the chapter whose
  43. tag is @Code "intro" begins.  Two cross referencing steps are needed,
  44. first to {@Code "@Chapter&&intro"}, then from there to
  45. {@Code "@Page&&preceding"}, where the page number is known.
  46. @PP
  47. Given the success of the design so far, this last problem proves to be
  48. surprisingly difficult.  We first try
  49. @ID @Code {
  50. "@Chapter&&intro @Open {"
  51. "    @Page&&preceding @Open { @PageNum }"
  52. "}"
  53. }
  54. but this fails because @Code "@Page&&preceding" is evaluated in the
  55. present context, not in the context of @Code "@Chapter&&intro" as
  56. required.  So our next attempt is
  57. @ID @Code {
  58. "def @Chapter"
  59. "    named @PageNum { @Page&&preceding @Open { @PageNum } }"
  60. "    ..."
  61. }
  62. with the @Code "@Page&&preceding" cross reference attached to the
  63. chapter; we write
  64. @ID @Code "@Chapter&&intro @Open { @PageNum }"
  65. This also fails, because parameters are evaluated after substitution, so
  66. once again @Code "@Page&&preceding" is evaluated in the wrong context.  We
  67. could of course define a new operator specifically for this case:
  68. @ID @Code "@Page&&{ @Preceding @Chapter&&intro }"
  69. or some such.  This is free of the annoying context-sensitivity, but it
  70. seems quite complex, and the expected cross reference @Code "@Page&&preceding"
  71. does not appear.
  72. @PP
  73. The author was lost in these obscurities for some time, and ultimately
  74. rescued himself by looking ahead to the implementation of the
  75. @Code preceding and @Code following tags, to see if a simple extension
  76. of it would solve the problem.  This led to the @Code "@Tagged" operator:
  77. @ID @Code "@Page&&preceding @Tagged intro"
  78. placed at the beginning of the body of the chapter will attach @Code intro
  79. as an extra tag to the closest preceding invocation of {@Code "@Page"},
  80. so that
  81. @ID @Code "@Page&&intro @Open { @PageNum }"
  82. yields the desired page number.  There is something low-level and ad hoc
  83. about the @Code "@Tagged" operator, but the two cross references do
  84. appear naturally, and it works.
  85. @End @SubSection
  86.