<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Elizabeth Mattijsen</title>
    <description>The latest articles on Forem by Elizabeth Mattijsen (@lizmat).</description>
    <link>https://forem.com/lizmat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F175135%2F4032db6a-2b31-41ff-9ab6-30c690fe19c5.jpeg</url>
      <title>Forem: Elizabeth Mattijsen</title>
      <link>https://forem.com/lizmat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lizmat"/>
    <language>en</language>
    <item>
      <title>Definitely How What Where, Who?</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Tue, 24 Feb 2026 13:29:22 +0000</pubDate>
      <link>https://forem.com/lizmat/definitely-how-what-where-who-5c5n</link>
      <guid>https://forem.com/lizmat/definitely-how-what-where-who-5c5n</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part thirteen in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the various introspection methods that you can use on objects in the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt;.  Note that in some documentation these methods are also referred to as &lt;a href="https://docs.raku.org/language/mop#Metamethods" rel="noopener noreferrer"&gt;Metamethods&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turtles All The Way Down
&lt;/h2&gt;

&lt;p&gt;In Raku everything is an object, or can be thought of as an object.  An object is an instantiation of a class (usually made by calling the &lt;code&gt;new&lt;/code&gt; method on it).  A class is represented by a so-called &lt;a href="https://docs.raku.org/language/objects#Type_objects" rel="noopener noreferrer"&gt;"type object"&lt;/a&gt;.  Such a type object in turn is an instantation of a so-called &lt;a href="https://docs.raku.org/language/mop" rel="noopener noreferrer"&gt;meta class&lt;/a&gt;.  And these meta classes are themselves built out of more primitive representations.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Going this deep would most definitely be out of scope for these blog posts.  But yours truly does intend to go there at some point in the future.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  WHAT
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://docs.raku.org/syntax/WHAT" rel="noopener noreferrer"&gt;&lt;code&gt;WHAT&lt;/code&gt;&lt;/a&gt; method returns the &lt;a href="https://docs.raku.org/syntax/type%20object" rel="noopener noreferrer"&gt;type object&lt;/a&gt; of the given invocant.  Not much else to tell about it really.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;WHAT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;# (Int)&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;WHAT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# (Str)&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;now&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;WHAT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;# (Instant)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  HOW
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://docs.raku.org/syntax/HOW" rel="noopener noreferrer"&gt;&lt;code&gt;HOW&lt;/code&gt;&lt;/a&gt; method returns the meta-object of the class of the given invocant.  The &lt;code&gt;HOW&lt;/code&gt; (b)acronym stands for "&lt;strong&gt;H&lt;/strong&gt;igher &lt;strong&gt;O&lt;/strong&gt;rder &lt;strong&gt;W&lt;/strong&gt;orkings".  It allows one to introspect the class of the invocant.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;HOW&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;        &lt;span class="c1"&gt;# Int&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;HOW&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;("&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;");&lt;/span&gt;  &lt;span class="c1"&gt;# Str&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;now&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;HOW&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;now&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      &lt;span class="c1"&gt;# Instant&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the invocant of the &lt;code&gt;HOW&lt;/code&gt; method needs to be repeated in the introspection method's call as the first argument.  Why?  Well, this is really to be &lt;em&gt;possibly&lt;/em&gt; compatible with &lt;em&gt;future&lt;/em&gt; versions of Raku.&lt;/p&gt;

&lt;p&gt;Since one is usually only interested in the introspection aspect of &lt;code&gt;HOW&lt;/code&gt;, a shortcut method invocation was created that allows one to directly call the introspection method &lt;strong&gt;without&lt;/strong&gt; needing to repeat oneself: &lt;a href="https://docs.raku.org/language/operators#methodop_%2E^" rel="noopener noreferrer"&gt;&lt;code&gt;.^&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;# Int&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# Str&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;now&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;# Instant&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some other common introspection methods are &lt;a href="https://docs.raku.org/type/Metamodel/C3MRO#method_mro" rel="noopener noreferrer"&gt;&lt;code&gt;mro&lt;/code&gt;&lt;/a&gt; (showing the base classes of the class of the value) and &lt;a href="https://docs.raku.org/routine/methods" rel="noopener noreferrer"&gt;&lt;code&gt;methods&lt;/code&gt;&lt;/a&gt; (which returns the &lt;code&gt;method&lt;/code&gt; objects of the methods that can be called on the value):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;mro&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           &lt;span class="c1"&gt;# ((Int) (Cool) (Any) (Mu))&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# (ACCEPTS Bool Bridge Capture Complex...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that these meta-classes are classes themselves, so can have meta-methods on them called as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;HOW&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# Perl6::Metamodel::ClassHOW&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Yeah, there's still some legacy code that will need renaming under the hood!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  WHERE
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://docs.raku.org/routine/WHERE" rel="noopener noreferrer"&gt;&lt;code&gt;WHERE&lt;/code&gt;&lt;/a&gt; method returns the memory address of the invocant.  It is of limited use in the Rakudo implementation as the memory location of an object is &lt;strong&gt;not&lt;/strong&gt; guaranteed to be constant.  As such, it is intended for (core) debugging only.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;WHERE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# 2912024602280 (or some other number)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  VAR
&lt;/h2&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/lizmat/store-proxy-fetch-a07"&gt;previous blog post&lt;/a&gt; the &lt;code&gt;Scalar&lt;/code&gt; object was described.  But the &lt;code&gt;Scalar&lt;/code&gt; objects are nearly invisible.  How can one obtain a &lt;code&gt;Scalar&lt;/code&gt; object from a given variable?  And find out its name from that?&lt;/p&gt;

&lt;p&gt;The "secret" to that is the &lt;a href="https://docs.raku.org/syntax/VAR" rel="noopener noreferrer"&gt;&lt;code&gt;VAR&lt;/code&gt;&lt;/a&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;VAR&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# Scalar&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each &lt;code&gt;Scalar&lt;/code&gt; object provides at least these &lt;a href="https://docs.raku.org/type/Scalar#Introspection" rel="noopener noreferrer"&gt;introspection methods&lt;/a&gt;: &lt;a href="https://docs.raku.org/type/Scalar#method_of" rel="noopener noreferrer"&gt;&lt;code&gt;of&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://docs.raku.org/type/Scalar#method_name" rel="noopener noreferrer"&gt;&lt;code&gt;name&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://docs.raku.org/type/Scalar#method_default" rel="noopener noreferrer"&gt;&lt;code&gt;default&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://docs.raku.org/type/Scalar#method_dynamic" rel="noopener noreferrer"&gt;&lt;code&gt;dynamic&lt;/code&gt;&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;Int&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;              &lt;span class="c1"&gt;# 666&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;VAR&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;# (Int)&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;VAR&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;# $a&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;VAR&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# 42&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;VAR&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;of&lt;/code&gt; method returns the constraint that needs to be fulfilled in order to be able to assign to the variable.  The &lt;code&gt;name&lt;/code&gt; method returns the name of the variable.  The &lt;code&gt;default&lt;/code&gt; method returns the default value (&lt;code&gt;Any&lt;/code&gt; if none is specified).&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;dynamic&lt;/code&gt; method returns &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt; whether the variable is visible for dynamic variable lookups.  This usually only returns &lt;code&gt;True&lt;/code&gt; for variables with the &lt;a href="https://docs.raku.org/language/variables#The_*_twigil" rel="noopener noreferrer"&gt;&lt;code&gt;*&lt;/code&gt; twigil&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  WHO
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://docs.raku.org/syntax/WHO" rel="noopener noreferrer"&gt;&lt;code&gt;WHO&lt;/code&gt;&lt;/a&gt; method (for "who lives here?) is actually a bit of a misnomer.  It should probably have been called &lt;code&gt;OUR&lt;/code&gt; because it returns the &lt;a href="https://docs.raku.org/type/Stash" rel="noopener noreferrer"&gt;&lt;code&gt;Stash&lt;/code&gt;&lt;/a&gt; of the type object of the invocant.  And a stash is an object that does the &lt;code&gt;Associative&lt;/code&gt; role, and as such can be accessed as if it were a &lt;code&gt;Hash&lt;/code&gt;.  And the stash of a type object is the same namespace as &lt;code&gt;our&lt;/code&gt; inside that package.&lt;/p&gt;

&lt;p&gt;So for instance if you would like to know all classes that live in the &lt;code&gt;IO&lt;/code&gt; package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;WHO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;keys&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# (ArgFiles CatHandle Handle Notification Path Pipe Socket Spec Special)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, you would know them more by their complete names such as &lt;code&gt;IO::ArgFiles&lt;/code&gt;, &lt;code&gt;IO::CatHandle&lt;/code&gt;, &lt;code&gt;IO::Handle&lt;/code&gt;, etc.  In fact the &lt;a href="https://docs.raku.org/language/packages#index-entry-::" rel="noopener noreferrer"&gt;&lt;code&gt;::&lt;/code&gt;&lt;/a&gt; delimiter is shortcut for using &lt;code&gt;WHO&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;WHO&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;Handle&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# (Handle)&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nn"&gt;IO::&lt;/span&gt;&lt;span class="nv"&gt;Handle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;# (Handle)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that goes even further: &lt;code&gt;foo::&lt;/code&gt; is just short for &lt;code&gt;foo.WHO&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nn"&gt;IO::&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;keys&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# (ArgFiles CatHandle Handle Notification Path Pipe Socket Spec Special)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A little closer to home: how would that look in a package that you define yourself and have an &lt;a href="https://docs.raku.org/syntax/our" rel="noopener noreferrer"&gt;&lt;code&gt;our&lt;/code&gt;&lt;/a&gt; scoped variable in there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nb"&gt;package&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;our&lt;/span&gt; &lt;span class="nv"&gt;$foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;WHO&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;$foo&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# 42&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nn"&gt;A::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;$foo&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;# 42&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="nn"&gt;A::&lt;/span&gt;&lt;span class="nv"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;# 42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The careful reader will have noticed that &lt;a href="https://docs.raku.org/language/packages" rel="noopener noreferrer"&gt;&lt;code&gt;package&lt;/code&gt;&lt;/a&gt; was used in the example.  A very simple reason: &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;role&lt;/code&gt;, &lt;code&gt;grammar&lt;/code&gt; are all just packages with different &lt;code&gt;HOW&lt;/code&gt;s.  And &lt;code&gt;WHO&lt;/code&gt; doesn't care why kind of &lt;code&gt;package&lt;/code&gt; it is.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  REPR
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://docs.raku.org/language/traits#is_repr_and_native_representations%2E" rel="noopener noreferrer"&gt;&lt;code&gt;REPR&lt;/code&gt;&lt;/a&gt; method returns the &lt;em&gt;name&lt;/em&gt; of the memory representation of the class of the invocant.  For most of the objects this is "P6opaque".&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is basically the representation used by &lt;code&gt;class&lt;/code&gt; and its attribute specifications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;a href="https://docs.raku.org/language/nativecall" rel="noopener noreferrer"&gt;&lt;code&gt;NativeCall&lt;/code&gt;&lt;/a&gt; module provides a number or alternate memory representations, such as &lt;a href="https://docs.raku.org/language/nativecall#Structs" rel="noopener noreferrer"&gt;&lt;code&gt;CStruct&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://docs.raku.org/language/nativecall#Basic_use_of_pointers" rel="noopener noreferrer"&gt;&lt;code&gt;CPointer&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://docs.raku.org/language/nativecall#CUnions" rel="noopener noreferrer"&gt;&lt;code&gt;Cunion&lt;/code&gt;&lt;/a&gt;.  Native arrays also have a different representation (&lt;code&gt;VMArray&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;REPR&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# P6opaque&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;REPR&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# VMArray&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a class is defined, it gets the &lt;code&gt;P6opaque&lt;/code&gt; representation by default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;REPR&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# P6opaque&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Unless one is doing very deep core-ish work, how an object is represented in memory should not be of concern to you.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  DEFINITE
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://docs.raku.org/syntax/DEFINITE" rel="noopener noreferrer"&gt;&lt;code&gt;DEFINITE&lt;/code&gt;&lt;/a&gt; method returns either &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt; depending on whether the invocant has a concrete representation.  This is &lt;em&gt;almost always&lt;/em&gt; the same as calling the &lt;a href="https://docs.raku.org/routine/defined" rel="noopener noreferrer"&gt;&lt;code&gt;defined&lt;/code&gt;&lt;/a&gt; method.  But in some cases it makes more sense in Raku to return the opposite with the &lt;code&gt;defined&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;An example of this is the &lt;code&gt;Failure&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;Failure&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;DEFINITE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# True&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;Failure&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;# False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In general the &lt;code&gt;defined&lt;/code&gt; method should be used.  The &lt;code&gt;DEFINITE&lt;/code&gt; method is intended to be used in very low-level (core) code.  It's not all uppercase for nothing!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The reason &lt;code&gt;Failure.new.defined&lt;/code&gt; always returns &lt;code&gt;False&lt;/code&gt; is to make it compatible with &lt;a href="https://docs.raku.org/syntax/with%20orwith%20without" rel="noopener noreferrer"&gt;&lt;code&gt;with&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Macroish
&lt;/h2&gt;

&lt;p&gt;All of the introspection "metamethods" described in this blog post are actually parsed as macros directly generating low-level execution opcodes.  This is really necessary in some cases (as otherwise information can be lost), and in other cases it's just for performance.&lt;/p&gt;

&lt;p&gt;This doesn't mean that it's not possible to call this introspection functionality as a method: you can.  For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;macro: &lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;  &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;VAR&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;# macro: $a&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;method: &lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;VAR&lt;/span&gt;&lt;span class="p"&gt;"()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# method: $a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Furthermore for consistency, the same functionality of these methods is &lt;strong&gt;also&lt;/strong&gt; available as subroutines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sub: &lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nv"&gt;VAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# sub: $b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So if you're more at home in imperative programming, you can do that as well!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This concludes the thirteenth episode of cases of UPPER language elements in the Raku Programming Language, the sixth episode discussing interface methods.&lt;/p&gt;

&lt;p&gt;In this episode the following macro-like introspection methods were discussed (in alphabetical order): &lt;code&gt;DEFINITE&lt;/code&gt;, &lt;code&gt;HOW&lt;/code&gt;, &lt;code&gt;REPR&lt;/code&gt;, &lt;code&gt;VAR&lt;/code&gt;, &lt;code&gt;WHAT&lt;/code&gt;, &lt;code&gt;WHERE&lt;/code&gt;, &lt;code&gt;WHO&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next episode!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Raku Resolutions #3</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Sun, 22 Feb 2026 14:23:48 +0000</pubDate>
      <link>https://forem.com/lizmat/raku-resolutions-3-3j6m</link>
      <guid>https://forem.com/lizmat/raku-resolutions-3-3j6m</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is a third follow-up on &lt;a href="https://dev.to/lizmat/series/34948"&gt;Raku Resolutions&lt;/a&gt; series.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The third meeting was held on 21 February 2026 at 19:00 UTC.  Apart from 3 Raku Steering Council members, only 1 other person attended.  In the end, &lt;strong&gt;7&lt;/strong&gt; issues were discussed within the allotted time (1 hour).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/Raku/problem-solving/issues/286" rel="noopener noreferrer"&gt;Separate Community Resource page&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;After some discussion, it became clear that this issue basically has gone stale in light of the new raku.org site.  &lt;em&gt;Richard Hainsworth&lt;/em&gt; will create a new issue, after which this one can be closed.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/Raku/problem-solving/issues/501" rel="noopener noreferrer"&gt;What makes &lt;code&gt;unit&lt;/code&gt; be too late?&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;After some discussion it was agreed that from a language design point of view, it shouldn't really matter when the &lt;code&gt;unit&lt;/code&gt; occurs in the code, as long as there's only one of them.  And that the rest of the source would be considered to be part of that scope.&lt;/p&gt;

&lt;p&gt;It was agreed that the documentation will describe this future state with the caveat that this is currently not yet the case.  &lt;em&gt;Eric Forste&lt;/em&gt; agreed to make a PR accordingly, after which the issue can be closed.&lt;/p&gt;

&lt;p&gt;The point of being able to specify an &lt;code&gt;EXPORT&lt;/code&gt; sub &lt;em&gt;before&lt;/em&gt; a &lt;code&gt;unit&lt;/code&gt; would be technically correct, but not very useful in practice as an &lt;code&gt;EXPORT&lt;/code&gt; sub usually needs to refer to objects/classes that have already been defined in the code (and thus should logically be positioned &lt;em&gt;after&lt;/em&gt; the scope).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/Raku/problem-solving/issues/160" rel="noopener noreferrer"&gt;Errors indexing past the end of a &lt;code&gt;List&lt;/code&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;After some discussion it was decided that the current behaviour of returning &lt;code&gt;Nil&lt;/code&gt; for &lt;code&gt;List&lt;/code&gt; elements beyond the end is correct.  And that returning a &lt;code&gt;Failure&lt;/code&gt; for negative index values is the most consistent behaviour, especially in light of &lt;code&gt;Array&lt;/code&gt; doing that as well.  So the issue could be closed.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/Raku/problem-solving/issues/4" rel="noopener noreferrer"&gt;Some useful math/statistics functions are missing&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Consensus was that it would be nice to have all of these math / statistics methods, but that these should live in module land for the foreseeable future.  So the issue could be closed.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/Raku/problem-solving/issues/5" rel="noopener noreferrer"&gt;There's a huge PR/issue deficit in the Rakudo repo&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;It was recognized that there are indeed quite a few open issues in Rakudo (although much less than there have been in the past).  However, there will always be open issues.  And with the current size of the core team, the number of issues will not significantly reduce in the future (with the current rate of new issues coming in).&lt;/p&gt;

