{"id":5564,"date":"2024-06-20T23:26:43","date_gmt":"2024-06-20T21:26:43","guid":{"rendered":"https:\/\/oopm.org\/?page_id=5564"},"modified":"2024-12-19T12:05:51","modified_gmt":"2024-12-19T11:05:51","slug":"9-1-using-fat-comma-for-specifying-parameters","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=5564","title":{"rendered":"9.1 Using fat comma for specifying parameters"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages5564&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages5564&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">For classes and methods with many parameters it may sometimes be difficult to remember which parameter is which in the list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To improve readability it is possible to associate a name with a parameter &#8211; such a name is called a <em>fat comma <\/em>since it is used instead of a comma.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have seen examples of using fat comma for method invocations and one such example is the <code>put<\/code> method of the <code>Array<\/code> class introduced in section <script>mkRef(\"Array and for-loop\")<\/script>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a: <strong>obj<\/strong> Array(100,integer)\na.put(7):at&#91;3]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The statement <code>a.put(7):at[3] <\/code>describes the invocation of a method <code>put:at<\/code> with two arguments 7 and 3. This method assigns the value 7 at index 3 in the array <code>a<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If we instead just use traditional comma-based syntax, this statement would have to written  like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a.put(7,3) <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With this syntax it may not be clear whether the index is the first or second parameter. Using the fat comma syntax, this is not a problem.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The overall structure of the <code>Array<\/code> class is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Array(range: <strong>var<\/strong> integer, element:&lt; Object):\n   get&#91;inx: <strong>var<\/strong> integer]:\n      :::\n   put(e: <strong>var<\/strong> element):at&#91;inx: <strong>var<\/strong> integer]:\n      :::<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>Array<\/code> has two parameters <code>range<\/code>, the number of elements of the <code>Array<\/code> and <code>element<\/code>, the type of the elements in the <code>Array<\/code>. It has two attributes, the method <code>get<\/code> and the method <code>put:at<\/code>, which are described in section <script>mkRef(\"Array and for-loop\")<\/script><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have seen other examples of using fat comma such as the control method <code>if:then,<\/code> <code>if:then:else<\/code>, and <code>for:to:repeat<\/code>. We show the overall structure of <code>if:then:else<\/code> below in this section and a more detailed description is given in section <script>mkRef(\"Conditional statements\")<\/script>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The general form of declaring a method using fat comma is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>Id1<\/em>(<em>parameter1<\/em>):<em>id2<\/em>(<em>paramater2<\/em>):<em>id3<\/em>(<em>parameter3<\/em>):\n   ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This method has the name <code>Id1:id2:id3<\/code> and has three parameters specified by <em>parameter1<\/em>, <em>parameter2<\/em>, and <em>parameter3<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An invocation has the form: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>Id1<\/em>(<em>exp1<\/em>):<em>id2<\/em>(<em>exp2<\/em>):<em>id3<\/em>(<em>exp3<\/em>)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">where <em>exp1<\/em>, <em>exp2<\/em>, and <em>exp3<\/em> are the arguments being supplied.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There may be an arbitrary number of parameters &#8211; for brevity, we have just shown 3 parameters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is possible to use different parentheses like <code>(<\/code>, <code>)<\/code>, <code>[<\/code>, <code>]<\/code>, <code>{<\/code>, and <code>}<\/code> as in:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>put(e):at&#91;inx]:do{S}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By convention, <code>(<\/code>, and <code>)<\/code> are used for a parameter representing a datum in general, <code>[<\/code>, and <code>]<\/code> are used for a parameter representing an index, and <code>{<\/code>, and <code>}<\/code> are used for a parameter being a virtual method or class. However, these are not rules enforces by the compiler and the programmer may use whatever parameters he\/she prefers, but we recommend following the conventions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a parameter defined using curly brackets <code>{,<\/code> and <code>}<\/code>, these may in an invocation be replaced by indentation of the actual argument.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Consider the <code>if:then:else<\/code>, which has the following overall structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (cond):then{thenPart:&lt; object}else{ elsePart:&lt; Object}:\n   ::: <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">An <code>if:then:else<\/code> may be invoked as follows using curly brackets:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (a &lt; b) :then { a := a - b }:else { b := b - a }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If indentation is used instead of the curly brackets, this <code>if:then:else<\/code> may be written as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (a &lt; b) :then\n   a := a - b \n:else\n   b := b - a<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Fat comma may be used to specify the parameters of classes as well as methods.<\/p>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=5564\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>For classes and methods with many parameters it may sometimes be difficult to remember which parameter is which in the list. To improve readability it is possible to associate a name with a parameter &#8211; such a name is called a fat comma since it is used instead of a comma. We have seen examples [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3671,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5564","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5564"}],"version-history":[{"count":28,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5564\/revisions"}],"predecessor-version":[{"id":10638,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5564\/revisions\/10638"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/3671"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}