<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/all-sites/layout.xsl"?>
<page>
<title>Metanoia 10.2: Orthogonal Redispatch</title>
<description>The problem with the redispatch in Raku 6 is that each keyword (except wrap) combines three separate concepts into one. Those concepts are:</description>
<category>Metanoias</category>
<author name="Tim Nelson"/>
<sitedir>table-oriented-programming</sitedir>
<filename>Metanoias/Redispatch.xml</filename>
<nav-order>10.2</nav-order>
<content>
<h1>Overview</h1>
<p>The problem with the redispatch in Raku 6 is that each keyword (except wrap)
combines three separate concepts into one.  Those concepts are:</p>

<ul>
  <li><b>Returns:</b> Whether execution continues after the keyword</li>
  <li><b>Arguments:</b> Whether the arguments from the currently executing 
    routine will be reused</li>
  <li><b>Referee:</b> What routine will it call?</li>
</ul>

<p>If we take these three concepts, and represent each of them separately, 
rather than bundling them into a single word, then we can combine them in
ways that aren't possible in Raku 6, and can use them separately where useful.</p>

<p>We deal with these concepts as follows:</p>

<ul>
  <li><b>Returns:</b> We can either use the return-rw keyword, or leave it out;
    no change necessary.  </li>
  <li><b>Arguments:</b> We add a “reuse” modifier to function calls that means 
    that the arguments of the caller are all passed to the callee.  This does 
    away with the distinction between “callsame” and “callwith”.  I've assumed 
    we'd use a :reuse adverb, butI suspect there's a better idea of which I 
    haven't thought.  </li>
  <li><b>Referee:</b> We need only one item: <code>callee</code>.  This is an 
	array (or at least, it does Positional) that lists all the callable
	items in the stack.  <code>callee[0]</code> is the one we'll use to 
	replace</li>
  <ul>
    <li>nextcallee (no change)</li>
    <li>selfcallee (so we can replace samewith)</li>
  </ul>
</ul>

<p>The <code>wrap</code> method doesn't change.</p>

<p>On the down side, this ends up being a bit more wordy, but on the up side, 
a good bit more flexible:</p>

<h1>Method Call Modifiers</h1>

<p>We need to be able to specify some keywords that alter <b>how</b> a method is called.  
I'm going to suggest the syntax ::&lt;keyword&gt;.  Examples could include:</p>

<ul>
  <li><code>::reuse</code> -- </li>
</ul>

<h1>Comparison of Raku 6 and Raku 7</h1>

<p>The following table will compare some Raku 6 code with Raku 7:</p>

<table>
  <tr>
    <th>Raku 6</th>
    <th>Raku 7</th>
    <th>Comments</th>
  </tr>
  <tr>
    <td><code>nextsame</code></td>
    <td><code>return-rw nextcallee(:reuse)</code></td>
    <td></td>
  </tr>
  <tr>
    <td><code>nextwith(@args)</code></td>
    <td><code>return-rw nextcallee(@args)</code></td>
    <td></td>
  </tr>
  <tr>
    <td><code>@rv = callsame</code></td>
    <td><code>@rv = nextcallee(:reuse)</code></td>
    <td></td>
  </tr>
  <tr>
    <td><code>@rv = callwith(@args)</code></td>
    <td><code>@rv = nextcallee(@args)</code></td>
    <td></td>
  </tr>
  <tr>
    <td><code>samewith(@args)</code></td>
    <td><code>selfcallee(@args)</code></td>
    <td></td>
  </tr>
  <tr>
    <td><code>my &amp;nextone = nextcallee</code></td>
    <td><code>my &amp;nextone = nextcallee</code></td>
    <td>No change</td>
  </tr>
  <tr>
    <td><code>nextone(@args)</code></td>
    <td><code>nextone(@args)</code></td>
    <td></td>
  </tr>
  <tr>
    <td>-</td>
    <td><code>selfcallee(:reuse)</code></td>
    <td>Probably not very useful, but maybe</td>
  </tr>
  <tr>
    <td>-</td>
    <td><code>nextone(:reuse)</code></td>
    <td>Could be handy sometime</td>
  </tr>
  <tr>
    <td>-</td>
    <td><code>my &amp;savedcallee = selfcallee;
Promise.in(π²).then: { savedcallee(s) }
    </code></td>
    <td>This one looks pretty handy too</td>
  </tr>
</table>


</content>
</page>