&lt;p&gt;So it was decided to close the issue as "unresolvable".&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/Raku/problem-solving/issues/6" rel="noopener noreferrer"&gt;New named parameters to &lt;code&gt;.classify&lt;/code&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;It was decided that the issue has gone a bit stale, and thus ask the OP (Original Poster) whether this should stay open, especially since it was suggested that &lt;code&gt;.classify&lt;/code&gt; / &lt;code&gt;.categorize&lt;/code&gt; maybe should need an overhaul (at least internally).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/Raku/problem-solving/issues/59" rel="noopener noreferrer"&gt;Need a substitute for Perl 5 &lt;code&gt;die&lt;/code&gt; with newline for raising end-user errors?&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;After explaining the esoteric rule in Perl 5 with regards to &lt;code&gt;die&lt;/code&gt; with a message with and without a new line, it was agreed that it would be nice to have such a feature.  Especially since at least 2 of the attendees had been using a &lt;code&gt;note $message; exit 1&lt;/code&gt; sequence to achieve just that.  Disadvantage to this is that such a sequence can &lt;strong&gt;not&lt;/strong&gt; be caught by a &lt;code&gt;CATCH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After some discussion, a &lt;code&gt;:no-backtrace&lt;/code&gt; named argument to &lt;code&gt;die()&lt;/code&gt; was suggested, and that the issue could be closed if a Pull Requst had been created for this.  This has since then been implemented in &lt;a href="https://github.com/rakudo/rakudo/pull/6076" rel="noopener noreferrer"&gt;#6076&lt;/a&gt;, so the issue was closed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next meeting
&lt;/h2&gt;

&lt;p&gt;The next meeting will be held at 7 March 2026 at 19:00 UTC (20:00 CET, 14:00 EST, 11:00 PST, 04:00 JST (22 Jan), 06:00 AEST (22 Jan)), and again at a one hour maximum. If not all of these issues have been resolved, they will be moved to a future meeting.&lt;/p&gt;

&lt;p&gt;Since Jitsi is still working out so far, the next one will be held at the same URL: &lt;a href="https://meet.jit.si/SpecificRosesEstablishAllegedly" rel="noopener noreferrer"&gt;https://meet.jit.si/SpecificRosesEstablishAllegedly&lt;/a&gt;. The reason Jitsi was selected, is that it has proven to be working with minimal hassle for at least the Raku Steering Council meetings. As the only thing you need to be able to attend, is a modern browser, a camera, and a microphone. No further installation required.&lt;/p&gt;

&lt;p&gt;A new &lt;a href="https://github.com/Raku/problem-solving/issues?q=state%3Aopen%20label%3A%22Next%20Resolutions%20Meeting%22" rel="noopener noreferrer"&gt;set of issues&lt;/a&gt; has been selected by yours truly (in issue number order, oldest first):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/Raku/problem-solving/issues/13" rel="noopener noreferrer"&gt;Specify rounding mode in CORE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Raku/problem-solving/issues/19" rel="noopener noreferrer"&gt;Metadata licenses should be required before adding new modules to ecosystem&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Raku/problem-solving/issues/21" rel="noopener noreferrer"&gt;Semantics of coercion type on an &lt;code&gt;rw&lt;/code&gt; parameter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Raku/problem-solving/issues/24" rel="noopener noreferrer"&gt;where blocks vs sub signatures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Raku/problem-solving/issues/55" rel="noopener noreferrer"&gt;LCM (support &lt;code&gt;Rat&lt;/code&gt; and fail on lossy coercion)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Raku/problem-solving/issues/63" rel="noopener noreferrer"&gt;Should &lt;code&gt;without&lt;/code&gt; allow chaining?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Raku/problem-solving/issues/91" rel="noopener noreferrer"&gt;&lt;code&gt;.raku&lt;/code&gt; should be replaced with a pluggable system&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Preparation
&lt;/h2&gt;

&lt;p&gt;Any Raku Community member is welcome to these meetings.  Do you consider yourself a Raku Community member?  You're welcome.  It's as simple as that.&lt;/p&gt;

&lt;p&gt;But please make sure you have looked at the issues that will be discussed &lt;strong&gt;before&lt;/strong&gt; attending the meeting.  And if you already have any comments to make on these issues, make them with the issue beforehand.&lt;/p&gt;

&lt;p&gt;The original contributors to these issues will also be notified (unless they muted themselves from these issues).  We hope that they also will be able to attend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small steps
&lt;/h2&gt;

&lt;p&gt;If you consider yourself a Raku Community member, please try to attend!  If anything, it will allow you to put faces to the names that you may be familiar with.&lt;/p&gt;

&lt;p&gt;Hope to see you there!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
    </item>
    <item>
      <title>Store Proxy Fetch</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Fri, 20 Feb 2026 11:39:50 +0000</pubDate>
      <link>https://forem.com/lizmat/store-proxy-fetch-a07</link>
      <guid>https://forem.com/lizmat/store-proxy-fetch-a07</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part twelve in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the various aspects of containers in the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Containers and binding
&lt;/h2&gt;

&lt;p&gt;This may come as a shock to some, but Raku really &lt;em&gt;only&lt;/em&gt; knows about &lt;strong&gt;binding&lt;/strong&gt; (&lt;code&gt;:=&lt;/code&gt;) values.  Assignment is &lt;a href="https://en.wikipedia.org/wiki/Syntactic_sugar" rel="noopener noreferrer"&gt;syntactic sugar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;What?&lt;/p&gt;

&lt;p&gt;Most of the scalar variables that you see in Raku, are really objects that have an attribute to which the value is &lt;em&gt;bound&lt;/em&gt; when you &lt;em&gt;assign&lt;/em&gt; to the variable.  These objects are called &lt;a href="https://docs.raku.org/type/Scalar" rel="noopener noreferrer"&gt;&lt;code&gt;Scalar&lt;/code&gt;&lt;/a&gt; containers, or just short &lt;a href="https://docs.raku.org/language/containers" rel="noopener noreferrer"&gt;"containers"&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In short: &lt;strong&gt;assignment in Raku is binding to an attribute in a &lt;code&gt;Scalar&lt;/code&gt; object&lt;/strong&gt;.  &lt;a href="https://en.wikipedia.org/wiki/Grok#In_computer_programmer_culture" rel="noopener noreferrer"&gt;Grokking&lt;/a&gt; how containers work in Raku (as opposed to many other programming languages) is one of the rites of passage to becoming an experienced and efficient developer in Raku.  It sure was a rite of passage for yours truly!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a simplified representation (almost &lt;a href="https://en.wikipedia.org/wiki/Pseudocode" rel="noopener noreferrer"&gt;pseudocode&lt;/a&gt;) one can think of these &lt;code&gt;Scalar&lt;/code&gt; objects like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Scalar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;STORE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$new&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$new&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;FETCH&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And an assignment such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can be thought of as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;Scalar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;STORE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and showing the value of a variable (as in &lt;code&gt;say $a&lt;/code&gt;), can be thought of as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;FETCH&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In reality it's of course slightly more complicated, because there are such things as type constraints that can exist on a variable (such as &lt;code&gt;my Int $a&lt;/code&gt;).  And variables may have a default value (as in &lt;code&gt;my $a is default(42)&lt;/code&gt;).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This type of information is kept in a so-called "container descriptor", which is considered to be an &lt;a href="https://docs.raku.org/syntax/is%20implementation-detai" rel="noopener noreferrer"&gt;implementation detail&lt;/a&gt; (as in: don't depend on its functionality directly, the interface to it might change at any time).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Many shortcuts are made in implementing this, in the interest of performance.  Because assignments are one of the very basic operations in a programming language.  And you want those to be fast!&lt;/p&gt;

&lt;p&gt;As a mental model, this is very useful for understanding quite a few constructs in Raku.&lt;/p&gt;

&lt;h2&gt;
  
  
  Return values
&lt;/h2&gt;

&lt;p&gt;In Raku any value returned at the end of a block (or with the &lt;a href="https://docs.raku.org/syntax/return" rel="noopener noreferrer"&gt;&lt;code&gt;return&lt;/code&gt;&lt;/a&gt; statement) are de-containerized by default.  This means that something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# Cannot modify an immutable Int (42)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will not work.  What if you could return the container from a block?  Then you could just assign to it!  There are indeed two easy ways to return something with the container intact: the &lt;a href="https://docs.raku.org/routine/is%20rw" rel="noopener noreferrer"&gt;&lt;code&gt;is rw&lt;/code&gt;&lt;/a&gt; trait:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nf"&gt;is&lt;/span&gt; &lt;span class="nf"&gt;rw&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# 666&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternately, one can use the &lt;a href="https://docs.raku.org/syntax/return-rw" rel="noopener noreferrer"&gt;&lt;code&gt;return-rw&lt;/code&gt;&lt;/a&gt; statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;rw&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# 666&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This feature is for instance used if you want to assign to an array element.  In &lt;a href="https://dev.to/lizmat/positional-methods-439i"&gt;part 9&lt;/a&gt; of this series it was shown that the &lt;code&gt;AT-POS&lt;/code&gt; method is what is being called by postcircumfix &lt;code&gt;[ ]&lt;/code&gt;.  In the core, both the postcircumfix &lt;code&gt;[ ]&lt;/code&gt; operator as well as the underlying &lt;code&gt;AT-POS&lt;/code&gt; method have this trait set for performance (as the &lt;code&gt;return-rw&lt;/code&gt; statement has slightly more overhead).&lt;/p&gt;

&lt;h2&gt;
  
  
  Binding to containers
&lt;/h2&gt;

&lt;p&gt;If an array is initialized with values, it will create containers for each element and put the right value in the right place.  So you cannot only &lt;em&gt;fetch&lt;/em&gt; the values from there, but you can also &lt;em&gt;assign&lt;/em&gt; to these containers.  And it is also possible to &lt;em&gt;bind&lt;/em&gt; such a container to another variable.&lt;/p&gt;

&lt;p&gt;Binding to containers allows for features in Raku that are considered "magic" by some, and maybe "too magic" by others.  They are part of common idioms in the Raku Programming Language.&lt;/p&gt;

&lt;p&gt;For instance: incrementing all values in an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# [2 3 4 5 6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The topic variable &lt;code&gt;$_&lt;/code&gt; &lt;strong&gt;binds&lt;/strong&gt; to the elements of the array in a &lt;code&gt;for&lt;/code&gt; loop.  So in each iteration it actually represents the container at that location and can thus be incremented.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;People coming from other languages may think that &lt;code&gt;$_&lt;/code&gt; is a "reference" (or "pointer") to the actual memory location of the element in the array.  This notion is incorrect in Raku.  The topic variable &lt;code&gt;$_&lt;/code&gt; is bound to the &lt;strong&gt;container&lt;/strong&gt; of each element.  The container object itself is completely agnostic as to where it lives.  It's just a simple object that knows how to &lt;code&gt;FETCH&lt;/code&gt; and &lt;code&gt;STORE&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Slices to arrays also return containers.  For instance to increment only the first and last element in an array without knowing its size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# [2 2 3 4 6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The slice &lt;code&gt;[0, *-1]&lt;/code&gt; produces 2 containers (one for the first element (&lt;code&gt;0&lt;/code&gt;) and one for the last (&lt;code&gt;*-1&lt;/code&gt;).  Only these containers get incremented, thus giving the expected result.&lt;/p&gt;

&lt;p&gt;The same logic applies to the &lt;a href="https://docs.raku.org/routine/values" rel="noopener noreferrer"&gt;&lt;code&gt;values&lt;/code&gt;&lt;/a&gt; in hashes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# {a =&amp;gt; 43, b =&amp;gt; 667}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But binding containers can also be done directly in your code.  A contrived example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$b&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# 666&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that by assigning to &lt;code&gt;$b&lt;/code&gt;, you're assiging to the container that lives in &lt;code&gt;$a&lt;/code&gt;.  Because the binding of &lt;code&gt;$b&lt;/code&gt; to &lt;code&gt;$a&lt;/code&gt; effectively aliased the container in &lt;code&gt;$a&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Special containers
&lt;/h2&gt;

&lt;p&gt;In Raku it is possible to assign to elements in an array that do not exist yet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# [(Any) (Any) (Any) 42]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So there's no container yet the element at index &lt;code&gt;3&lt;/code&gt;.  Yet it is possible to assign to it!  How does that work?&lt;/p&gt;

&lt;p&gt;The secret is really in the "container descriptor".  So let's refine our pseudocode representation of the &lt;code&gt;Scalar&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Scalar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;STORE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;descriptor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;FETCH&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that storing a value has now become a little more complicated (&lt;code&gt;$!descriptor.process($value)&lt;/code&gt; rather than just &lt;code&gt;$!value&lt;/code&gt;).  So the descriptor object's &lt;code&gt;process&lt;/code&gt; method takes the value, does what it needs to do with it, and then returns it so that it can be bound to the attribute.&lt;/p&gt;

&lt;p&gt;This descriptor object is typically responsible for remembering the name of the variable, the default type, perform type checking and keep a default value of a container.  And any additional logic that is needed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are many different types of container descriptor classes in the Rakudo implementation, all starting with the &lt;code&gt;ContainerDescriptor::&lt;/code&gt; name.  And all are considered to be implementation detail.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For instance, when an &lt;code&gt;AT-POS&lt;/code&gt; method is called on a non-existing element in an array, a container with a special type of descriptor is created that "knows" to which &lt;code&gt;Array&lt;/code&gt; it belongs, and at which index it should be stored.  The same is true for the descriptor of the container returned by &lt;code&gt;AT-KEY&lt;/code&gt; (as seen in &lt;a href="https://dev.to/lizmat/associative-methods-2mcl"&gt;part 10&lt;/a&gt;) which knows in which &lt;code&gt;Hash&lt;/code&gt; it should store when assigned to, and what key should be used.&lt;/p&gt;

&lt;p&gt;It's this special behaviour that allows arrays and hashes to really just &lt;a href="https://docs.raku.org/syntax/DWIM" rel="noopener noreferrer"&gt;DWIM&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Action at a distance
&lt;/h2&gt;

&lt;p&gt;These special descriptors of containers for arrays and hashes also introduce an action-at-a-distance feature that you may or may not like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$b&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# []&lt;/span&gt;
&lt;span class="nv"&gt;$b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# [(Any) (Any) (Any) 42]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the element in the array was &lt;em&gt;not&lt;/em&gt; initialized after the binding, but only &lt;em&gt;after&lt;/em&gt; a value was assigned to &lt;code&gt;$b&lt;/code&gt;.  This behaviour was specifically implemented this way to prevent accidental &lt;a href="https://docs.raku.org/language/subscripts#Autovivification" rel="noopener noreferrer"&gt;auto-vivification&lt;/a&gt;.  For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# False&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;               &lt;span class="c1"&gt;# {}&lt;/span&gt;
&lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;               &lt;span class="c1"&gt;# {a =&amp;gt; {b =&amp;gt; 42}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So even though &lt;code&gt;%h&amp;lt;a&lt;/code&gt;&amp;gt; is considered to be an &lt;code&gt;Associative&lt;/code&gt; because of the &lt;code&gt;&amp;lt;b&amp;gt;&lt;/code&gt;, the &lt;code&gt;:exists&lt;/code&gt; test will &lt;strong&gt;not&lt;/strong&gt; create a &lt;code&gt;Hash&lt;/code&gt; in &lt;code&gt;%h&amp;lt;a&amp;gt;&lt;/code&gt;.  Only &lt;em&gt;after&lt;/em&gt; a value has been assigned does &lt;code&gt;%h&amp;lt;a&amp;gt;&lt;/code&gt; and &lt;code&gt;%h&amp;lt;a&amp;gt;&amp;lt;b&amp;gt;&lt;/code&gt; actually spring to life.&lt;/p&gt;

&lt;h2&gt;
  
  
  Proxy
&lt;/h2&gt;

&lt;p&gt;This rather lengthy introduction / diversion was to make you aware of some of the underlying mechanics of containers.  Because Raku supplies a full customizable class that allows you to create your own container logic: &lt;a href="https://docs.raku.org/type/Proxy" rel="noopener noreferrer"&gt;&lt;code&gt;Proxy&lt;/code&gt;&lt;/a&gt;.  And understanding what containers are about is helpful when working with that class.&lt;/p&gt;

&lt;p&gt;Creation of such a container is quite easy: all you need to supply are a &lt;code&gt;method&lt;/code&gt; for &lt;em&gt;fetching&lt;/em&gt; the value, and a &lt;code&gt;method&lt;/code&gt; for &lt;em&gt;storing&lt;/em&gt; a value (very similar to the pseudocode representation at the start of this blog post).  This is done with the named arguments &lt;code&gt;FETCH&lt;/code&gt; and &lt;code&gt;STORE&lt;/code&gt;.  Creation of a &lt;code&gt;Proxy&lt;/code&gt; object is usually done inside a subroutine for convenience.  A contrived example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;answer&lt;/span&gt; &lt;span class="nf"&gt;is&lt;/span&gt; &lt;span class="nf"&gt;rw&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;Proxy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s"&gt;FETCH&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nv"&gt;$value&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="s"&gt;STORE&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$new&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;storing &lt;/span&gt;&lt;span class="si"&gt;$new&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
          &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$new&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;# 42&lt;/span&gt;
&lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# storing 666&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;# 666&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The careful reader will have noticed that the &lt;code&gt;is rw&lt;/code&gt; attribute needs to be specified on the subroutine, otherwise the &lt;code&gt;Proxy&lt;/code&gt; would be de-containerized on return.  And that the result of calling the &lt;code&gt;answer&lt;/code&gt; subroutine was bound (&lt;code&gt;:=&lt;/code&gt;) instead of assigned, because assignment would also cause de-containerization and thus completely defeat the purpose of this exercise.&lt;/p&gt;

&lt;p&gt;Because the code in the supplied methods &lt;a href="https://docs.raku.org/syntax/closures" rel="noopener noreferrer"&gt;closes over&lt;/a&gt; the lexical variable &lt;code&gt;$value&lt;/code&gt;, that variable stays alive until the &lt;code&gt;Proxy&lt;/code&gt; object is destroyed.  So it offers an easy way to actually store the value for this &lt;code&gt;Proxy&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;Inside the supplied methods you are completely free to put whatever code that you want.  As an example how that could work in a module, the &lt;a href="https://raku.land/zef:lizmat/Hash::MutableKeys" rel="noopener noreferrer"&gt;&lt;code&gt;Hash::MutableKeys&lt;/code&gt;&lt;/a&gt; distribution was created.  Another case of BDD (Blog Driven Development)!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You may have observed that the &lt;code&gt;Proxy&lt;/code&gt; object does not allow for a descriptor.  It was not considered to be needed, as you have all the flexibility you could possibly want.  If you want one in your &lt;code&gt;Proxy&lt;/code&gt; objects, you can create one yourself.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This concludes the twelfth episode of cases of UPPER language elements in the Raku Programming Language, the fifth episode discussing interface methods.&lt;/p&gt;

