{"id":42,"date":"2024-09-24T20:36:25","date_gmt":"2024-09-24T19:36:25","guid":{"rendered":"http:\/\/monkey.ploogie.co.uk\/?page_id=42"},"modified":"2024-11-26T08:48:51","modified_gmt":"2024-11-26T08:48:51","slug":"function","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/function\/","title":{"rendered":"function"},"content":{"rendered":"<h2><span id=\"Syntax\" class=\"mw-headline\">Syntax<\/span><\/h2>\n<p>function <strong><em>name<\/em><\/strong>(<strong><em>argument-list, . . .<\/em><\/strong>) {<em><strong>BLOCK<\/strong><\/em>}<\/p>\n<h2>Parameters<\/h2>\n<table class=\"confluenceTable tablesorter tablesorter-default\">\n<thead>\n<tr class=\"tablesorter-headerRow\">\n<th class=\"confluenceTh sortableHeader tablesorter-headerAsc\" data-column=\"0\">\n<div class=\"tablesorter-header-inner\">Parameter<\/div>\n<\/th>\n<th class=\"confluenceTh sortableHeader\" data-column=\"1\">\n<div class=\"tablesorter-header-inner\">Definition<\/div>\n<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td class=\"confluenceTd\">argument-list<\/td>\n<td class=\"confluenceTd\">The argument list can be a NULL entry if no variables are passed to the function, a single argument, or several arguments separated by commas.<\/td>\n<\/tr>\n<tr>\n<td class=\"confluenceTd\">BLOCK<\/td>\n<td class=\"confluenceTd\">One or more MSL statements that define the action the function performs.<\/td>\n<\/tr>\n<tr>\n<td class=\"confluenceTd\">name<\/td>\n<td class=\"confluenceTd\">Character label that is used to identify and call the function from within the MSL program. The name cannot be the same as a MSL built-in function or a MSL variable.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span id=\"Example\" class=\"mw-headline\">Description<\/span><\/h2>\n<p>The <em>function<\/em> statement provides user-defined functions within MSL, similar to those available in the C programming language. The function keyword is required in a user function definition.<\/p>\n<p>Functions must be defined before their first use, and the correct argument list must be passed in a\u00a0<em>function<\/em> call. A\u00a0\u00a0<em>function<\/em> call always returns a character that represents a character string or numeric value. (All data types are represented within PSL as character strings.)\u00a0<br class=\"atl-forced-newline\" \/><br class=\"atl-forced-newline\" \/>Arguments are passed by value to parameters (that is, local copies are created from the arguments&#8217; data passed in), and thus changing a parameter will not affect the value of the argument. Function parameters are local to a function and can be named the same as global variables (or the same as parameters of other functions).\u00a0<br class=\"atl-forced-newline\" \/><br class=\"atl-forced-newline\" \/>If a function definition appears in the middle of executable statements and control flow reaches that definition from above, the definition is skipped as a comment is skipped. The only way to enter the body of a function is to explicitly call it. The function definitions serve merely to define a function and are not invoked until called. Hence, it is possible to place executable code above, below, and between function definitions.<\/p>\n<h2>Example<\/h2>\n<pre>function max(x,y){\r\n    if(x &gt; y) {\r\n        return x\r\n    } else {\r\n        return y\r\n    }\r\n}\r\nm = max(1,2)\r\nprint(\"maximum is \", m, \"\\n\")<\/pre>\n<p>Of course, you could also do<\/p>\n<pre>\r\nfunction max(x,y) {\r\n    return (x > y) ? x : y\r\n}\r\nm = max(1,2)\r\nprint(\"maximum is \", m, \"\\n\")<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Syntax function name(argument-list, . . .) {BLOCK} Parameters Parameter Definition argument-list The argument list can be a NULL entry if no variables are passed to the function, a single argument, or several arguments separated by commas. BLOCK One or more MSL statements that define the action the function performs. name Character label that is used &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-42","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":5,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/42\/revisions"}],"predecessor-version":[{"id":762,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/42\/revisions\/762"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}