{"id":4906,"date":"2024-06-08T13:54:55","date_gmt":"2024-06-08T11:54:55","guid":{"rendered":"https:\/\/oopm.org\/?page_id=4906"},"modified":"2024-11-02T17:35:19","modified_gmt":"2024-11-02T16:35:19","slug":"8-1-1-the-inner-statement","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=4906","title":{"rendered":"8.2.1 The inner statement"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages4906&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=wpv2pages4906&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\">The&nbsp;<code>inner<\/code>-statement is central for defining methods that may be used as supermethods of other methods. We take a closer look at what happens when executing <code>anAccount.deposit(500)<\/code>. This implies the following steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Execution of anAccount.deposit(500) (1).<\/li>\n\n\n\n<li>Execution starts by the executing the items in <code>transact<\/code>, which implies execution of  <code>theTransaction := Transaction(...)<\/code> (2).<\/li>\n\n\n\n<li>The <code>inner(transact)<\/code> is executed (3), which implies that the items in <code>deposit<\/code> are executed.<\/li>\n\n\n\n<li>In addition to <code>balance := balance + amount<\/code>, <code>theTransaction<\/code> is marked as a deposit (4).<\/li>\n\n\n\n<li>After execution of <code>deposit<\/code>, control returns to <code>transact<\/code> (5).<\/li>\n\n\n\n<li>Then <code>transactions.insert(theTransaction)<\/code> is executed (6).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The figure below illustrates the above steps of execution &#8211; the numbers in the figure corresponds to the numbers in the text.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"588\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/06\/InnerAnAccount.deposit500-1024x588.jpg\" alt=\"\" class=\"wp-image-5317\" style=\"width:858px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/06\/InnerAnAccount.deposit500-1024x588.jpg 1024w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/06\/InnerAnAccount.deposit500-300x172.jpg 300w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/06\/InnerAnAccount.deposit500-768x441.jpg 768w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/06\/InnerAnAccount.deposit500.jpg 1248w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Sequence of actions for the call \u201canAccount.deposit(500)\u201d<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The above example show how invocation of <code>deposit<\/code> takes place &#8211; invocation of <code>withdraw<\/code> takes place in a similar way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Nested inner<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>M<\/code> is a method, <code>inner(M)<\/code> may be placed in any nested object-descriptor within <code>M<\/code>. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose we want to inspect all transactions on an <code>Account<\/code> that involves a specific amount. This may e.g. be the case if you want to find out when and if you have made such a transaction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We extend the example in section <script>mkRef(\"Composite values\")<\/script> where we add a <code>find<\/code> method that goes through the <code>transactions<\/code> of a given <code>Account<\/code>. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Account(owner: <strong>ref<\/strong> Customer):\n   -\"-\n   transactions: <strong>obj<\/strong> Set(Transaction)\n   -\"-\n   find(amount: <strong>var<\/strong> float):\n      current: <strong>ref<\/strong> Transaction\n      transaction.scan\n            if current = amount :then\n               this(find).current := current\n               inner(find)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>find<\/code> method has a nested <code>inner(find)<\/code>. It is placed in the singular method descriptor <code>transaction.scan{...},<\/code> which is nested in the method descriptor for <code>find<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that <code>find<\/code> has a variable <code>current<\/code> that has the same name as the variable <code>current<\/code> in <code>scan<\/code>. We therefore use <code>this(find).current<\/code> to denote the <code>current<\/code> declared in <code>find<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We may use <code>find<\/code> in the following way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>anAccount: <strong>ref<\/strong> Account\n...\nanAccount.find(450)\n   console.print(\"A \" + current.what + \" was made on \" + current.whichDate)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Execution of <code>inner(find)<\/code> implies that statements in submethods of <code>find<\/code> are executed. In this case, the <code>console.print<\/code> statement will thus be executed for each transaction where <code>amount<\/code> is equal to 450 &#8211; if any.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Inner in classes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Inner<\/code> may also be used to combine the statements of a superclass and a subclass. We give examples of this in sections <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\"><script>mkRef(\"Active objects and parallel programming\")<\/script><\/mark>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/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=4906\" 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>The&nbsp;inner-statement is central for defining methods that may be used as supermethods of other methods. We take a closer look at what happens when executing anAccount.deposit(500). This implies the following steps: The figure below illustrates the above steps of execution &#8211; the numbers in the figure corresponds to the numbers in the text. The above [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":4900,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-4906","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\/4906","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=4906"}],"version-history":[{"count":18,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/4906\/revisions"}],"predecessor-version":[{"id":9213,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/4906\/revisions\/9213"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/4900"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}