&lt;p&gt;In this episode containers were described, as well as the special &lt;code&gt;Proxy&lt;/code&gt; class with its named arguments &lt;code&gt;STORE&lt;/code&gt; and &lt;code&gt;FETCH&lt;/code&gt;.  This &lt;code&gt;Proxy&lt;/code&gt; class provides a fully customizable container implementation.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next episode!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Method Not Found Fallback</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Tue, 17 Feb 2026 15:22:31 +0000</pubDate>
      <link>https://forem.com/lizmat/method-not-found-fallback-5cn8</link>
      <guid>https://forem.com/lizmat/method-not-found-fallback-5cn8</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part eleven in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the interface method that can be provided in a class to handle calls to methods that do not actually exist in this class (or its parents).&lt;/p&gt;

&lt;h2&gt;
  
  
  Some background
&lt;/h2&gt;

&lt;p&gt;Method dispatch in the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt; is quite complicated, especially in the case of multi-dispatch.  But the first step is really to see if there is &lt;strong&gt;any&lt;/strong&gt; (multi) method with the given name.&lt;/p&gt;

&lt;p&gt;Internally this is handled by the &lt;a href="https://docs.raku.org/type/Metamodel/MROBasedMethodDispatch#method_find_method" rel="noopener noreferrer"&gt;&lt;code&gt;find_method&lt;/code&gt; method&lt;/a&gt; on the meta-object of the class (which is typically called with the &lt;a href="https://docs.raku.org/language/operators#methodop_%2E^" rel="noopener noreferrer"&gt;&lt;code&gt;.^method&lt;/code&gt; syntax&lt;/a&gt; on the class).&lt;/p&gt;

&lt;p&gt;So for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="c1"&gt;# an empty class&lt;/span&gt;
&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;dd&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;find_method&lt;/span&gt;&lt;span class="p"&gt;("&lt;/span&gt;&lt;span class="s2"&gt;foobar&lt;/span&gt;&lt;span class="p"&gt;");&lt;/span&gt;  &lt;span class="c1"&gt;# Mu&lt;/span&gt;
&lt;span class="nv"&gt;dd&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;find_method&lt;/span&gt;&lt;span class="p"&gt;("&lt;/span&gt;&lt;span class="s2"&gt;gist&lt;/span&gt;&lt;span class="p"&gt;");&lt;/span&gt;    &lt;span class="c1"&gt;# proto method gist (Mu $:: |) {*}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that an empty class &lt;code&gt;A&lt;/code&gt; (which by default inherits from the &lt;a href="https://docs.raku.org/type/Any" rel="noopener noreferrer"&gt;&lt;code&gt;Any&lt;/code&gt; class&lt;/a&gt;) does &lt;strong&gt;not&lt;/strong&gt; provide a method "foobar" (indicated by the &lt;a href="https://docs.raku.org/type/Mu" rel="noopener noreferrer"&gt;&lt;code&gt;Mu&lt;/code&gt; type object&lt;/a&gt;).  But it &lt;em&gt;does&lt;/em&gt; provide a &lt;code&gt;gist&lt;/code&gt; method (indicated by the &lt;code&gt;proto method gist (Mu $:: |) {*}&lt;/code&gt; representation of a &lt;a href="https://docs.raku.org/type/Callable" rel="noopener noreferrer"&gt;&lt;code&gt;Callable&lt;/code&gt;&lt;/a&gt;) because that is inherited from the &lt;code&gt;Any&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;It's this logic that is internally used by the dispatch logic to link a method name to an actual piece of code to be executed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method not found
&lt;/h2&gt;

&lt;p&gt;If the dispatch logic can not find a method by the given name, then it will throw an &lt;a href="https://docs.raku.org/type/X/Method/NotFound" rel="noopener noreferrer"&gt;&lt;code&gt;X::Method::NotFound&lt;/code&gt;&lt;/a&gt; error.  One could of course use a &lt;a href="https://docs.raku.org/language/exceptions#Catching_exceptions" rel="noopener noreferrer"&gt;&lt;code&gt;CATCH&lt;/code&gt;&lt;/a&gt; phaser to handle such cases (as seen in &lt;a href="https://dev.to/lizmat/catch-control-i9o"&gt;part 6&lt;/a&gt; of this series).&lt;/p&gt;

&lt;p&gt;But there's a better and easier way to handle method names that could not be found.  That is, if you're interested in somehow making them less fatal.&lt;/p&gt;

&lt;h2&gt;
  
  
  FALLBACK
&lt;/h2&gt;

&lt;p&gt;If a class provides a &lt;a href="https://docs.raku.org/language/typesystem#Fallback_method" rel="noopener noreferrer"&gt;&lt;code&gt;FALLBACK&lt;/code&gt; method&lt;/a&gt; (either directly in its class, or by one of its base classes, or by ingestion of a role), then that method will be called whenever a method could &lt;em&gt;not&lt;/em&gt; be found.  The name of the method will be passed as the first argument, and all other arguments will be passed verbatim.&lt;/p&gt;

&lt;p&gt;A contrived example in which a non-existing method returns the &lt;em&gt;name&lt;/em&gt; of the method, but only if there were &lt;strong&gt;no&lt;/strong&gt; arguments passed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;B&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;FALLBACK&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;B&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;# foo&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;B&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;# Too many positionals passed; expected 2 arguments but got 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So is there something special about the &lt;code&gt;FALLBACK&lt;/code&gt; method?   No, its only specialty is &lt;em&gt;when&lt;/em&gt; it is being called.  So you can make it a &lt;a href="https://docs.raku.org/syntax/multi-method" rel="noopener noreferrer"&gt;&lt;code&gt;multi&lt;/code&gt; method&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;C&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;multi&lt;/span&gt; &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;FALLBACK&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$name&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nv"&gt;multi&lt;/span&gt; &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;FALLBACK&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$value&lt;/span&gt;&lt;span class="s2"&gt;.raku() passed to '&lt;/span&gt;&lt;span class="si"&gt;$name&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;C&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;# foo&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;C&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;# 42 passed to 'bar'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the other hand if you don't care about any arguments at all and just want to return &lt;a href="https://docs.raku.org/type/Nil" rel="noopener noreferrer"&gt;&lt;code&gt;Nil&lt;/code&gt;&lt;/a&gt;, you can specify the nameless capture &lt;code&gt;|&lt;/code&gt; as the signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;D&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;FALLBACK&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;Nil&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;D&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;# Nil&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;D&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;# Nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  An actual application
&lt;/h2&gt;

&lt;p&gt;The Raku Programming Language allows hyphens in identifier names (usually referred to as &lt;a href="https://en.wikipedia.org/wiki/Letter_case#Kebab_case" rel="noopener noreferrer"&gt;"kebab case"&lt;/a&gt;).  Many programmers coming from other programming languages are not really used to this: they are more comfortable with using underscores in identifiers (&lt;a href="https://en.wikipedia.org/wiki/Letter_case#Snake_case" rel="noopener noreferrer"&gt;"Snake case"&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Modern Raku programs usually use kebab case in identifiers.  So it's quite common for programmers to make the mistake of using an underscore where they should have been using a hyphen.  If such an error is made when writing a program, it will be a runtime error.  Which can be annoying.  In such a case, a &lt;code&gt;FALLBACK&lt;/code&gt; method can be a useful thing to have if it could correct such mistakes.&lt;/p&gt;

&lt;p&gt;This could look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;E&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;foo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foobar&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;FALLBACK&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$corrected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;trans&lt;/span&gt;&lt;span class="p"&gt;("&lt;/span&gt;&lt;span class="s2"&gt;_&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="p"&gt;");&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;find_method&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$corrected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;no_fallback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;&amp;amp;code&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nn"&gt;X::Method::&lt;/span&gt;&lt;span class="nv"&gt;NotFound&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;invocant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;self&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;method&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;typename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.^&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The "E" class has a method "foo-bar".  And a method "FALLBACK" that takes the name of the method that was not found (and putting any additional arguments in the &lt;a href="https://docs.raku.org/type/Capture" rel="noopener noreferrer"&gt;&lt;code&gt;Capture&lt;/code&gt;&lt;/a&gt; "c").&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that the "c" is just an idiom for the name of a capture.  It could have any name, but "c" is nice and short.  If you want to use a name that's more clear to you, then please do so.  As long as you use the same name later on.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It then converts all occurrences of underscore to hyphen in the name and then tries to find a &lt;code&gt;Callable&lt;/code&gt; for that name.  If that is successful it will execute the code with any arguments that were given by flattening the &lt;a href="https://docs.raku.org/language/signatures#Capture_parameters" rel="noopener noreferrer"&gt;&lt;code&gt;|c&lt;/code&gt; capture&lt;/a&gt;.  Otherwise it throws a "method not found" error.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;:no_fallback&lt;/code&gt; argument is needed to prevent the method lookup from producing the "FALLBACK" method if the method was not found.  Otherwise the code would loop forever.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So now this code will work instead of causing an execution error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;say E.foo-bar;  # foobar
say E.foo_bar;  # foobar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make this more generally usable this code could be put into a &lt;a href="https://docs.raku.org/language/objects#Parameterized_roles" rel="noopener noreferrer"&gt;&lt;code&gt;role&lt;/code&gt;&lt;/a&gt; and have that live as an installable module.  But that would be extra work, wouldn't it?&lt;/p&gt;

&lt;p&gt;Fortunately the writing of this blog post initiated the development of such a role (and associated distribution) called &lt;a href="https://raku.land/zef:lizmat/Method::Misspelt" rel="noopener noreferrer"&gt;&lt;code&gt;Method::Misspelt&lt;/code&gt;&lt;/a&gt;.  How's that for BDD (Blog Driven Development)?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that the module introduces a few more features and optimizations, while handling keeping track of multiple classes ingesting the same role.  See the &lt;a href="https://github.com/lizmat/Method-Misspelt/blob/main/lib/Method/Misspelt.rakumod" rel="noopener noreferrer"&gt;internal documentation&lt;/a&gt; for more information.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This concludes the eleventh episode of cases of UPPER language elements in the Raku Programming Language, the fourth episode discussing interface methods.&lt;/p&gt;

&lt;p&gt;In this episode the &lt;code&gt;FALLBACK&lt;/code&gt; method was described, as well as some simple customizations.  And a &lt;a href="https://raku.land/zef:lizmat/Method::Misspelt" rel="noopener noreferrer"&gt;bonus module&lt;/a&gt; created for this blog post only.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next episode!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Associative Methods</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Thu, 12 Feb 2026 19:28:15 +0000</pubDate>
      <link>https://forem.com/lizmat/associative-methods-2mcl</link>
      <guid>https://forem.com/lizmat/associative-methods-2mcl</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part ten in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the interface methods that one can implement to provide a custom &lt;a href="https://docs.raku.org/type/Associative" rel="noopener noreferrer"&gt;&lt;code&gt;Associative&lt;/code&gt;&lt;/a&gt; interface in the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt;.  Associative access is indicated by the &lt;a href="https://docs.raku.org/language/operators#postcircumfix_{_}" rel="noopener noreferrer"&gt;postcircumfix { } operator&lt;/a&gt; (aka the "hash indexing operator").&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In a way this blog post is a &lt;a href="https://en.wikipedia.org/wiki/Fish_Licence" rel="noopener noreferrer"&gt;cat license&lt;/a&gt; ("a dog licence with the word 'dog' crossed out and 'cat' written in crayon") from the &lt;a href="https://dev.to/lizmat/positional-methods-439i"&gt;previous post&lt;/a&gt;.  But there are some subtle differences between the &lt;code&gt;Positional&lt;/code&gt; and the &lt;code&gt;Associative&lt;/code&gt; roles, so just changing all occurrences of "POS" in "KEY" will not cut it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Some background
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Associative&lt;/code&gt; role is really just a marker, just as the &lt;code&gt;Positional&lt;/code&gt; role.  It does &lt;strong&gt;not&lt;/strong&gt; enforce any methods to be provided by the consuming class.  So why use it?  Because it is &lt;em&gt;that&lt;/em&gt; constraint that is being checked for any variable with a &lt;code&gt;%&lt;/code&gt; &lt;a href="https://docs.raku.org/language/glossary#Sigil" rel="noopener noreferrer"&gt;sigil&lt;/a&gt;.  An example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Type check failed in binding; expected Associative but got Foo (Foo)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, if we make that class ingest the &lt;code&gt;Associative&lt;/code&gt; marker role, it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="nv"&gt;does&lt;/span&gt; &lt;span class="nv"&gt;Associative&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# (Any)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and it is even possible to call the postcircumfix &lt;code&gt;{ }&lt;/code&gt; operator on it!  Although it doesn't return anything really useful.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that the binding operator &lt;code&gt;:=&lt;/code&gt; was used: otherwise it would be interpreted as initializing a hash &lt;code&gt;%h&lt;/code&gt; with a single value, which would complain with an "Odd number of elements found where hash initializer expected: Only saw: type object 'Foo'" execution error.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Postcircumfix { }
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;postcircumfix { }&lt;/code&gt; operator performs all of the work of slicing and dicing objects that perform the &lt;code&gt;Associative&lt;/code&gt; role, and handling all of the adverbs: &lt;code&gt;:exists&lt;/code&gt;, &lt;code&gt;:delete&lt;/code&gt;, &lt;code&gt;:p&lt;/code&gt;, &lt;code&gt;:kv&lt;/code&gt;, &lt;code&gt;:k&lt;/code&gt;, and &lt;code&gt;:v&lt;/code&gt;.  But it is completely agnostic about how this is actually done, because all it does is calling the interface methods that are (implicitely) provided by the object, just as with the &lt;code&gt;Positional&lt;/code&gt; role.  Except the names of the interface methods are different.  For instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is actually doing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;AT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;("&lt;/span&gt;&lt;span class="s2"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;");&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;under the hood.  So these interface methods are the ones that actually know how to work on an &lt;a href="https://docs.raku.org/type/Hash" rel="noopener noreferrer"&gt;&lt;code&gt;Hash&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://docs.raku.org/type/Map" rel="noopener noreferrer"&gt;&lt;code&gt;Map&lt;/code&gt;&lt;/a&gt; or a &lt;a href="https://docs.raku.org/type/PseudoStash" rel="noopener noreferrer"&gt;&lt;code&gt;PseudoStash&lt;/code&gt;&lt;/a&gt;, or any other class that does the &lt;code&gt;Associative&lt;/code&gt; role.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Interface Methods
&lt;/h2&gt;

&lt;p&gt;Let's introduce the cast of &lt;em&gt;this&lt;/em&gt; show (the interface methods associated with the &lt;code&gt;Associative&lt;/code&gt; role):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_AT-KEY" rel="noopener noreferrer"&gt;&lt;code&gt;AT-KEY&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_EXISTS-KEY" rel="noopener noreferrer"&gt;&lt;code&gt;EXISTS-KEY&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_DELETE-KEY" rel="noopener noreferrer"&gt;&lt;code&gt;DELETE-KEY&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_ASSIGN-KEY" rel="noopener noreferrer"&gt;&lt;code&gt;ASSIGN-KEY&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_BIND-KEY" rel="noopener noreferrer"&gt;&lt;code&gt;BIND-KEY&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/type/Associative#method_STORE" rel="noopener noreferrer"&gt;&lt;code&gt;STORE&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/type/Map#method_keys" rel="noopener noreferrer"&gt;&lt;code&gt;keys&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  AT-KEY
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;AT-KEY&lt;/code&gt; method is the most important method of the interface methods of the &lt;code&gt;Associative&lt;/code&gt; role: it is expected to take the argument as a key, and return the value associated with that key.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that the key does &lt;strong&gt;not&lt;/strong&gt; need to be a string, it could be any object.  It's just that the implenentation of &lt;code&gt;Hash&lt;/code&gt; and &lt;code&gt;Map&lt;/code&gt; will coerce the key to a string.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;code&gt;AT-KEY&lt;/code&gt; method should return a container if that is appropriate, which is usually the case.  Which means you probably should specify &lt;a href="https://docs.raku.org/routine/is%20raw" rel="noopener noreferrer"&gt;&lt;code&gt;is raw&lt;/code&gt;&lt;/a&gt; on the &lt;code&gt;AT-KEY&lt;/code&gt; method if you're implementing that yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as %h.AT-KEY("bar")&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  EXISTS-KEY
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;EXISTS-KEY&lt;/code&gt; method is expected to take the argument as a key, and return a &lt;a href="https://docs.raku.org/type/Bool" rel="noopener noreferrer"&gt;&lt;code&gt;Bool&lt;/code&gt;&lt;/a&gt; value indicating whether that key is considered to be existing or not.  This is what is being called when the &lt;a href="https://docs.raku.org/type/Hash#:exists" rel="noopener noreferrer"&gt;&lt;code&gt;:exists&lt;/code&gt;&lt;/a&gt; adverb is specified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as %h.EXISTS-KEY("bar")&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  DELETE-KEY
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;DELETE-KEY&lt;/code&gt; method is supposed to act very much like the &lt;code&gt;AT-KEY&lt;/code&gt; method.  But it is also expected to remove the key so that the &lt;code&gt;EXISTS-KEY&lt;/code&gt; method will return &lt;code&gt;False&lt;/code&gt; for that key in the future.  This is what is being called when the &lt;a href="https://docs.raku.org/type/Hash#:delete" rel="noopener noreferrer"&gt;&lt;code&gt;:delete&lt;/code&gt;&lt;/a&gt; adverb is specified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as %h.DELETE-KEY("bar")&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ASSIGN-KEY
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;ASSIGN-KEY&lt;/code&gt; method is a convenience method that &lt;em&gt;may&lt;/em&gt; be called when assigning (&lt;code&gt;=&lt;/code&gt;) a value to a key.  It takes 2 arguments: the key and the value, and is expected to return the value.  It functionally defaults to &lt;code&gt;object.AT-KEY(key) = value&lt;/code&gt;.  A typical reason for implementing this method is performance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as @a.ASSIGN-KEY("bar", 42)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  BIND-KEY
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;BIND-KEY&lt;/code&gt; method is a method that will be called when binding (&lt;code&gt;:=&lt;/code&gt;) a value to a key.  It takes 2 arguments: the key and the value, and is expected to return the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as %h.BIND-KEY("bar", 42)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STORE
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;STORE&lt;/code&gt; method accepts the values (as an &lt;a href="https://docs.raku.org/type/Iterable" rel="noopener noreferrer"&gt;&lt;code&gt;Iterable&lt;/code&gt;&lt;/a&gt;) with which to (re-)initialize the hash, &lt;strong&gt;and&lt;/strong&gt; returns the invocant.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;:INITIALIZE&lt;/code&gt; named argument will be passed with a &lt;code&gt;True&lt;/code&gt; value if this is the first time the values are to be set.  This is important if your data structure is supposed to be immutable: if that argument is &lt;code&gt;False&lt;/code&gt; or not specified, it means a re-initialization is being attempted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as %h.STORE( (a =&amp;gt; 42, b =&amp;gt; 666) )&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  keys
&lt;/h3&gt;

&lt;p&gt;Although not an uppercase named method, it is an important interface method: the &lt;a href="https://docs.raku.org/type/Map#method_keys" rel="noopener noreferrer"&gt;&lt;code&gt;keys&lt;/code&gt;&lt;/a&gt; method is expected to return the keys in the object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# (a b)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Handling simple customizations
&lt;/h2&gt;

&lt;p&gt;Again, that's a lot to take in (especially if you didn't read the previous post)!  But if it is just a simple customization you wish to do to the basic functionality of e.g. a hash, you can simply inherit from the &lt;code&gt;Hash&lt;/code&gt; class.  Here's a simple, contrived example that will return any values doubled as string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nn"&gt;Hash::&lt;/span&gt;&lt;span class="nv"&gt;Twice&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;Hash&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;AT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;callsame&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nn"&gt;Hash::&lt;/span&gt;&lt;span class="nv"&gt;Twice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;: %h{&lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;}&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a: 4242
b: 666666
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that in this case the &lt;a href="https://docs.raku.org/syntax/callsame" rel="noopener noreferrer"&gt;&lt;code&gt;callsame&lt;/code&gt;&lt;/a&gt; function is called to get the actual value from the array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Helpful modules
&lt;/h2&gt;

