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 / s3.1 < prev    next >
Text File  |  1994-01-25  |  3KB  |  77 lines

  1. @SubSection
  2.     @Tag { operators }
  3.     @Title { Operators }
  4. @Begin
  5. @PP
  6. It is evident from the example of Eqn that user-defined operators are
  7. needed that mimic the primitive ones in taking objects as parameters
  8. and returning objects as results.  For example, to define a superscript
  9. operator so that
  10. @ID @Code "2 sup n"
  11. appears as {@Eq {2 sup @R n}}, the following operator definition may
  12. be used:
  13. @ID @Code {
  14. "def sup"
  15. "    precedence 50"
  16. "    associativity right"
  17. "    left x"
  18. "    right y"
  19. "{"
  20. "    @OneRow {  |  {-2p @Font y}  ^/0.5fk  x  }"
  21. "}"
  22. }
  23. The @Code "sup" operator has precedence 50, is right associative, takes
  24. two objects as parameters passed on the left and right, and returns the
  25. object between braces as result.  This object has the structure
  26. @ID @I +2p @Font {
  27. | @ShowMarks @Code y / @ShowMarks @Code x
  28. }
  29. but with the first row mark hidden by the @Code "@OneRow" operator,
  30. and @Code y two points smaller than it would otherwise have been.  The
  31. length @Code "0.5f" specifies half the current font size;  Figure
  32. {@NumberOf gapmodes} describes the @Code k gap mode.  In the Eq equation
  33. formatting package [10] the equation as a whole is
  34. set in italic font, and @Code 2 is an identifier whose body contains
  35. a font change back to Roman.  The digits @Code 0 to @Code 9 are classed
  36. as punctuation characters, permitting @Code 234 for example to be
  37. interpreted as a sequence of three identifiers.
  38. @PP
  39. These definitions are easily implemented by a standard symbol table
  40. and an operator precedence parser.  Algol block structure with the
  41. usual scope rules was adopted as a matter of course.
  42. @PP
  43. Operators are limited to at most two parameters, left and
  44. right, and the parameters cannot be given default values.  @I Named
  45. parameters solve both problems:
  46. @ID @Code {
  47. "def @Preface"
  48. "    named @Tag {}"
  49. "    named @Title { Preface }"
  50. "    right @Body"
  51. "{"
  52. "    Bold @Font @Title"
  53. "    //0.3v  @Body"
  54. "}"
  55. }
  56. The default value appears just after the parameter's declaration,
  57. between braces.  Invocations have a natural syntax:
  58. @ID @Code {
  59. "@Preface"
  60. "    @Title { About this book }"
  61. "{"
  62. "    Few observers would have supposed in 1984, that ..."
  63. "}"
  64. }
  65. with the actual named parameters following directly after the
  66. operator, before any right parameter.  In this example, @Code "@Tag"
  67. will receive its default value, and a less expert user could safely
  68. omit the @Code "@Title" parameter as well.
  69. @PP
  70. Lout permits named parameters to have parameters, a feature with
  71. applications to bibliographic databases, running headers, and other
  72. places where a format has to be supplied before content is
  73. known.  One could go further and provide a complete lambda calculus,
  74. with functions as first-class objects, provided care was taken not
  75. to intimidate the non-expert user.
  76. @End @SubSection
  77.