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.LOUT / ch2.02 < prev    next >
Text File  |  1994-01-25  |  3KB  |  92 lines

  1. @Section
  2.   @Tag { visibility }
  3.   @Title { Nested definitions, body parameters, and import and export }
  4. @Begin
  5. @PP
  6. A definition may contain
  7. nested.def @Index { Nested definitions }
  8. other definitions at the beginning of its body:
  9. @ID @Code {
  10. "def @NineSquare"
  11. "   right x"
  12. "{"
  13. "   def @Three { x |0.2i x |0.2i x }"
  14. ""
  15. "   @Three /0.2i @Three /0.2i @Three"
  16. "}"
  17. }
  18. A parameter like @Code x may be invoked anywhere within the body of the
  19. symbol it is a parameter of, including within nested definitions.  A
  20. nested symbol like @Code "@Three" may be invoked anywhere from the
  21. beginning of its own body to the end of the body of the symbol it is
  22. defined within.  So, assuming an appropriate definition of
  23. {@Code "@Box"},
  24. @ID @Code {
  25. "@NineSquare @Box"
  26. }
  27. has result
  28. @ID @Fig {
  29. @NineSquare @Box { 0.2i @Wide 0.2i @High }
  30. }
  31. Nested definitions may themselves contain nested definitions, to
  32. arbitrary depth.
  33. @PP
  34. There are three special features which permit a nested symbol or
  35. parameter to be invoked outside its normal range; that is, outside the
  36. body of the enclosing symbol.  The first and simplest of these features
  37. is the {@I {body parameter}},
  38. parameter.body @SubIndex { @Code body parameter }
  39. body.par @Index { @Code body parameter }
  40. an alternative form of right parameter.  The Eq equation formatting
  41. package [{@Ref kingston92eq}] is a classic example of the use of a body
  42. parameter.  In outline, it looks like this:
  43. @ID @Code {
  44. "export \"+\" sup over"
  45. ""
  46. "def @Eq"
  47. "    body x"
  48. "{"
  49. "    def \"+\" ..."
  50. "    def sup ..."
  51. "    def over ..."
  52. "    ..."
  53. ""
  54. "    Slope @Font x"
  55. "}"
  56. }
  57. First we list those nested symbols and parameters that we intend to
  58. refer to outside the body of @Code "@Eq" in an @Code export clause,
  59. export @Index { @Code export clause }
  60. preceding the definition as shown.  Only exported symbols may be
  61. invoked outside the body of {@Code "@Eq"}.  A body parameter may not be
  62. exported.  The body parameter is like a right parameter except that the
  63. exported symbols are visible within it:
  64. @ID @Code {
  65. "@Eq { {x sup 2 + y sup 2} over 2 }"
  66. }
  67. calls on the nested definitions of @Code "@Eq" to produce the result
  68. @ID {
  69. @Eq { {x sup 2 + y sup 2} over 2 }
  70. }
  71. The body parameter's value must be enclosed in braces.  The term `body
  72. parameter' is a reminder that the value is interpreted as if it was
  73. within the body of the symbol.
  74. @PP
  75. The second place where exported symbols may be used is in the right
  76. parameter of the @@Open symbol, and following its alternative form,
  77. @@Use (Section {@NumberOf open}).
  78. @PP
  79. Finally, exported nested symbols and parameters may be made visible within
  80. a subsequent definition or macro by preceding it with an @Code import
  81. import @Index { @Code import clause }
  82. clause, like this:
  83. @ID @Code {
  84. "import @Eq"
  85. "def pythag { sqrt { x sup 2 + y sup 2 } }"
  86. }
  87. Note however that @Code pythag can only be used with some invocation of
  88. {@Code "@Eq"}:  within the body parameter of an invocation of {@Code "@Eq"},
  89. within the right parameter of an {@Code "@Eq&&tag @Open"}, or following
  90. a @@Use.  There may be several symbols in the @Code import clause.
  91. @End @Section
  92.