&lt;p&gt;If you want to be able to do more than just simple modifications, but for instance have an existing data structure on which you want to provide an &lt;code&gt;Associative&lt;/code&gt; interface, it becomes a bit more complicated and potentially cumbersome.&lt;/p&gt;

&lt;p&gt;Fortunately there are a number of modules in the ecosystem that will help you to create a consistent &lt;code&gt;Associative&lt;/code&gt; interface for your class.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hash::Agnostic
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://raku.land/zef:lizmat/Hash::Agnostic" rel="noopener noreferrer"&gt;&lt;code&gt;Hash::Agnostic&lt;/code&gt;&lt;/a&gt; distribution provides a &lt;code&gt;Hash::Agnostic&lt;/code&gt; role with all of the necessary logic for making your object act as a &lt;code&gt;Hash&lt;/code&gt;.  The only methods that &lt;em&gt;must&lt;/em&gt; be provided, are the &lt;code&gt;AT-KEY&lt;/code&gt; and &lt;code&gt;keys&lt;/code&gt; methods.  Your class &lt;em&gt;may&lt;/em&gt; provide more methods for functionality or performance reasons.&lt;/p&gt;

&lt;h3&gt;
  
  
  Map::Agnostic
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://raku.land/zef:lizmat/Map::Agnostic" rel="noopener noreferrer"&gt;&lt;code&gt;Map::Agnostic&lt;/code&gt;&lt;/a&gt; distribution provides a &lt;code&gt;Map::Agnostic&lt;/code&gt; role with all of the necessary logic for making your object act as a &lt;code&gt;Map&lt;/code&gt;.  The only methods that you &lt;em&gt;must&lt;/em&gt; be provided, are the &lt;code&gt;AT-KEY&lt;/code&gt; and &lt;code&gt;keys&lt;/code&gt; methods.  As with &lt;code&gt;Hash::Agnostic&lt;/code&gt;, your class &lt;em&gt;may&lt;/em&gt; provide more methods for functionality or performance reasons.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example class
&lt;/h3&gt;

&lt;p&gt;A very contrived example in which a &lt;code&gt;Hash::Int&lt;/code&gt; class is created that provides an &lt;code&gt;Associative&lt;/code&gt; interface in which the keys can only be integer values.  Under the hood it uses an array to store values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Hash::&lt;/span&gt;&lt;span class="nv"&gt;Agnostic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nn"&gt;Hash::&lt;/span&gt;&lt;span class="nv"&gt;Int&lt;/span&gt; &lt;span class="nv"&gt;does&lt;/span&gt; &lt;span class="nn"&gt;Hash::&lt;/span&gt;&lt;span class="nv"&gt;Agnostic&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;AT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Int:D&lt;/span&gt; &lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;AT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;POS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nb"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;grep&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;EXISTS&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;POS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;STORE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;\&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@values&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;CREATE&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;STORE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;INITIALIZE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;@values&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;ASSIGN&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;POS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;key&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;@values&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and can be used like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nn"&gt;Hash::&lt;/span&gt;&lt;span class="nv"&gt;Int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="mi"&gt;137&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;dd&lt;/span&gt; &lt;span class="nv"&gt;%h&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which would show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a
Hash::Int.new(42 =&amp;gt; "a",137 =&amp;gt; "c",666 =&amp;gt; "b")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, note that the &lt;code&gt;STORE&lt;/code&gt; method had to be provided by the class to allow for the &lt;code&gt;is Hash::Int&lt;/code&gt; syntax to work.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're wondering what's happening with &lt;code&gt;Map.CREATE.STORE(values, :INITIALIZE)&lt;/code&gt;: the initialization logic of hashes and maps allows for both separate key,value initialization, as well as key=&amp;gt;value initialization.  And any mix of them.  So this is just a quick way to use that rather specialized logic of &lt;code&gt;Map.new&lt;/code&gt; to create a consistent &lt;a href="https://docs.raku.org/type/Seq" rel="noopener noreferrer"&gt;&lt;code&gt;Seq&lt;/code&gt;&lt;/a&gt; of &lt;a href="https://docs.raku.org/type/Pair" rel="noopener noreferrer"&gt;&lt;code&gt;Pair&lt;/code&gt;&lt;/a&gt;s with which to initialize the underlying array.&lt;/p&gt;

&lt;p&gt;Raku actually has a syntax for creating a &lt;code&gt;Hash&lt;/code&gt; that only takes &lt;code&gt;Int&lt;/code&gt; values as keys: &lt;code&gt;my %h{Int}&lt;/code&gt;.  This creates a so-called &lt;a href="https://docs.raku.org/language/hashmap#Non-string_keys_(object_hash)" rel="noopener noreferrer"&gt;"object hash"&lt;/a&gt; with different performance characteristics to the approach taken with &lt;code&gt;Hash::Int&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This concludes the tenth episode of cases of UPPER language elements in the Raku Programming Language, the third episode discussing interface methods.&lt;/p&gt;

&lt;p&gt;In this episode the &lt;code&gt;AT-KEY&lt;/code&gt; family of methods were described, as well as some simple customizations and  some handy Raku modules that can help you create a fully functional interface: &lt;code&gt;Map::Agnostic&lt;/code&gt; and &lt;code&gt;Hash::Agnostic&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next episode!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Positional Methods</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Wed, 11 Feb 2026 11:45:37 +0000</pubDate>
      <link>https://forem.com/lizmat/positional-methods-439i</link>
      <guid>https://forem.com/lizmat/positional-methods-439i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part nine in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the interface methods that one can implement to provide a custom &lt;a href="https://docs.raku.org/type/Positional" rel="noopener noreferrer"&gt;&lt;code&gt;Positional&lt;/code&gt;&lt;/a&gt; interface in the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt;.  Positional access is indicated by the &lt;a href="https://docs.raku.org/language/operators#postcircumfix_[_]" rel="noopener noreferrer"&gt;postcircumfix [ ] operator&lt;/a&gt; (aka the "array indexing operator").&lt;/p&gt;

&lt;h2&gt;
  
  
  Some background
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Positional&lt;/code&gt; role is really just a marker.  It does &lt;strong&gt;not&lt;/strong&gt; enforce any methods to be provided by the consuming class.  So why use it?  Because it is &lt;em&gt;that&lt;/em&gt; constraint that is being checked for any variable with an &lt;code&gt;@&lt;/code&gt; &lt;a href="https://docs.raku.org/language/glossary#Sigil" rel="noopener noreferrer"&gt;sigil&lt;/a&gt;.  An example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Type check failed in binding; expected Positional but got Foo (Foo)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, if we make that class ingest the &lt;code&gt;Positional&lt;/code&gt; marker role, it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="nv"&gt;does&lt;/span&gt; &lt;span class="nv"&gt;Positional&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;  &lt;span class="c1"&gt;# (Foo)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and it is even possible to call the postcircumfix &lt;code&gt;[ ]&lt;/code&gt; operator on it!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that the binding operator &lt;code&gt;:=&lt;/code&gt; was used: otherwise the array &lt;code&gt;@a&lt;/code&gt; would just be initialized with the &lt;code&gt;Foo&lt;/code&gt; type object as its first element.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So why is that possible?  That's really possible because each item in Raku can be considered as a single element list.  And thus the first element (aka &lt;code&gt;[0]&lt;/code&gt;) will &lt;strong&gt;always&lt;/strong&gt; provide the invocant.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;  &lt;span class="c1"&gt;# 42&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;  &lt;span class="c1"&gt;# Index out of range. Is: 1, should be in 0..0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which in turn is why the &lt;code&gt;Positional&lt;/code&gt; role does not enforce any methods.  Because they are always already provided by the &lt;a href="https://docs.raku.org/type/Any" rel="noopener noreferrer"&gt;&lt;code&gt;Any&lt;/code&gt; class&lt;/a&gt;, so it would &lt;em&gt;never&lt;/em&gt; complain about methods &lt;em&gt;not&lt;/em&gt; having been provided.&lt;/p&gt;

&lt;h2&gt;
  
  
  Postcircumfix [ ]
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;postcircumfix [ ]&lt;/code&gt; operator performs all of the work of slicing and dicing objects that perform the &lt;code&gt;Positional&lt;/code&gt; role, and handling all of the adverbs: &lt;code&gt;:exists&lt;/code&gt;, &lt;code&gt;:delete&lt;/code&gt;, &lt;code&gt;:p&lt;/code&gt;, &lt;code&gt;:kv&lt;/code&gt;, &lt;code&gt;:k&lt;/code&gt;, and &lt;code&gt;:v&lt;/code&gt;.  But it is completely agnostic about how this is actually done, because all it does is calling the interface methods that are (implicitely) provided by the object.  For instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;  &lt;span class="c1"&gt;# 42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is actually doing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;AT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;POS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;under the hood.  So these interface methods are the ones that actually know how to work on an &lt;a href="https://docs.raku.org/type/Array" rel="noopener noreferrer"&gt;&lt;code&gt;Array&lt;/code&gt;&lt;/a&gt;, a &lt;a href="https://docs.raku.org/type/List" rel="noopener noreferrer"&gt;&lt;code&gt;List&lt;/code&gt;&lt;/a&gt; or a &lt;a href="https://docs.raku.org/type/Blob" rel="noopener noreferrer"&gt;&lt;code&gt;Blob&lt;/code&gt;&lt;/a&gt;, or any other class that does the &lt;code&gt;Positional&lt;/code&gt; role.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Interface Methods
&lt;/h2&gt;

