Basics-AttributeDef.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="Attribute_Definition">
  5. <title>Definitions</title>
  6. <para>Each ECL definition<indexterm>
  7. <primary>ECL definition</primary>
  8. </indexterm> is the basic building block of ECL. A definition specifies
  9. <emphasis>what </emphasis>is done but not <emphasis>how</emphasis> it is to
  10. be done. Definitions can be thought of as a highly developed form of
  11. macro-substitution, making each succeeding definition more and more highly
  12. leveraged upon the work that has gone before. This results in extremely
  13. efficient query construction.</para>
  14. <para>All definitions take the form:</para>
  15. <para><emphasis role="bold">[</emphasis><emphasis>Scope</emphasis><emphasis
  16. role="bold">] [</emphasis><emphasis>ValueType</emphasis><emphasis
  17. role="bold">] Name<indexterm>
  18. <primary>Name</primary>
  19. </indexterm> [ </emphasis>(<emphasis>parms</emphasis>) <emphasis
  20. role="bold">] := Expression<indexterm>
  21. <primary>Expression</primary>
  22. </indexterm> [ </emphasis><emphasis>:WorkflowService</emphasis><emphasis
  23. role="bold">] ;</emphasis></para>
  24. <para>The Definition Operator<indexterm>
  25. <primary>Definition Operator</primary>
  26. </indexterm> (<emphasis role="bold"> :=</emphasis> read as “is defined
  27. as”) defines an expression. On the left side of the operator is an optional
  28. <emphasis>Scope<indexterm>
  29. <primary>Scope</primary>
  30. </indexterm></emphasis> (see <emphasis role="bold">Attribute
  31. Visibility</emphasis>), <emphasis>ValueType<indexterm>
  32. <primary>Value Type</primary>
  33. </indexterm></emphasis> (see <emphasis role="bold">Value
  34. Types</emphasis>), and any parameters<indexterm>
  35. <primary>parameters</primary>
  36. </indexterm> (<emphasis>parms</emphasis>) it may take (see <emphasis
  37. role="bold">Functions (Parameter Passing)</emphasis>). On the right side is
  38. the expression that produces the result and optionally a colon (:) and a
  39. comma-delimited list of <emphasis>WorkflowServices</emphasis> (see <emphasis
  40. role="bold">Workflow Services</emphasis>). A definition must be explicitly
  41. terminated with a semi-colon (;). The Definition name can be used in
  42. subsequent definitions:</para>
  43. <programlisting>MyFirstDefinition := 5; //defined as 5
  44. MySecondDefinition := MyFirstDefinition + 5; //this is 10</programlisting>
  45. <sect2 id="Attribute_Name_Rules">
  46. <title>Definition Name Rules</title>
  47. <para>Definition name<indexterm>
  48. <primary>Definition Name</primary>
  49. </indexterm>s begin with a letter and may contain only letters, numbers,
  50. or underscores (_).</para>
  51. <programlisting>My_First_Definition1 := 5; // valid name
  52. My First Definition := 5; // INVALID name, spaces not allowed</programlisting>
  53. <para>You may name a Definition with the name of a previously created
  54. module in the ECL Repository, if the attribute is defined with an explicit
  55. <emphasis>ValueType</emphasis>.</para>
  56. </sect2>
  57. <sect2 id="Reserved_Words">
  58. <title>Reserved Words</title>
  59. <para>ECL keywords<indexterm>
  60. <primary>ECL keywords</primary>
  61. </indexterm>, built-in functions and their options are reserved
  62. words<indexterm>
  63. <primary>Reserved Words</primary>
  64. </indexterm>, but they are generally reserved only in the context within
  65. which they are valid for use. Even in that context, you may use reserved
  66. words as field or attribute names, provided you explicitly disambiguate
  67. them, as in this example:</para>
  68. <programlisting>ds2 := DEDUP(ds, ds.all, ALL); //ds.all is the 'all' field in the
  69. //ds dataset - not DEDUP’s ALL option</programlisting>
  70. <para>However, it is still a good idea to avoid using ECL keywords as
  71. attribute or field names.</para>
  72. </sect2>
  73. <sect2 id="Attribute_Naming">
  74. <title>Definition Naming</title>
  75. <para>Use descriptive names for all EXPORTed and SHARED Definitions. This
  76. will make your code more readable. The naming convention adopted
  77. throughout the ECL documentation and training courses is as
  78. follows:</para>
  79. <programlisting><emphasis role="bold">Definition Type</emphasis> <emphasis
  80. role="bold">Are Named
  81. </emphasis>Boolean Is...
  82. Set Definition Set...
  83. Record Set ...DatasetName</programlisting>
  84. <para>For example:</para>
  85. <programlisting>IsTrue := TRUE; // a BOOLEAN Definition
  86. SetNumbers := [1,2,3,4,5]; // a Set Definition
  87. R_People := People(firstname[1] = 'R'); // a Record Set Definition</programlisting>
  88. </sect2>
  89. </sect1>