&lt;p&gt;Let's introduce the cast of this show (the interface methods associated with the &lt;code&gt;Positional&lt;/code&gt; role):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_AT-POS" rel="noopener noreferrer"&gt;&lt;code&gt;AT-POS&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_EXISTS-POS" rel="noopener noreferrer"&gt;&lt;code&gt;EXISTS-POS&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_DELETE-POS" rel="noopener noreferrer"&gt;&lt;code&gt;DELETE-POS&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_ASSIGN-POS" rel="noopener noreferrer"&gt;&lt;code&gt;ASSIGN-POS&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_BIND-POS" rel="noopener noreferrer"&gt;&lt;code&gt;BIND-POS&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/language/subscripts#method_STORE" rel="noopener noreferrer"&gt;&lt;code&gt;STORE&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.raku.org/routine/elems#(Subscripts)_method_elems" rel="noopener noreferrer"&gt;&lt;code&gt;elems&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  AT-POS
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;AT-POS&lt;/code&gt; method is the most important method of the interface methods: it is expected to take the integer index of the element to be returned, and return that.  It should return a container if that is appropriate, which is usually the case.  Which means you probably should specify &lt;a href="https://docs.raku.org/routine/is%20raw" rel="noopener noreferrer"&gt;&lt;code&gt;is raw&lt;/code&gt;&lt;/a&gt; on the &lt;code&gt;AT-POS&lt;/code&gt; method if you're implementing that yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;  &lt;span class="c1"&gt;# same as @a.AT-POS($index)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  EXISTS-POS
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;EXISTS-POS&lt;/code&gt; method is expected to take the integer index of an element, and return a &lt;a href="https://docs.raku.org/type/Bool" rel="noopener noreferrer"&gt;&lt;code&gt;Bool&lt;/code&gt;&lt;/a&gt; value indicating whether that element is considered to be existing or not.  This is what is being called when the &lt;a href="https://docs.raku.org/language/subscripts#:exists" rel="noopener noreferrer"&gt;&lt;code&gt;:exists&lt;/code&gt;&lt;/a&gt; adverb is specified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;say @a[$index]:exists;  # same as @a.EXISTS-POS($index)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  DELETE-POS
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;DELETE-POS&lt;/code&gt; method is supposed to act very much like the &lt;code&gt;AT-POS&lt;/code&gt; method.  But is also expected to remove the element so that the &lt;code&gt;EXISTS-POS&lt;/code&gt; method will return &lt;code&gt;False&lt;/code&gt; for that element in the future.  This is what is being called when the &lt;a href="https://docs.raku.org/language/subscripts#:delete" rel="noopener noreferrer"&gt;&lt;code&gt;:delete&lt;/code&gt;&lt;/a&gt; adverb is specified.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;&lt;span class="nb"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as @a.DELETE-POS($index)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ASSIGN-POS
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;ASSIGN-POS&lt;/code&gt; method is a convenience method that &lt;em&gt;may&lt;/em&gt; be called when assigning (&lt;code&gt;=&lt;/code&gt;) a value to an element.  It takes 2 arguments: the index and the value.  It functionally defaults to &lt;code&gt;object.AT-POS(index) = value&lt;/code&gt;.  A typical reason for implementing this method is performance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as @a.ASSIGN-POS($index, 42)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  BIND-POS
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;BIND-POS&lt;/code&gt; method is a method that will be called when binding (&lt;code&gt;:=&lt;/code&gt;) a value to an element.  It takes 2 arguments: the index and the value.  If not implemented, binding will always fail with an execution error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as @a.BIND-POS($index, 42)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STORE
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;STORE&lt;/code&gt; method accepts the values to be (re-)initializing with as an &lt;a href="https://docs.raku.org/type/Iterable" rel="noopener noreferrer"&gt;&lt;code&gt;Iterable&lt;/code&gt;&lt;/a&gt; &lt;strong&gt;and&lt;/strong&gt; returns the invocant (&lt;a href="https://docs.raku.org/syntax/self" rel="noopener noreferrer"&gt;&lt;code&gt;self&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;:INITIALIZE&lt;/code&gt; named argument will be passed with a &lt;code&gt;True&lt;/code&gt; value if this is the first time the values are to be set.  This is important if your data structure is supposed to be immutable: if that argument is &lt;code&gt;False&lt;/code&gt; or not specified, it means a re-initialization is being attempted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;137&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# same as @a.STORE( (42, 666, 137) )&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  elems
&lt;/h3&gt;

&lt;p&gt;Although not an uppercase named method, it is an important interface method: the &lt;a href="https://docs.raku.org/type/List#routine_elems" rel="noopener noreferrer"&gt;&lt;code&gt;elems&lt;/code&gt;&lt;/a&gt; method is expected to return the number of elements in the object.  Basically the highest index value + 1 that can be specified expected to return a value (because indexing starts at 0).&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling simple customizations
&lt;/h2&gt;

&lt;p&gt;Wow, that's a lot to take in!  But if it is just a simple customization you wish to do to the basic functionality of e.g. an array, you can simply inherit from the &lt;code&gt;Array&lt;/code&gt; class.  Here's a simple, contrived example that will return any content of the array doubled as string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nn"&gt;Array::&lt;/span&gt;&lt;span class="nv"&gt;Twice&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;Array&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;AT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;POS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Int:D&lt;/span&gt; &lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;callsame&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nn"&gt;Array::&lt;/span&gt;&lt;span class="nv"&gt;Twice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\@&lt;/span&gt;&lt;span class="s2"&gt;a[&lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;] = &lt;/span&gt;&lt;span class="si"&gt;@a&lt;/span&gt;&lt;span class="s2"&gt;[&lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;]&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@a[0] = aa
@a[1] = bb
@a[2] = cc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that in this case the &lt;a href="https://docs.raku.org/syntax/callsame" rel="noopener noreferrer"&gt;&lt;code&gt;callsame&lt;/code&gt;&lt;/a&gt; function is called to get the actual value from the array.&lt;/p&gt;

&lt;p&gt;Another contrived example where the customization initializes the array with given values in random order (using &lt;a href="https://docs.raku.org/type/List#routine_pick" rel="noopener noreferrer"&gt;&lt;code&gt;.pick&lt;/code&gt;&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nn"&gt;Array::&lt;/span&gt;&lt;span class="nv"&gt;Confused&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;Array&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;STORE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;\&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nn"&gt;Array::&lt;/span&gt;&lt;span class="nv"&gt;STORE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;pick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nn"&gt;Array::&lt;/span&gt;&lt;span class="nv"&gt;Confused&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\@&lt;/span&gt;&lt;span class="s2"&gt;a[&lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;] = &lt;/span&gt;&lt;span class="si"&gt;@a&lt;/span&gt;&lt;span class="s2"&gt;[&lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;]&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@a[0] = b
@a[1] = a
@a[2] = c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that this example uses the fully qualified method syntax (&lt;code&gt;self.Array::STORE&lt;/code&gt;) to set the values in the array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Helpful modules
&lt;/h2&gt;

&lt;p&gt;If you want to be able to do more than just simple modifications, but for instance have an existing data structure on which you want to provide a &lt;code&gt;Positional&lt;/code&gt; interface, it becomes a bit more complicated and potentially cumbersome.&lt;/p&gt;

&lt;p&gt;Fortunately there are a number of modules in the ecosystem that will help you creating a consistent &lt;code&gt;Positional&lt;/code&gt; interface for your class.&lt;/p&gt;

&lt;h3&gt;
  
  
  Array::Agnostic
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://raku.land/zef:lizmat/Array::Agnostic" rel="noopener noreferrer"&gt;&lt;code&gt;Array::Agnostic&lt;/code&gt;&lt;/a&gt; distribution provides an &lt;code&gt;Array::Agnostic&lt;/code&gt; role with all of the necessary logic for making your object act as an &lt;code&gt;Array&lt;/code&gt;.  The only methods that &lt;em&gt;must&lt;/em&gt; be provided, are the &lt;code&gt;AT-POS&lt;/code&gt; and &lt;code&gt;elems&lt;/code&gt; methods.  Your class &lt;em&gt;may&lt;/em&gt; provide more methods for functionality or performance reasons.&lt;/p&gt;

&lt;h3&gt;
  
  
  List::Agnostic
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://raku.land/zef:lizmat/List::Agnostic" rel="noopener noreferrer"&gt;&lt;code&gt;List::Agnostic&lt;/code&gt;&lt;/a&gt; distribution provides a &lt;code&gt;List::Agnostic&lt;/code&gt; role with all of the necessary logic for making your object act as a &lt;code&gt;List&lt;/code&gt;.  The only methods that you &lt;em&gt;must&lt;/em&gt; be provided, are the &lt;code&gt;AT-POS&lt;/code&gt; and &lt;code&gt;elems&lt;/code&gt; methods.  As with &lt;code&gt;Array::Agnostic&lt;/code&gt;, your class &lt;em&gt;may&lt;/em&gt; provide more methods for functionality or performance reasons.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example class
&lt;/h3&gt;

&lt;p&gt;A very contrived example in which a &lt;a href="https://docs.raku.org/type/Date" rel="noopener noreferrer"&gt;&lt;code&gt;Date&lt;/code&gt;&lt;/a&gt; object is going to represented by a 3-element array.  The class looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;List::&lt;/span&gt;&lt;span class="nv"&gt;Agnostic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nn"&gt;Date::&lt;/span&gt;&lt;span class="nv"&gt;Indexed&lt;/span&gt; &lt;span class="nv"&gt;does&lt;/span&gt; &lt;span class="nn"&gt;List::&lt;/span&gt;&lt;span class="nv"&gt;Agnostic&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;date&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;AT&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;POS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;Int:D&lt;/span&gt; &lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;try&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*.&lt;/span&gt;&lt;span class="nv"&gt;year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*.&lt;/span&gt;&lt;span class="nv"&gt;month&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*.&lt;/span&gt;&lt;span class="nv"&gt;day&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="nv"&gt;$index&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;elems&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;STORE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;\&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;date&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;Date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nb"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="sr"&gt;//&lt;/span&gt; &lt;span class="nv"&gt;Date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;today&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;self&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and can be used like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;@a&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nn"&gt;Date::&lt;/span&gt;&lt;span class="nv"&gt;Indexed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2026-02-11&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\@&lt;/span&gt;&lt;span class="s2"&gt;a[&lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;] = &lt;/span&gt;&lt;span class="si"&gt;@a&lt;/span&gt;&lt;span class="s2"&gt;[&lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;]&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="nv"&gt;@a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which would show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@a[0] = 2026
@a[1] = 2
@a[2] = 11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the &lt;code&gt;STORE&lt;/code&gt; method had to be provided by the class to allow for the &lt;code&gt;is Date::Indexed&lt;/code&gt; syntax to work.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're wondering what's happening with &lt;code&gt;try (*.year, *.month, *.day)[$index]($!date)&lt;/code&gt;: that's a list built of 3 &lt;a href="https://docs.raku.org/type/WhateverCode" rel="noopener noreferrer"&gt;&lt;code&gt;WhateverCode&lt;/code&gt;&lt;/a&gt;s with the specified index selecting the appropriate entry and executing that with the &lt;code&gt;$!date&lt;/code&gt; attribute as the invocant.  If that would fail (probably because the index was out of range), then the &lt;a href="https://docs.raku.org/syntax/try%20%28statement%20prefix%29" rel="noopener noreferrer"&gt;&lt;code&gt;try&lt;/code&gt;&lt;/a&gt; will make sure that the error is caught and a &lt;code&gt;Nil&lt;/code&gt; is returned.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This concludes the ninth episode of cases of UPPER language elements in the Raku Programming Language, the second  episode discussing interface methods.&lt;/p&gt;

&lt;p&gt;In this episode the &lt;code&gt;AT-POS&lt;/code&gt; family of methods were described, as well as some simple customizations and  some handy Raku modules that can help you create a fully functional interface: &lt;code&gt;List::Agnostic&lt;/code&gt; and &lt;code&gt;Array::Agnostic&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next episode!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The second two</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Sun, 08 Feb 2026 19:29:26 +0000</pubDate>
      <link>https://forem.com/lizmat/the-second-two-1k5d</link>
      <guid>https://forem.com/lizmat/the-second-two-1k5d</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is a second follow-up on &lt;a href="https://dev.to/lizmat/series/34948"&gt;Raku Resolutions&lt;/a&gt; series.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The second meeting was held on 7 February 2026 at 19:00 UTC.  Apart from 4 Raku Steering Council members, up to 5 other people attended with a true worldwide spread: local times spanning from UTC-8 to UTC+11!  Thank you all for your attendance and your feedback!&lt;/p&gt;

&lt;p&gt;In the end, &lt;strong&gt;2&lt;/strong&gt; issues were discussed within the allotted time (1 hour).  Both had extensive discussions, but no immediate resoluton.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://github.com/Raku/problem-solving/issues/489" rel="noopener noreferrer"&gt;Raku Classification System&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This discussion took most of the time, as it is indeed could be a very big project.  It was felt that this was a project worth pursuing, and that having more meta-data on Raku and its uses would be very valuable.  &lt;em&gt;Tim Nelson&lt;/em&gt; &lt;a href="https://github.com/Raku/problem-solving/issues/489#issuecomment-3865236200" rel="noopener noreferrer"&gt;replied after the meeting&lt;/a&gt;.  To be continued (but probably through the issue, and not merely at these meetings).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://github.com/Raku/problem-solving/issues/337" rel="noopener noreferrer"&gt;Function return types should also tell about the used assignment/container&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;It became clear that this is not just a documentation issue, but in a way a language design (and implementation) issue as well.  The argument was made that when some functionality is made that returns a mutable entity, it should be clearly visible (for instance &lt;a href="https://docs.raku.org/type/Str#routine_substr" rel="noopener noreferrer"&gt;&lt;code&gt;substr&lt;/code&gt;&lt;/a&gt; versus &lt;a href="https://docs.raku.org/type/Str#method_substr-rw" rel="noopener noreferrer"&gt;&lt;code&gt;substr-rw&lt;/code&gt;&lt;/a&gt;).  &lt;em&gt;Márton Polgar&lt;/em&gt; summarized &lt;a href="https://github.com/Raku/problem-solving/issues/337#issuecomment-3867569693" rel="noopener noreferrer"&gt;the result&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The next meeting
&lt;/h2&gt;

&lt;p&gt;The next meeting will be held at 21 February 2026 at 19:00 UTC (20:00 CET, 14:00 EST, 11:00 PST, 04:00 JST (22 Jan), 06:00 AEST (22 Jan)), and again at a one hour maximum.  If not all of these issues have been resolved, they will be moved to a future meeting.&lt;/p&gt;

&lt;p&gt;Since Jitsi is still working out so far, the next one will be held at the same URL: &lt;a href="https://meet.jit.si/SpecificRosesEstablishAllegedly" rel="noopener noreferrer"&gt;https://meet.jit.si/SpecificRosesEstablishAllegedly&lt;/a&gt;.  The reason Jitsi was selected, is that it has proven to be working with minimal hassle for at least the Raku Steering Council meetings.  As the only thing you need to be able to attend, is a modern browser, a camera, and a microphone.  No further installation required.&lt;/p&gt;

&lt;p&gt;The remaining issues that will be discussed, are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/Raku/problem-solving/issues/286" rel="noopener noreferrer"&gt;Separate Community Resource pages&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Raku/problem-solving/issues/501" rel="noopener noreferrer"&gt;What makes &lt;code&gt;unit&lt;/code&gt; be too late?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and any other issues that people want to discuss.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparation
&lt;/h2&gt;

&lt;p&gt;Any Raku Community member is welcome to this meeting.  Do you consider yourself a Raku Community member?  You're welcome.  It's as simple as that.&lt;/p&gt;

&lt;p&gt;But please make sure you have looked at the issues that will be discussed &lt;strong&gt;before&lt;/strong&gt; attending the meeting.  And if you already have any comments to make on these issues, make them with the issue beforehand.&lt;/p&gt;

&lt;p&gt;The original contributors to these issues will also be notified (unless they muted themselves from these issues).  We hope that they also will be able to attend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small steps
&lt;/h2&gt;

&lt;p&gt;If you consider yourself a Raku Community member, please try to attend!  If anything, it will allow you to put faces to the names that you may be familiar with.&lt;/p&gt;

&lt;p&gt;Hope to see you there!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
    </item>
    <item>
      <title>Tweak Build</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Sun, 08 Feb 2026 13:08:48 +0000</pubDate>
      <link>https://forem.com/lizmat/tweak-build-fhg</link>
      <guid>https://forem.com/lizmat/tweak-build-fhg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part eight in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the interface methods that one can provide to tweak the creation of objects in the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  But first some background
&lt;/h2&gt;

&lt;p&gt;If you are unfamiliar as to how Raku allows one to create classes, describe attributes and methods, it is recommended to first have a look at &lt;a href="https://docs.raku.org/language/classtut" rel="noopener noreferrer"&gt;Classes and objects - A tutorial about creating and using classes in Raku&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In short: by default, objects are created with the &lt;a href="https://docs.raku.org/syntax/new%20%28method%29#(Object_orientation)_new_(method)_new_(method)" rel="noopener noreferrer"&gt;&lt;code&gt;.new&lt;/code&gt;&lt;/a&gt; method (which is provided by the &lt;a href="https://docs.raku.org/type/Mu" rel="noopener noreferrer"&gt;&lt;code&gt;Mu&lt;/code&gt; base class&lt;/a&gt;).  This &lt;code&gt;.new&lt;/code&gt; method takes named arguments and tries to match these with attribute names that are supposed to be set with &lt;code&gt;.new&lt;/code&gt;.  Any unmatched named arguments are silently ignored. &lt;/p&gt;

&lt;p&gt;Attributes that are settable with &lt;code&gt;.new&lt;/code&gt; that are &lt;strong&gt;not&lt;/strong&gt; specified will have any default value applied to them.  A small example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# attribute + accessor&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;               &lt;span class="c1"&gt;# 42&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# 666&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, actually that is a little white lie.  But it &lt;em&gt;is&lt;/em&gt; true in most cases.&lt;/p&gt;

&lt;p&gt;The thing is that you can also specify your own &lt;code&gt;.new&lt;/code&gt; method in your class, and &lt;strong&gt;still&lt;/strong&gt; have all of the attribute initialization work done for you.  The reason for this is that it's not really the &lt;code&gt;.new&lt;/code&gt; method that is doing the work, but the &lt;a href="https://docs.raku.org/routine/bless" rel="noopener noreferrer"&gt;&lt;code&gt;.bless&lt;/code&gt;&lt;/a&gt; method that is also provided by the &lt;code&gt;Mu&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;Functionally the &lt;code&gt;.new&lt;/code&gt; method supplied by &lt;code&gt;Mu&lt;/code&gt; is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;bless&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|%&lt;/span&gt;&lt;span class="nv"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;although in reality it's a little bit more complex more allowing for some optimizations.  Object creation occurs a &lt;strong&gt;lot&lt;/strong&gt; when you're executing a Raku program, so it makes sense to try to optimize that!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that methods in Raku always have a &lt;code&gt;*%_&lt;/code&gt; (aka a &lt;a href="https://docs.raku.org/language/signatures#index-entry-slurpy_argument" rel="noopener noreferrer"&gt;"slurpy hash"&lt;/a&gt;) added to their signature, unless there is already a slurpy hash in the signature.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An example of a custom &lt;code&gt;.new&lt;/code&gt; method that takes a single positional argument:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;multi&lt;/span&gt; &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$bar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;bless&lt;/span&gt;&lt;span class="p"&gt;(:&lt;/span&gt;&lt;span class="nv"&gt;$bar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;|%&lt;/span&gt;&lt;span class="nv"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;               &lt;span class="c1"&gt;# 42&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;666&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# 666&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="mi"&gt;137&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;# 137&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason that this &lt;em&gt;also&lt;/em&gt; allows the named argument way, is because of the &lt;a href="https://docs.raku.org/syntax/multi" rel="noopener noreferrer"&gt;&lt;code&gt;multi&lt;/code&gt;&lt;/a&gt;.  This &lt;strong&gt;adds&lt;/strong&gt; a candidate to the existing dispatch table for the &lt;code&gt;.new&lt;/code&gt; method, so the &lt;code&gt;Mu.new&lt;/code&gt; candidate can still be dispatched to.  Without the &lt;code&gt;multi&lt;/code&gt; there would only be the one &lt;code&gt;.new&lt;/code&gt; method in the dispatch table for &lt;code&gt;class Foo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Also note the &lt;code&gt;|%_&lt;/code&gt; in the &lt;code&gt;self.bless&lt;/code&gt; call: this makes sure that any additional named argments are also passed to &lt;code&gt;.bless&lt;/code&gt; if you specify a positional argument.&lt;/p&gt;

&lt;h2&gt;
  
  
  BUILD vs TWEAK
&lt;/h2&gt;

&lt;p&gt;Any class in Raku can have a &lt;a href="https://docs.raku.org/syntax/BUILD" rel="noopener noreferrer"&gt;&lt;code&gt;BUILD&lt;/code&gt;&lt;/a&gt; and/or a &lt;a href="https://docs.raku.org/syntax/TWEAK" rel="noopener noreferrer"&gt;&lt;code&gt;TWEAK&lt;/code&gt;&lt;/a&gt; method specified.  Both are called by the object building logic, but only if it is possible to call them.  Both methods receive the same arguments as having been (indirectly) passed to &lt;code&gt;.bless&lt;/code&gt;.  The return value of these methods will be ignored.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;BUILD&lt;/code&gt; method is called &lt;strong&gt;instead&lt;/strong&gt; of attribute initializations from the named arguments.  Specifying the &lt;code&gt;BUILD&lt;/code&gt; method means needing to mimic &lt;strong&gt;all&lt;/strong&gt; named argument setting in that &lt;code&gt;BUILD&lt;/code&gt; method..&lt;/p&gt;

&lt;p&gt;Any default values for attributes are assigned if the attribute did not receive a value yet (either from attribute initializations from the named arguments, or having been initialized in the &lt;code&gt;BUILD&lt;/code&gt; method).&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;TWEAK&lt;/code&gt; method is called as the &lt;strong&gt;last stage&lt;/strong&gt; of object instantiation.  Nowadays it is the recommended way of altering the named argument -&amp;gt; attribute initialization logic for a class (after all initializations and default setting has been done).&lt;/p&gt;

&lt;h2&gt;
  
  
  BUILDPLAN
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https:://rakud.org" rel="noopener noreferrer"&gt;Rakudo&lt;/a&gt; distribution comes with a handy introspection module that shows what steps are taken (in pseudo-code) in the creation of an instance of a class: &lt;code&gt;BUILDPLAN&lt;/code&gt;.  It's use is pretty simple: &lt;code&gt;use BUILDPLAN class&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nv"&gt;BUILDPLAN&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Foo BUILDPLAN:
 0 nqp::getattr(obj,Foo,'$!bar') = :$bar if possible
 1 nqp::getattr(obj,Foo,'$!bar') = 42 if not set
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that there are two steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;assign value of named argument "bar" to the attribute "$!bar" if specified&lt;/li&gt;
&lt;li&gt;assign value &lt;code&gt;42&lt;/code&gt; to the "$!bar" attribute if it has not been set yet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, if we add a &lt;code&gt;BUILD&lt;/code&gt; method to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;submethod&lt;/span&gt; &lt;span class="nv"&gt;BUILD&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nv"&gt;BUILDPLAN&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the build plan changes to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Foo BUILDPLAN:
 0 call obj.Foo::BUILD
 1 nqp::getattr(obj,Foo,'$!bar') = 42 if not set
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the first step changed from "nqp::getattr(obj,Foo,'$!bar') = :$bar if possible" to "call obj.Foo::BUILD".  So instead of looking for a named argument "bar", it is now just calling the "BUILD" method.&lt;/p&gt;

&lt;p&gt;Also note that second step stayed the same: so if the &lt;code&gt;BUILD&lt;/code&gt; method doesn't assign anything to the &lt;code&gt;$!bar&lt;/code&gt; attribute, the default value will &lt;em&gt;still&lt;/em&gt; be set.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tricks and Tips
&lt;/h2&gt;

&lt;p&gt;Historically the &lt;code&gt;BUILD&lt;/code&gt; method was one of the first things actually implemented in Raku, and thus a lot of (older) code in the wild uses the &lt;code&gt;BUILD&lt;/code&gt; method.  Since then many features have been added to the way one can specify attributes, obsoleting some of the common &lt;code&gt;BUILD&lt;/code&gt; uses.&lt;/p&gt;

&lt;p&gt;Here are some examples of outdated idioms:&lt;/p&gt;

&lt;h3&gt;
  
  
  Making a named argument required
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;BUILD&lt;/code&gt; method can make a named argument for the creation of the object mandatory by making it a required named argument of &lt;code&gt;BUILD&lt;/code&gt; (by adding a &lt;code&gt;!&lt;/code&gt; in the signature):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;submethod&lt;/span&gt; &lt;span class="nv"&gt;BUILD&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$bar&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$bar&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The better way is to use the &lt;a href="https://docs.raku.org/syntax/is%20required" rel="noopener noreferrer"&gt;&lt;code&gt;is required&lt;/code&gt;&lt;/a&gt; trait on attributes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;required&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Allowing a named argument without automatic accessor
&lt;/h3&gt;

&lt;p&gt;By allowing a named argument in the &lt;code&gt;BUILD&lt;/code&gt; signature and assigning that to the attribute in the body, you're effectively mimicing the &lt;code&gt;.&lt;/code&gt; twigil in the attribute definition without having an accessor made automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;submethod&lt;/span&gt; &lt;span class="nv"&gt;BUILD&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$bar&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$bar&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The better way is to use the &lt;a href="https://docs.raku.org/syntax/is%20built" rel="noopener noreferrer"&gt;&lt;code&gt;is built&lt;/code&gt;&lt;/a&gt; attribute trait:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Foo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;bar&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;built&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When to use TWEAK
&lt;/h2&gt;

&lt;p&gt;Looking at the modules in the ecosystem, the &lt;code&gt;TWEAK&lt;/code&gt; method is oftentimes being used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;throwing an error if some complicate condition is not met&lt;/li&gt;
&lt;li&gt;throwing an error if conflicting arguments have been specified&lt;/li&gt;
&lt;li&gt;starting async workers once the object is fully fleshed&lt;/li&gt;
&lt;li&gt;setting up a (fast) data-structure based on the attributes supplied&lt;/li&gt;
&lt;li&gt;setting attributes from information supplied in a (JSON) hash&lt;/li&gt;
&lt;li&gt;reading / parsing a file into additional attributes&lt;/li&gt;
&lt;li&gt;inform a logger when an object has been created&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You typically should &lt;strong&gt;not&lt;/strong&gt; use a &lt;code&gt;TWEAK&lt;/code&gt; method if you can achieve the same effect with an extensive specification of the attributes.  First of all the declarative manner in which these are specified is easier to comprehend.  Secondly, the processing of the named arguments and their specificaton is highly optimized.  Compare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ raku -e 'class A { has $.a = 42 }; A.new for ^1000000; say now - ENTER now'
0.080668357
$ raku -e 'class A { has $.a; method TWEAK(:$a) { $!a = $a // 42 }; A.new for ^1000000; say now - ENTER now'
0.122443318
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which shows that using proper attribute declarations is at least 30% faster.  Well in this case.  YMMV.&lt;/p&gt;

&lt;p&gt;If you're more comfortable with using a &lt;code&gt;TWEAK&lt;/code&gt; method, then please do.  There's more than one way to do it!&lt;/p&gt;

&lt;h2&gt;
  
  
  submethod vs method
&lt;/h2&gt;

&lt;p&gt;A &lt;a href="https://docs.raku.org/syntax/Submethods" rel="noopener noreferrer"&gt;&lt;code&gt;submethod&lt;/code&gt;&lt;/a&gt; is a special type of public method, but which is &lt;strong&gt;not&lt;/strong&gt; inherited by subclasses.  &lt;code&gt;TWEAK&lt;/code&gt; and &lt;code&gt;BUILD&lt;/code&gt; methods should be made &lt;code&gt;submethod&lt;/code&gt;s, because otherwise they can get executed more than once if they are in a base class, and the inheriting class does &lt;strong&gt;not&lt;/strong&gt; specify its own &lt;code&gt;TWEAK&lt;/code&gt; or &lt;code&gt;BUILD&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;method&lt;/span&gt; &lt;span class="nv"&gt;TWEAK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;B&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;B&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A
A
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because class "B" inherited the &lt;code&gt;TWEAK&lt;/code&gt; method from "A".  And at object initialization, the &lt;code&gt;BUILDPLAN&lt;/code&gt; of each class in the class hierarchy is executed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This concludes the eight episode of cases of UPPER language elements in the Raku Programming Language, the first discussion interface methods.&lt;/p&gt;

&lt;p&gt;In this episode the &lt;code&gt;TWEAK&lt;/code&gt; and &lt;code&gt;BUILD&lt;/code&gt; methods were described, with a supporting role for the &lt;code&gt;BUILDPLAN&lt;/code&gt; module.  In short: don't use &lt;code&gt;BUILD&lt;/code&gt; if you can use &lt;code&gt;TWEAK&lt;/code&gt;.  Don't use &lt;code&gt;TWEAK&lt;/code&gt; if you can describe the same logic in the attribute specifications.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next episode!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Doc Mirages</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Wed, 04 Feb 2026 22:18:26 +0000</pubDate>
      <link>https://forem.com/lizmat/doc-mirages-1aj9</link>
      <guid>https://forem.com/lizmat/doc-mirages-1aj9</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part seven in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the final set of (non-)existing phasers in the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  But first: --doc
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;--doc&lt;/code&gt; command line argument to &lt;code&gt;raku&lt;/code&gt; is described as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--doc         extract documentation and print it as text
--doc=module  use Pod::To::[module] to render inline documentation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what that basically does, is process the source of the program to be executed as documentation, and render that documentation in various forms.&lt;/p&gt;

&lt;p&gt;Internally this is achieved by loading the &lt;code&gt;Pod::To::xxx&lt;/code&gt; module (with "xxx" defaulting to "Text" in case of &lt;code&gt;--doc&lt;/code&gt; without arguments).  It then installs an &lt;code&gt;INIT&lt;/code&gt; phaser that basically does:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;INIT&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nn"&gt;Pod::To::&lt;/span&gt;&lt;span class="nv"&gt;xxx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;pod&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the &lt;code&gt;Pod::To::Text&lt;/code&gt; module is  installed as part of the rakudo distribution (whether it should be considered part of the Raku Programming Language specification is yet unclear).&lt;/p&gt;

&lt;p&gt;Other renderers such as &lt;a href="https://raku.land/zef:raku-community-modules/Pod::To::HTML" rel="noopener noreferrer"&gt;&lt;code&gt;Pod::To::HTML&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://raku.land/zef:dwarring/Pod::To::PDF" rel="noopener noreferrer"&gt;&lt;code&gt;Pod::To::PDF&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://raku.land/zef:raku-community-modules/Pod::To::Markdown" rel="noopener noreferrer"&gt;&lt;code&gt;Pod::To::Markdown&lt;/code&gt;&lt;/a&gt; would have to be installed first from the ecosystem (e.g. &lt;code&gt;zef install Pod::To::Markdown&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;With that under our belt, we can start discussing the &lt;code&gt;DOC&lt;/code&gt; phaser.&lt;/p&gt;

&lt;h2&gt;
  
  
  DOC
&lt;/h2&gt;

&lt;p&gt;There is not one single &lt;a href="https://docs.raku.org/syntax/DOC" rel="noopener noreferrer"&gt;&lt;code&gt;DOC&lt;/code&gt;&lt;/a&gt; phaser, there are actually three of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;DOC BEGIN&lt;/code&gt; - add &lt;code&gt;BEGIN&lt;/code&gt; phaser but only if --doc is set&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DOC CHECK&lt;/code&gt; - add &lt;code&gt;CHECK&lt;/code&gt; phaser but only if --doc is set&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DOC INIT&lt;/code&gt; - add &lt;code&gt;INIT&lt;/code&gt; phaser but only if --doc is set&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another way of thinking about this, is that the &lt;code&gt;DOC&lt;/code&gt; phaser could be thought of as a sort of statement prefix that will add the phaser only if &lt;code&gt;--doc&lt;/code&gt; was specified on the command line.  In pseudo-code, for &lt;code&gt;DOC BEGIN&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if --doc is set {
    BEGIN ...;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that if the &lt;code&gt;--doc&lt;/code&gt; is &lt;strong&gt;not&lt;/strong&gt; specified, the phasers will &lt;strong&gt;not&lt;/strong&gt; be executed.  Observe the difference between:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ raku -e 'DOC BEGIN say "begin"; DOC CHECK say "check"; DOC INIT say "init"'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;not showing anything, while:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ raku --doc -e 'DOC BEGIN say "begin"; DOC CHECK say "check"; DOC INIT say "init"'
begin
check
init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;will&lt;/em&gt; execute the phasers and shows the output.&lt;/p&gt;

&lt;p&gt;There's only one "but": even though the &lt;code&gt;DOC&lt;/code&gt; phasers are only added if &lt;code&gt;--doc&lt;/code&gt; is specified, they &lt;em&gt;must&lt;/em&gt; contain valid Raku code to prevent errors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ raku -e 'DOC BEGIN +-+'            
===SORRY!=== Error while compiling -e
Prefix + requires an argument, but no valid term found.
Did you mean + to be an opening bracket for a declarator block?
at -e:1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what use are they?  Looking at the ecosystem, there actually only appears to be &lt;strong&gt;one&lt;/strong&gt; type of use that makes sense.  And that is functionality offered by the &lt;a href="https://raku.land/zef:raku-community-modules/Pod::EOD" rel="noopener noreferrer"&gt;&lt;code&gt;POD::EOD&lt;/code&gt; module&lt;/a&gt;, which places &lt;a href="https://docs.raku.org/language/pod#Declarator_blocks" rel="noopener noreferrer"&gt;declarator documentation&lt;/a&gt; at the end of the documentation, rather than where they occur in the source code.  Which works because it directly modifies the content of the &lt;code&gt;$=pod&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;Yours truly has not been able to find any other (correct) usage.&lt;/p&gt;

&lt;h2&gt;
  
  
  TEMP
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;TEMP&lt;/code&gt; phaser is a bit of a mirage.  In the &lt;a href="https://github.com/Raku/old-design-docs/tree/master?tab=readme-ov-file#perl6-design-documents" rel="noopener noreferrer"&gt;old design documents&lt;/a&gt; it was mentioned in &lt;a href="https://github.com/Raku/old-design-docs/blob/master/S06-routines.pod#temporization" rel="noopener noreferrer"&gt;S06 - Temporization&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However it looks like sometime in May 2012 &lt;a href="https://docs.raku.org/routine/let" rel="noopener noreferrer"&gt;&lt;code&gt;let&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://docs.raku.org/routine/temp" rel="noopener noreferrer"&gt;&lt;code&gt;temp&lt;/code&gt;&lt;/a&gt; were implemented.  But the described &lt;code&gt;TEMP&lt;/code&gt; phaser never was implemented in all of the years since then.  Probably because the functionality of &lt;code&gt;temp&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; covered almost all use cases, combined with the &lt;a href="https://docs.raku.org/syntax/KEEP" rel="noopener noreferrer"&gt;&lt;code&gt;KEEP&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://docs.raku.org/syntax/UNDO" rel="noopener noreferrer"&gt;&lt;code&gt;UNDO&lt;/code&gt;&lt;/a&gt; phasers, so nobody felt the need to actually implement support for it.&lt;/p&gt;

&lt;p&gt;Oddly enough the syntax for the &lt;code&gt;TEMP&lt;/code&gt; phaser &lt;em&gt;does&lt;/em&gt; exist.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ raku -e 'TEMP say "temp"; say "alive";
alive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But it just doesn't do anything.  And after this blog post, chances are that the support for the syntax will be removed (see &lt;a href="https://github.com/Raku/problem-solving/issues/511" rel="noopener noreferrer"&gt;problem solving issue&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  COMPOSE
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://docs.raku.org/syntax/COMPOSE" rel="noopener noreferrer"&gt;&lt;code&gt;COMPOSE&lt;/code&gt; phaser&lt;/a&gt; is even more of a mirage, as it is &lt;em&gt;not even partly implemented&lt;/em&gt;.  Its only mention is in the &lt;a href="https://github.com/Raku/old-design-docs/blob/master/S04-control.pod#phasers" rel="noopener noreferrer"&gt;S04 - Phasers&lt;/a&gt; section of the old design documentation.&lt;/p&gt;

&lt;p&gt;However developers wanting to use &lt;a href="https://docs.raku.org/language/glossary#Roles" rel="noopener noreferrer"&gt;roles&lt;/a&gt; when composing another &lt;a href="https://docs.raku.org/language/objects#index-entry-role_declaration-role" rel="noopener noreferrer"&gt;role&lt;/a&gt; or &lt;a href="https://docs.raku.org/language/classtut#Class" rel="noopener noreferrer"&gt;class&lt;/a&gt; often refer to the &lt;a href="https://irclogs.raku.org/raku/gist.html?2019-12-09Z12:36,2019-12-19Z21:06,2022-08-12Z20:20,2025-05-24Z03:45-0002" rel="noopener noreferrer"&gt;lack of its existence&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The thing is that most of the functionality of the mythical &lt;code&gt;COMPOSE&lt;/code&gt; phaser is already available: any code that exists in the mainline of a &lt;code&gt;role&lt;/code&gt;, will be executed &lt;em&gt;every time&lt;/em&gt; the role is consumed by a &lt;code&gt;class&lt;/code&gt; at &lt;em&gt;compile time&lt;/em&gt;.  A small contrived example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;role&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;composing $?CLASS.^name()&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;B&lt;/span&gt; &lt;span class="nv"&gt;does&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;C&lt;/span&gt; &lt;span class="nv"&gt;does&lt;/span&gt; &lt;span class="nv"&gt;A&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;BEGIN&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composing B
composing C
begin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the &lt;a href="https://docs.raku.org/language/variables#index-entry-$%3FCLASS" rel="noopener noreferrer"&gt;&lt;code&gt;$?CLASS&lt;/code&gt;&lt;/a&gt; compile time variable contains the type object of the class being composed.  And in August 2020 it basically became clear that a &lt;a href="https://irclogs.raku.org/raku/2020-08-12.html#15:28" rel="noopener noreferrer"&gt;&lt;code&gt;COMPOSE&lt;/code&gt; phaser would not be needed&lt;/a&gt;.  Well, at least not until someone can show that a &lt;code&gt;COMPOSE&lt;/code&gt; phaser offers more functionality than the current way of executing the mainline of the &lt;code&gt;role&lt;/code&gt; is offering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;DOC&lt;/code&gt; set of phasers is activated with the &lt;code&gt;--doc&lt;/code&gt; command line argument: without that having been specified, all &lt;code&gt;DOC&lt;/code&gt; phasers are no-ops but need to be syntactically correct.  Their use appears to be limited.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;TEMP&lt;/code&gt; phaser was never implemented, but the &lt;code&gt;temp&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; prefix operators, as well as the &lt;code&gt;KEEP&lt;/code&gt; and &lt;code&gt;UNDO&lt;/code&gt; phasers, provide the functionality promised by &lt;code&gt;TEMP&lt;/code&gt; phaser.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;COMPOSE&lt;/code&gt; phaser was never implemented, because the mainline of a &lt;code&gt;role&lt;/code&gt; is executed when a &lt;code&gt;role&lt;/code&gt; is consumed in a class, effectively providing exactly the functionality promised by that phaser.  At least so far.&lt;/p&gt;

&lt;p&gt;This concludes the seventh episode of cases of UPPER language elements in the Raku Programming Language.  This also concludes all phasers in Raku.  Next up will describe the uppercase methods that you, as a user of the Raku Programming Language, can provide in your code to tweak behaviour.  Stay tuned!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Catch Control</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Tue, 03 Feb 2026 19:25:53 +0000</pubDate>
      <link>https://forem.com/lizmat/catch-control-i9o</link>
      <guid>https://forem.com/lizmat/catch-control-i9o</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part six in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the phasers that catch exceptions of various kinds.&lt;/p&gt;

&lt;h2&gt;
  
  
  CATCH
&lt;/h2&gt;

&lt;p&gt;Many programming languages have a &lt;code&gt;try&lt;/code&gt; / &lt;code&gt;catch&lt;/code&gt; mechanism.  Although it is true that the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt; &lt;em&gt;does&lt;/em&gt; have a &lt;a href="https://docs.raku.org/syntax/try%20%28statement%20prefix%29" rel="noopener noreferrer"&gt;&lt;code&gt;try&lt;/code&gt; statement prefix&lt;/a&gt;, and it &lt;em&gt;does&lt;/em&gt; have a &lt;a href="https://docs.raku.org/syntax/CATCH#Resuming_of_exceptions" rel="noopener noreferrer"&gt;&lt;code&gt;CATCH&lt;/code&gt; phaser&lt;/a&gt;, you should generally &lt;strong&gt;not&lt;/strong&gt; use both at the same time.&lt;/p&gt;

&lt;p&gt;In Raku &lt;strong&gt;any&lt;/strong&gt; scope can have a &lt;strong&gt;single&lt;/strong&gt; &lt;code&gt;CATCH&lt;/code&gt; block.  The code within it will be executed as soon as any runtime exception occurs in that scope, with the exception that was thrown topicalized in &lt;a href="https://docs.raku.org/syntax/%24_" rel="noopener noreferrer"&gt;&lt;code&gt;$_&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is the reason you cannot have a &lt;code&gt;CATCH&lt;/code&gt; thunk: it needs to have a scope to be able to set &lt;code&gt;$_&lt;/code&gt; in there, without affecting anything outside of that scope.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It does &lt;strong&gt;not&lt;/strong&gt; matter &lt;em&gt;where&lt;/em&gt; in a scope you put the &lt;code&gt;CATCH&lt;/code&gt; block.  But it is recommended for clarity's sake to put a &lt;code&gt;CATCH&lt;/code&gt; block as &lt;em&gt;early&lt;/em&gt; in the scope as possible (rather than "hiding" it somewhere near the end of a scope): when reading the code, you will almost immediately see that there is something special going on with regards to exceptions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Handling exceptions
&lt;/h3&gt;

&lt;p&gt;Let's start again with a contrived example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nv"&gt;CATCH&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;when&lt;/span&gt; &lt;span class="nn"&gt;X::&lt;/span&gt;&lt;span class="nv"&gt;AdHoc&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naughty: &lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;.message()&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nb"&gt;die&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;urgh&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;  &lt;span class="c1"&gt;# throws an X::AdHoc exception&lt;/span&gt;
    &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;after&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;alive still&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running the above code will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;naughty: urgh
alive still
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that having the exception in &lt;code&gt;$_&lt;/code&gt; smart-matching with &lt;a href="https://docs.raku.org/syntax/when" rel="noopener noreferrer"&gt;&lt;code&gt;when&lt;/code&gt;&lt;/a&gt; effectively disables the exception so it won't be re-thrown on scope exit.  Because of that, the &lt;code&gt;say "alive still"&lt;/code&gt; will be executed.  Any other type of error would &lt;strong&gt;not&lt;/strong&gt; be disabled, although you could if you wanted do that with a &lt;a href="https://docs.raku.org/syntax/default%20when" rel="noopener noreferrer"&gt;&lt;code&gt;default&lt;/code&gt;&lt;/a&gt; block.&lt;/p&gt;

&lt;p&gt;The careful reader will have noticed that the &lt;code&gt;say "after"&lt;/code&gt; was &lt;strong&gt;not&lt;/strong&gt; executed.  That's because the current scope was left as if a &lt;code&gt;return Nil&lt;/code&gt; was executed in the scope where the &lt;code&gt;CATCH&lt;/code&gt; block is located.&lt;/p&gt;

&lt;p&gt;If you feel like the exception in question is benign, you can make execution continue in the statement following the one that caused the exception.  You can do this by calling the &lt;a href="https://docs.raku.org/type/Exception#method_resume" rel="noopener noreferrer"&gt;&lt;code&gt;.resume&lt;/code&gt;&lt;/a&gt; method on the exception object.&lt;/p&gt;

&lt;p&gt;So let's assume all errors we get in that block are benign, and we want to just continue after each exception:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nv"&gt;CATCH&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;resume&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nb"&gt;die&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;urgh&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;after&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;alive still&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;after
alive still
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, not all exceptions are resumable!  So your program may stop nonetheless if the exception can not be actually resumed.  For instance, division by &lt;code&gt;0&lt;/code&gt; errors are not resumable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;CATCH&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;resume&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This exception is not resumable
  in block foo at bar line 42
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Trying code
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;try&lt;/code&gt; statements prefix (which either takes a thunk or a block) is actually a simplified case of a &lt;code&gt;CATCH&lt;/code&gt; handler that disarms all errors, sets &lt;a href="https://docs.raku.org/syntax/%24%21" rel="noopener noreferrer"&gt;&lt;code&gt;$!&lt;/code&gt;&lt;/a&gt; and returns &lt;a href="https://docs.raku.org/type/Nil" rel="noopener noreferrer"&gt;&lt;code&gt;Nil&lt;/code&gt;&lt;/a&gt;.  The code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="nv"&gt;try&lt;/span&gt; &lt;span class="nb"&gt;die&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;urgh&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;  &lt;span class="c1"&gt;# Nil&lt;/span&gt;
&lt;span class="nv"&gt;dd&lt;/span&gt; &lt;span class="vg"&gt;$!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;               &lt;span class="c1"&gt;# $! = X::AdHoc.new(payload =&amp;gt; "urgh")&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is actually pretty much short for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;CATCH&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nn"&gt;CALLERS::&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="vg"&gt;$!&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# set $! in right scope&lt;/span&gt;
        &lt;span class="nv"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;          &lt;span class="c1"&gt;# disarm exception&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nb"&gt;die&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;urgh&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}();&lt;/span&gt;    &lt;span class="c1"&gt;# Nil&lt;/span&gt;
&lt;span class="nv"&gt;dd&lt;/span&gt; &lt;span class="vg"&gt;$!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# $! = X::AdHoc.new(payload =&amp;gt; "urgh")&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that even though &lt;code&gt;die "urgh"&lt;/code&gt; is a thunk, the compiler turned this into its own scope internally to be able to handle the return from the thunk.&lt;/p&gt;

&lt;h2&gt;
  
  
  CONTROL
&lt;/h2&gt;

&lt;p&gt;Apart from runtime exceptions, many other types of exceptions are used in Raku.  They all consume the &lt;a href="https://docs.raku.org/type/X/Control" rel="noopener noreferrer"&gt;&lt;code&gt;X::Control&lt;/code&gt; role&lt;/a&gt; and are therefore referred to as &lt;a href="https://docs.raku.org/language/exceptions#Control_exceptions" rel="noopener noreferrer"&gt;"control exceptions"&lt;/a&gt;.  They are used for the following Raku features (in alphabetical order):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/routine/done" rel="noopener noreferrer"&gt;&lt;code&gt;done&lt;/code&gt;&lt;/a&gt; - call "done" callback on all taps&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/routine/emit" rel="noopener noreferrer"&gt;&lt;code&gt;emit&lt;/code&gt;&lt;/a&gt; - send item to all taps of supply&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/syntax/last" rel="noopener noreferrer"&gt;&lt;code&gt;last&lt;/code&gt;&lt;/a&gt; - exit the loop structure&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/syntax/next" rel="noopener noreferrer"&gt;&lt;code&gt;next&lt;/code&gt;&lt;/a&gt; - start next iteration in loop structure&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/language/control#proceed_and_succeed" rel="noopener noreferrer"&gt;&lt;code&gt;proceed&lt;/code&gt;&lt;/a&gt; - resume after &lt;code&gt;given&lt;/code&gt; block&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/syntax/redo" rel="noopener noreferrer"&gt;&lt;code&gt;redo&lt;/code&gt;&lt;/a&gt; - restart iteration in loop structure&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/routine/return" rel="noopener noreferrer"&gt;&lt;code&gt;return&lt;/code&gt;&lt;/a&gt; - return from sub / method&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/syntax/succeed" rel="noopener noreferrer"&gt;&lt;code&gt;succeed&lt;/code&gt;&lt;/a&gt; - exit &lt;code&gt;given&lt;/code&gt; block&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/routine/take" rel="noopener noreferrer"&gt;&lt;code&gt;take&lt;/code&gt;&lt;/a&gt; - pass item to &lt;code&gt;gather&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.raku.org/routine/warn" rel="noopener noreferrer"&gt;&lt;code&gt;warn&lt;/code&gt;&lt;/a&gt; - warn with given message&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just as runtime exceptions they all perform the work they are expected to do without needing any specific action from a user.  However, you can &lt;strong&gt;not&lt;/strong&gt; catch these exceptions with a &lt;code&gt;CATCH&lt;/code&gt; phaser, you need a &lt;a href="https://docs.raku.org/syntax/CONTROL" rel="noopener noreferrer"&gt;&lt;code&gt;CONTROL&lt;/code&gt; phaser&lt;/a&gt; for that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Handling control exceptions yourself
&lt;/h3&gt;

&lt;p&gt;Suppose you have a pesky warning that you want to get rid of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="vg"&gt;$_&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which would show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Use of uninitialized value element of type Any in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
  in block foo at bar line 42
foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since warnings are control exceptions, you can "catch" them in a &lt;code&gt;CONTROL&lt;/code&gt; phaser like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;CONTROL&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;when&lt;/span&gt; &lt;span class="nn"&gt;CX::&lt;/span&gt;&lt;span class="nv"&gt;Warn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;resume&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="vg"&gt;$_&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The class names for these control exceptions can be determined from &lt;a href="https://en.wikipedia.org/wiki/Title_case" rel="noopener noreferrer"&gt;title casing&lt;/a&gt; the name of the feature, and then prefixing with &lt;code&gt;CX::&lt;/code&gt;.  So "warn" throws an instance of the &lt;code&gt;CX::Warn&lt;/code&gt; class.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;which would just show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty simple, eh?   Well, by popular demand there is actually a shortcut for this case, called the &lt;a href="https://docs.raku.org/syntax/quietly%20%28statement%20prefix%29" rel="noopener noreferrer"&gt;&lt;code&gt;quietly&lt;/code&gt; statement prefix&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;quietly&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="vg"&gt;$_&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The standard way of handling warnings only produces the exact call-site where the warning occurred.  Which sometimes is just not enough to find the reason for the warning, because you would need a full stack trace for that.  Well, you can do that as well with a &lt;code&gt;CONTROL&lt;/code&gt; block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;CONTROL&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;when&lt;/span&gt; &lt;span class="nn"&gt;CX::&lt;/span&gt;&lt;span class="nv"&gt;Warn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;note&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;note&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;backtrace&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;join&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;resume&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="vg"&gt;$_&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Use of uninitialized value element of type Any in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
  in sub warn at SETTING::src/core.c/control.rakumod line 267
  in method Str at SETTING::src/core.c/Mu.rakumod line 817
  in method join at SETTING::src/core.c/List.rakumod line 1200
  in sub infix:&amp;lt;~&amp;gt; at SETTING::src/core.c/Str.rakumod line 3995
  in block foo at bar line 42
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you would like to turn any warning into a runtime exception:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;CONTROL&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;when&lt;/span&gt; &lt;span class="nn"&gt;CX::&lt;/span&gt;&lt;span class="nv"&gt;Warn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="vg"&gt;$_&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;would show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Use of uninitialized value $_ of type Any in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
  in block foo at bar line 42
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and &lt;strong&gt;not&lt;/strong&gt; show the "foo" because it would never get to that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Building your own control exceptions
&lt;/h3&gt;

&lt;p&gt;Can you build you own control exceptions?  Yes, you can.  Are they useful?  Probably not.  But just in case someone finds a way to make this useful, here's how you do it.  You start with a class that consumes the &lt;code&gt;X::Control&lt;/code&gt; role:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;class&lt;/span&gt; &lt;span class="nv"&gt;Frobnicate&lt;/span&gt; &lt;span class="nv"&gt;does&lt;/span&gt; &lt;span class="nn"&gt;X::&lt;/span&gt;&lt;span class="nv"&gt;Control&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you create a nice subroutine to make it easier to create an instance of that class, pass it any arguments and throw the instantiated control exception object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;frobnicate&lt;/span&gt;&lt;span class="p"&gt;($message) {&lt;/span&gt;
    &lt;span class="nv"&gt;Frobnicate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(:&lt;/span&gt;&lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in your code, make sure there is a &lt;code&gt;CONTROL&lt;/code&gt; phaser in the dynamic scope that handles the control exception:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;CONTROL&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;when&lt;/span&gt; &lt;span class="nv"&gt;Frobnicate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Caught a frobnication: &lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;.message()&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;resume&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then execute the nice subroutine at will:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;before&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="nv"&gt;frobnicate&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;after&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which would show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;before
Caught a frobnication: This
after
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final notes
&lt;/h2&gt;

&lt;p&gt;Even though the &lt;code&gt;CATCH&lt;/code&gt; and &lt;code&gt;CONTROL&lt;/code&gt; phasers are scope based, you can &lt;strong&gt;not&lt;/strong&gt; introspect a given &lt;code&gt;Block&lt;/code&gt; to see whether it has &lt;code&gt;CATCH&lt;/code&gt; or &lt;code&gt;CONTROL&lt;/code&gt; phasers.  This is because you can only have one of them in a scope, and handling exceptions in these phasers actually needs to be built into the bytecode generated for a block.  So from a runtime point of view, there was no need to put them as attributes into the &lt;code&gt;Block&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;Exception handling in Raku is built on &lt;a href="https://en.wikipedia.org/wiki/Delimited_continuation" rel="noopener noreferrer"&gt;delimited continuations&lt;/a&gt;.  If you really want to get into the nitty gritty of this feature, you might be interested in reading &lt;a href="https://github.com/Raku/nqp/blob/main/docs/continuations.pod#continuations-in-nqp" rel="noopener noreferrer"&gt;"Continuations in NQP"&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;CATCH&lt;/code&gt; phaser catches exceptions that are supposed to be fatal.  The &lt;code&gt;CONTROL&lt;/code&gt; phasers catches exceptions for all sorts of "normal" functionality, such as &lt;code&gt;next&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;warn&lt;/code&gt;, etc.&lt;/p&gt;

&lt;p&gt;You can build your own control exceptions, but the utility of these remains unclear as of yet.&lt;/p&gt;

&lt;p&gt;Exceptions are built on top of so-called "delimited continuations".&lt;/p&gt;

&lt;p&gt;This concludes the sixth episode of cases of UPPER language elements in the Raku Programming Language.  Stay tuned for more!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Last Close, and Quitting</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Wed, 28 Jan 2026 15:41:34 +0000</pubDate>
      <link>https://forem.com/lizmat/last-close-and-quitting-3d0a</link>
      <guid>https://forem.com/lizmat/last-close-and-quitting-3d0a</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part five in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the phasers related to concurrent and async structures, and will go into some of the mechanics behind the scenes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concurrency and Async
&lt;/h2&gt;

&lt;p&gt;If you're unaware of the concurrency and async features of the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt; (especially about what &lt;a href="https://docs.raku.org/language/control#supply/emit" rel="noopener noreferrer"&gt;&lt;code&gt;supply&lt;/code&gt; / &lt;code&gt;emit&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;react&lt;/code&gt; / &lt;code&gt;whenever&lt;/code&gt; do), it might be a good idea to read up on the &lt;a href="https://docs.raku.org/language/concurrency#Supplies" rel="noopener noreferrer"&gt;Supplies section&lt;/a&gt; of the Raku documentation on &lt;a href="https://docs.raku.org/language/concurrency" rel="noopener noreferrer"&gt;Concurrency&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  LAST, CLOSE, QUIT
&lt;/h2&gt;

&lt;p&gt;We have seen in the &lt;a href="https://dev.to/lizmat/first-next-then-last-25c5"&gt;previous episode&lt;/a&gt; that one can have a &lt;a href="https://docs.raku.org/language/phasers#LAST" rel="noopener noreferrer"&gt;&lt;code&gt;LAST&lt;/code&gt; phaser in loop structures&lt;/a&gt;.  But one can also have a &lt;a href="https://docs.raku.org/language/phasers#LAST_0" rel="noopener noreferrer"&gt;&lt;code&gt;LAST&lt;/code&gt; phaser in supplies&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In fact, there are &lt;a href="https://docs.raku.org/language/phasers#Asynchronous_phasers" rel="noopener noreferrer"&gt;three asynchronous phasers&lt;/a&gt;: &lt;a href="https://docs.raku.org/language/phasers#LAST_0" rel="noopener noreferrer"&gt;&lt;code&gt;LAST&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://docs.raku.org/language/phasers#CLOSE" rel="noopener noreferrer"&gt;&lt;code&gt;CLOSE&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://docs.raku.org/language/phasers#QUIT" rel="noopener noreferrer"&gt;&lt;code&gt;QUIT&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;LAST&lt;/code&gt; - as soon as a supply is done / &lt;code&gt;last&lt;/code&gt; is executed&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CLOSE&lt;/code&gt; - as soon as &lt;code&gt;supply&lt;/code&gt; / &lt;code&gt;react&lt;/code&gt; is done&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;QUIT&lt;/code&gt; - when an exception occurs in the supplier&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's start with an example with &lt;code&gt;LAST&lt;/code&gt; and &lt;code&gt;CLOSE&lt;/code&gt;.  We create a &lt;code&gt;supply&lt;/code&gt; that will produce 5 values, and a &lt;code&gt;react&lt;/code&gt; block with a single &lt;code&gt;whenever&lt;/code&gt; that will handle the values produced by the &lt;code&gt;supply&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This example is completely synchronous because the &lt;code&gt;supply&lt;/code&gt; keyword creates an "on-demand" supply, which isn't really "event" processing.  However, any other supply (e.g. a "live" supply created by the &lt;a href="https://docs.raku.org/type/Supply#sub_signal" rel="noopener noreferrer"&gt;&lt;code&gt;signal&lt;/code&gt;&lt;/a&gt; would be handled in the same way and that &lt;em&gt;would&lt;/em&gt; be event processing).&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$supply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;supply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;CLOSE&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Supply was closed.&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="nv"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;react&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;CLOSE&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shutting down react.&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="nv"&gt;whenever&lt;/span&gt; &lt;span class="nv"&gt;$supply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;say&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;LAST&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Supply is done.&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;React has been shut down&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
1
2
3
4
Supply is done.
Supply was closed.
Shutting down react.
React has been shut down.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the &lt;code&gt;LAST&lt;/code&gt; phaser inside the &lt;code&gt;whenever&lt;/code&gt; fires &lt;em&gt;before&lt;/em&gt; the &lt;code&gt;CLOSE&lt;/code&gt; phaser in the &lt;code&gt;supply&lt;/code&gt;.  That's because the &lt;code&gt;supply&lt;/code&gt; needs to inform each tap that it is done, before it can shutdown itself.&lt;/p&gt;

&lt;p&gt;Also note that when the last (in this case only) &lt;code&gt;whenever&lt;/code&gt; is done in a &lt;code&gt;react&lt;/code&gt; block, that the &lt;code&gt;react&lt;/code&gt; block will end and the code following it will be executed.&lt;/p&gt;

&lt;p&gt;But what now if an execution error happens in the &lt;code&gt;supply&lt;/code&gt; when it is producing values?  That's when the &lt;code&gt;QUIT&lt;/code&gt; phaser becomes handy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$supply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;supply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;CLOSE&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Supply was closed.&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;die&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Urgh&lt;/span&gt;&lt;span class="p"&gt;"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vg"&gt;$_&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;react&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;CLOSE&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shutting down react&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="nv"&gt;whenever&lt;/span&gt; &lt;span class="nv"&gt;$supply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;say&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;LAST&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Supply is done.&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
        &lt;span class="nv"&gt;QUIT&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;when&lt;/span&gt; &lt;span class="nn"&gt;X::&lt;/span&gt;&lt;span class="nv"&gt;AdHoc&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Supply Error: &lt;/span&gt;&lt;span class="si"&gt;$_&lt;/span&gt;&lt;span class="s2"&gt;.message()&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;React has been shut down&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
1
Supply was closed.
Supply Error: Urgh.
Shutting down react.
React has been shut down.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the &lt;code&gt;LAST&lt;/code&gt; phaser will &lt;strong&gt;not&lt;/strong&gt; fire when an execution error occurs in the &lt;code&gt;supply&lt;/code&gt;, only the &lt;code&gt;QUIT&lt;/code&gt; phaser will execute.  Also note that the &lt;code&gt;X::AdHoc&lt;/code&gt; execution error is what &lt;code&gt;die&lt;/code&gt; creates and throws, and that the &lt;code&gt;when&lt;/code&gt; will cause the execution error to be disarmed.  Any other execution error will be propagated.&lt;/p&gt;

&lt;p&gt;For instance, replacing the line &lt;code&gt;die "Urgh" if $_ == 2;&lt;/code&gt; by &lt;code&gt;42[1] if $_ == 2;&lt;/code&gt;, will cause this output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
1
Supply was closed.
Shutting down react.
A react block:
  in block &amp;lt;unit&amp;gt; at foo line 9

Died because of the exception:
    Index out of range. Is: 1, should be in 0..0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that in that case, execution will &lt;strong&gt;not&lt;/strong&gt; continue after the &lt;code&gt;react&lt;/code&gt; block because the execution error was not disarmed (because it was not an &lt;code&gt;X::AdHoc&lt;/code&gt;).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Yes, the use of &lt;code&gt;42[1]&lt;/code&gt; may be weird, but it is one of the quickest ways to create an execution error that is not an &lt;code&gt;X::AdHoc&lt;/code&gt;.  This is an error because any value in Raku can be considered a one-element list.  So &lt;code&gt;foo[0]&lt;/code&gt; will return &lt;code&gt;foo&lt;/code&gt;, but &lt;code&gt;foo[1]&lt;/code&gt; will cause an out-of-bounds error.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Under the hood
&lt;/h2&gt;

&lt;p&gt;All of the block related phasers that have been discussed so far are stored as additional information in the &lt;a href="https://docs.raku.org/type/Block" rel="noopener noreferrer"&gt;&lt;code&gt;Block&lt;/code&gt;&lt;/a&gt; object.  Basically when the Raku grammar is parsing your code and it sees something that looks like a phaser, it just adds that to the surrounding block (represented by a &lt;code&gt;Block&lt;/code&gt; object).  Then later, when the situation is right, the runtime inspects the &lt;code&gt;Block&lt;/code&gt; object for any phasers that are applicable in that situation by name.  And if found, executes them.&lt;/p&gt;

&lt;p&gt;This results in the (possibly unexpected) situation that you are allowed to specify a phaser that will never be fired in that context.  For instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;CLOSE&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;closed&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;inside block&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will just show &lt;code&gt;inside block&lt;/code&gt;, simply because the &lt;code&gt;CLOSE&lt;/code&gt; phaser only makes sense inside an concurrent / async structure such as a &lt;code&gt;supply&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;One could argue that the above example should be a compilation error, as the &lt;code&gt;CLOSE&lt;/code&gt; phaser will never be called.  However, it is pretty difficult to be 100% sure at compile time how a block will actually be used in the code, and what phasers could be called.  And from a performance point of view, checking for not-applicable phasers at runtime would incur a significant performance penalty.  So it was decided to not do that and consider this way of improperly using of phasers a case of DIHWIDT (aka Doctor, It Hurts When I Do This.  "so don't do that then").&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, it &lt;em&gt;is&lt;/em&gt; possible to introspect &lt;code&gt;Block&lt;/code&gt; objects in Raku, because everything in Raku is an object (or can be thought of as one).  Consider this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$block&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;CLOSE&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;closed&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;inside block&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;$block&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;                           &lt;span class="c1"&gt;# inside block&lt;/span&gt;
&lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;$block&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;phasers&lt;/span&gt;&lt;span class="p"&gt;("&lt;/span&gt;&lt;span class="s2"&gt;CLOSE&lt;/span&gt;&lt;span class="p"&gt;");&lt;/span&gt;  &lt;span class="c1"&gt;# closed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that by adding &lt;code&gt;()&lt;/code&gt; after the variable, you're telling Raku to &lt;em&gt;execute&lt;/em&gt; the contents of that variable without giving any arguments.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Block.phasers&lt;/code&gt; method takes the name of a block-oriented phaser and returns a &lt;code&gt;List&lt;/code&gt; of &lt;code&gt;Block&lt;/code&gt; objects representing each phaser seen by that name (usually one, but there can be more than one).&lt;/p&gt;

&lt;p&gt;Now, from a performance point of view it might not be a good idea to do a lookup in the &lt;code&gt;Block&lt;/code&gt; information for a phaser by a given name if there are no phasers associated with the block at all.  &lt;strong&gt;Each time&lt;/strong&gt; the block is executed.  Fortunately the &lt;code&gt;Block&lt;/code&gt; object also has a &lt;code&gt;has-phasers&lt;/code&gt; method that provides an efficient way to check that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$block&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;CLOSE&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;closed&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
    &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;inside block&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;$block&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;                              &lt;span class="c1"&gt;# inside block&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;$block&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;has&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;phasers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="vg"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;$block&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;phasers&lt;/span&gt;&lt;span class="p"&gt;("&lt;/span&gt;&lt;span class="s2"&gt;CLOSE&lt;/span&gt;&lt;span class="p"&gt;");&lt;/span&gt;  &lt;span class="c1"&gt;# closed&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These features allow developers to handle special features for blocks on top of what Raku already provides.&lt;/p&gt;

&lt;p&gt;Unfortunately there's no way (yet) to add arbitrarily named phasers in Raku code: this will probably require creating a &lt;a href="https://docs.raku.org/language/slangs" rel="noopener noreferrer"&gt;"slang"&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;LAST&lt;/code&gt;, &lt;code&gt;CLOSE&lt;/code&gt; and &lt;code&gt;QUIT&lt;/code&gt; phasers can be used in &lt;code&gt;supply&lt;/code&gt;, &lt;code&gt;react&lt;/code&gt; and &lt;code&gt;whenever&lt;/code&gt; blocks and will be called at the appropriate times.&lt;/p&gt;

&lt;p&gt;Under the hood block-oriented phasers are stored as additional information in the surrounding &lt;code&gt;Block&lt;/code&gt; object.  They can be introspected with the &lt;code&gt;has-phasers&lt;/code&gt; and &lt;code&gt;phasers&lt;/code&gt; methods.&lt;/p&gt;

&lt;p&gt;This concludes the fifth episode of cases of UPPER language elements in the Raku Programming Language.  Stay tuned for more!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>First Next, then Last</title>
      <dc:creator>Elizabeth Mattijsen</dc:creator>
      <pubDate>Mon, 26 Jan 2026 14:47:35 +0000</pubDate>
      <link>https://forem.com/lizmat/first-next-then-last-25c5</link>
      <guid>https://forem.com/lizmat/first-next-then-last-25c5</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part four in the &lt;a href="https://dev.to/lizmat/series/35190"&gt;"Cases of UPPER"&lt;/a&gt; series of blog posts, describing the Raku syntax elements that are completely in UPPERCASE.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This part will discuss the phasers related to loop structures (the code between curly braces that is being repeatedly called)&lt;/p&gt;

&lt;h2&gt;
  
  
  But first, a statement
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://dev.to/lizmat/init-to-an-end-30hc"&gt;second&lt;/a&gt; episode already saw the use of the &lt;a href="https://docs.raku.org/syntax/state" rel="noopener noreferrer"&gt;&lt;code&gt;state&lt;/code&gt;&lt;/a&gt; declarator in one of the examples, without going into it much.  Since &lt;code&gt;state&lt;/code&gt; is affecting some aspects handled in this blog post, it felt important to first circle back to it before going on.&lt;/p&gt;

&lt;p&gt;In short, a &lt;code&gt;state&lt;/code&gt; variable is a lexically scoped variable that will keep its value between invocations of the scope in which it is defined.  For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;frobnicate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;state&lt;/span&gt; &lt;span class="nv"&gt;$times&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# defined inside "frobnicate"&lt;/span&gt;
  &lt;span class="k"&gt;END&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Frobnicated &lt;/span&gt;&lt;span class="si"&gt;$times&lt;/span&gt;&lt;span class="s2"&gt; times.&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;frobnicate&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Frobnicated 5 times.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is really as if the variable &lt;code&gt;$times&lt;/code&gt; has been defined in the outer scope.  This gives the same result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$times&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# defined outside of "frobnicate"&lt;/span&gt;
&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;frobnicate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;$times&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;END&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Frobnicated &lt;/span&gt;&lt;span class="si"&gt;$times&lt;/span&gt;&lt;span class="s2"&gt; times.&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;frobnicate&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The difference being that the &lt;code&gt;my $times&lt;/code&gt; variable is visible to other pieces of the program, where as the &lt;code&gt;state $times&lt;/code&gt; variable is &lt;strong&gt;not&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A slightly adapted example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;frobnicate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;state&lt;/span&gt; &lt;span class="nv"&gt;$times&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# defined inside "for" loop&lt;/span&gt;
    &lt;span class="k"&gt;END&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Frobnicated &lt;/span&gt;&lt;span class="si"&gt;$times&lt;/span&gt;&lt;span class="s2"&gt; times.&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;frobnicate&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Frobnicated 3 times.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not 5.  Not 15.  But 3.  That's because the above code could also be written as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;frobnicate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$times&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$times&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# defined outside of "for" loop&lt;/span&gt;
    &lt;span class="k"&gt;END&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Frobnicated &lt;/span&gt;&lt;span class="si"&gt;$times&lt;/span&gt;&lt;span class="s2"&gt; times.&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;frobnicate&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in this case each invocation of "frobnicate" will get a fresh &lt;code&gt;my $times&lt;/code&gt;.  And since the &lt;code&gt;END&lt;/code&gt; phaser occurs only once in the code, it will only see the value of &lt;code&gt;$times&lt;/code&gt; from the last time that "frobnicate" had been called.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The way initialization of &lt;code&gt;state&lt;/code&gt; variables is organized is slightly more complex than described above.  In most cases the above explanation is correct, and when it is not you're probably getting into DIHWIDT (Doctor, It Hurts When I Do This: "so don't do that") territory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally it should be noted that &lt;code&gt;state&lt;/code&gt; variables, like any other non-&lt;a href="https://docs.raku.org/type/atomicint" rel="noopener noreferrer"&gt;atomic&lt;/a&gt; variables, are &lt;strong&gt;not&lt;/strong&gt; thread-safe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;sub &lt;/span&gt;&lt;span class="nf"&gt;frobnicate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;state&lt;/span&gt; &lt;span class="nv"&gt;$times&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;END&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Frobnicated &lt;/span&gt;&lt;span class="si"&gt;$times&lt;/span&gt;&lt;span class="s2"&gt; times&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;await&lt;/span&gt; &lt;span class="nv"&gt;start&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="c1"&gt;# wait for jobs to finish&lt;/span&gt;
  &lt;span class="nb"&gt;sleep&lt;/span&gt; &lt;span class="nb"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;# create some chaos&lt;/span&gt;
  &lt;span class="nv"&gt;frobnicate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nv"&gt;xx&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;# start 100 async jobs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show fewer than 100 frobnications.&lt;/p&gt;

&lt;p&gt;This is caused by multiple threads trying to update the &lt;code&gt;$times&lt;/code&gt; variable simultaneously.  This may miss updates, because &lt;code&gt;$times += 1&lt;/code&gt; is essentially &lt;code&gt;$times = $times + 1&lt;/code&gt;.  If two threads fetch the value of &lt;code&gt;$times&lt;/code&gt; simultaneously, then one of the threads will lose its update to &lt;code&gt;$times&lt;/code&gt; because it didn't "see" the update of the other thread before fetching it.&lt;/p&gt;

&lt;p&gt;It's important to recognize this behaviour of &lt;code&gt;state&lt;/code&gt; variables, before they are being used.  However, the system uses some state variables under the hood.  So your code may be affected by this behaviour without you as a develeoper realizing that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Loop-di-loop
&lt;/h2&gt;

&lt;p&gt;All loop structures in the &lt;a href="https://raku.org" rel="noopener noreferrer"&gt;Raku Programming Language&lt;/a&gt; (&lt;a href="https://docs.raku.org/syntax/for" rel="noopener noreferrer"&gt;&lt;code&gt;for&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://docs.raku.org/syntax/while%20until" rel="noopener noreferrer"&gt;&lt;code&gt;while&lt;/code&gt; / &lt;code&gt;until&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://docs.raku.org/syntax/loop" rel="noopener noreferrer"&gt;&lt;code&gt;loop&lt;/code&gt;&lt;/a&gt;) allow for the specification of an additional 3 types of phaser: &lt;a href="https://docs.raku.org/syntax/FIRST" rel="noopener noreferrer"&gt;&lt;code&gt;FIRST&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://docs.raku.org/syntax/NEXT" rel="noopener noreferrer"&gt;&lt;code&gt;NEXT&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://docs.raku.org/syntax/FIRST" rel="noopener noreferrer"&gt;&lt;code&gt;LAST&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The names of these phasers are pretty self-explanatory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FIRST - runs the first time a loop structure is entered&lt;/li&gt;
&lt;li&gt;NEXT - runs each time after an iteration is done&lt;/li&gt;
&lt;li&gt;LAST - runs after the last iteration is done&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$left&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$right&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;$left&lt;/span&gt;  &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;$right&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;FIRST&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ID | +2&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;===+===&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
  &lt;span class="nv"&gt;NEXT&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="si"&gt;$id&lt;/span&gt;&lt;span class="s2"&gt; |  { &lt;/span&gt;&lt;span class="si"&gt;$id&lt;/span&gt;&lt;span class="s2"&gt; + 2 }&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
  &lt;span class="nv"&gt;LAST&lt;/span&gt; &lt;span class="nv"&gt;say&lt;/span&gt; &lt;span class="p"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;===+=== +&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="si"&gt;$left&lt;/span&gt;&lt;span class="s2"&gt; | &lt;/span&gt;&lt;span class="si"&gt;$right&lt;/span&gt;&lt;span class="p"&gt;";&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ID | +2
===+===
 0 |  2
 1 |  3
 2 |  4
 3 |  5
 4 |  6
===+=== +
10 | 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the &lt;code&gt;FIRST&lt;/code&gt; and &lt;code&gt;LAST&lt;/code&gt; phaser allows one to easily add a header and a footer using variables that only exist inside the loop structure.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;NEXT&lt;/code&gt; phaser runs when an iteration is ended normally, or is started with a &lt;a href="https://docs.raku.org/syntax/next" rel="noopener noreferrer"&gt;&lt;code&gt;next&lt;/code&gt;&lt;/a&gt; command.  The &lt;code&gt;LAST&lt;/code&gt; phaser is run after the last iteration is done, or when leaving the scope is initiated with a &lt;a href="https://docs.raku.org/syntax/last" rel="noopener noreferrer"&gt;&lt;code&gt;last&lt;/code&gt;&lt;/a&gt; command.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;FIRST&lt;/code&gt; phaser uses an invisible &lt;code&gt;state&lt;/code&gt; variable under the hood, so depends on the peculiarities of its implementation.&lt;/p&gt;

&lt;p&gt;It is possible to use the other &lt;code&gt;Block&lt;/code&gt; oriented phasers in loop structures as well.  But generally only the &lt;code&gt;LEAVE&lt;/code&gt; phaser makes sense in that case: it effectively can be used if you want the same code to be executed in both the &lt;code&gt;NEXT&lt;/code&gt; and the &lt;code&gt;LAST&lt;/code&gt; case.&lt;/p&gt;

&lt;h2&gt;
  
  
  FIRST in the future
&lt;/h2&gt;

&lt;p&gt;In the next language level of Raku, the &lt;code&gt;FIRST&lt;/code&gt; phaser will become active for &lt;strong&gt;any&lt;/strong&gt; scope, not just inside of loop structures.  It will then also return the value produced by the &lt;code&gt;FIRST&lt;/code&gt; phaser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ RAKUDO_RAKUAST=1 raku -e '{ say now - FIRST now }'
0.000048209
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This functionality is similar to what is provided by &lt;a href="https://docs.raku.org/syntax/once" rel="noopener noreferrer"&gt;&lt;code&gt;once&lt;/code&gt;&lt;/a&gt;.  But that looks phaser-like?  Why isn't &lt;code&gt;once&lt;/code&gt; a phaser and thus in all uppercase?&lt;/p&gt;

&lt;p&gt;There have been a lot of discussions about that, but in the end it was decided that it is not a phaser because it runs in-line like other statement prefixes (&lt;a href="https://irclogs.raku.org/perl6/2013-05-30.html#04:04" rel="noopener noreferrer"&gt;decision from 2013&lt;/a&gt;).  So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ raku -e '{ say now - once now }'
-0.000055917
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will show a negative value because the &lt;code&gt;once now&lt;/code&gt; is executed &lt;strong&gt;after&lt;/strong&gt; the first &lt;code&gt;now&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;FIRST&lt;/code&gt; phaser however will run when the scope is entered, &lt;strong&gt;not&lt;/strong&gt; where the &lt;code&gt;FIRST&lt;/code&gt; phaser occurs in code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;FIRST&lt;/code&gt;, &lt;code&gt;NEXT&lt;/code&gt; and &lt;code&gt;LAST&lt;/code&gt; phasers apply to a scope that is being used in a loop structure.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;FIRST&lt;/code&gt; phaser depends on a &lt;code&gt;state&lt;/code&gt; variable under the hood.&lt;/p&gt;

&lt;p&gt;With the next language level, the &lt;code&gt;FIRST&lt;/code&gt; phaser will become active for &lt;strong&gt;any&lt;/strong&gt; scope and return the value it produced.  This is like &lt;code&gt;once&lt;/code&gt; but at entry of the scope (not in-line).&lt;/p&gt;

&lt;p&gt;This concludes the fourth episode of cases of UPPER language elements in the Raku Programming Language.  Stay tuned for more!&lt;/p&gt;

</description>
      <category>rakulang</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
