<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>CLEAR — Retrospective</title>
    <subtitle>Field notes from building a memory-safe language with LLMs.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://cuzzo.github.io/clear/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-05-17T00:00:00+00:00</updated>
    <id>https://cuzzo.github.io/clear/atom.xml</id>
    <entry xml:lang="en">
        <title>Can AI Un-Slop Itself?</title>
        <published>2026-05-16T00:00:00+00:00</published>
        <updated>2026-05-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/blog/can-ai-unslop-itself/"/>
        <id>https://cuzzo.github.io/clear/blog/can-ai-unslop-itself/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/blog/can-ai-unslop-itself/">&lt;p&gt;Everyone knows that LLMs can, at least, &lt;em&gt;sometimes&lt;&#x2F;em&gt; create slop.&lt;&#x2F;p&gt;
&lt;p&gt;The interesting question isn’t whether they can create slop.  It’s: can they un-slop themselves?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;problem&quot;&gt;Problem&lt;&#x2F;h2&gt;
&lt;p&gt;I dreamed of a programming language for 10 years. After Gemini 3.1-pro, I figured LLMs were good enough that I should at least finally see what this AI &quot;vibe-coding&quot; craze was all about.&lt;&#x2F;p&gt;
&lt;p&gt;I set on a 6-month journey to build a programming language.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Within 2-months, I had a custom runtime built in Zig &quot;competitive&quot; with Go &amp;amp; Tokio.&lt;&#x2F;li&gt;
&lt;li&gt;Within 3-months, I had an Affine Ownership-based &quot;memory safe&quot; language like Rust - but (in my opinion) much more intuitive.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The problem is: this only &lt;em&gt;barely&lt;&#x2F;em&gt; worked, and no one wants a &lt;em&gt;barely&lt;&#x2F;em&gt; working programming language!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-didn-t-work&quot;&gt;What didn’t work&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;wrt-the-language&quot;&gt;WRT the language:&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Architecturally, the LLMs built it without a MIR-pass.&lt;&#x2F;li&gt;
&lt;li&gt;Without boring you too much, it’s virtually impossible to guarantee affine ownership &#x2F; memory safety without a MIR-pass.&lt;&#x2F;li&gt;
&lt;li&gt;So I had a memory safe language that &lt;em&gt;WASN’T&lt;&#x2F;em&gt; memory safe...&lt;&#x2F;li&gt;
&lt;li&gt;Nobody wants a Rust that regularly leaks memory and still has UAF and double free bugs...&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;wrt-the-runtime&quot;&gt;WRT the runtime:&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;More of the same&lt;&#x2F;li&gt;
&lt;li&gt;There was no TSan testing in place&lt;&#x2F;li&gt;
&lt;li&gt;There was no memory ordering testing in place&lt;&#x2F;li&gt;
&lt;li&gt;The LLMs built a fiber runtime - complete with hammer tests... and never bothered to test if it’s actually thread safe...&lt;&#x2F;li&gt;
&lt;li&gt;Spoiler: it wasn&#x27;t!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;what-happened-next&quot;&gt;What happened next?&lt;&#x2F;h3&gt;
&lt;p&gt;I told the LLMs to fix their slop!&lt;&#x2F;p&gt;
&lt;p&gt;In about ~35 minutes, they screamed:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“Done, you have a complete MIR pass in place! Everything is memory safe.”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;They proceeded to feed me this same line of crap for ~1000 commits over 2 months, and me constantly asking:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“If the MIR pass is done, then how come X is still there and Y is still segfaulting?”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;LLMs:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“Oh, yes, there’s just that one small part left. Okay, now it’s done!”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;what-happened-next-1&quot;&gt;What happened next?&lt;&#x2F;h2&gt;
&lt;p&gt;The definition of insanity is trying the same thing and expecting different results!&lt;&#x2F;p&gt;
&lt;p&gt;I gave up on LLMs&#x27; ability to tell me the truth about the state of a non-trivial codebase.&lt;&#x2F;p&gt;
&lt;p&gt;I got a wild idea...&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;If I can’t trust LLMs...&lt;&#x2F;li&gt;
&lt;li&gt;Can I trust them to build me tools &amp;amp; systems to have more trust in them???&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I had LLMs build me a set of tools that don’t exist in Ruby (it&#x27;s turtles all the way down).&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;I built the compiler in Ruby, because, initially this started off as a project I was building by hand.&lt;&#x2F;li&gt;
&lt;li&gt;The initial scope was merely to play around with Syntax and see if I could develop something I liked.&lt;&#x2F;li&gt;
&lt;li&gt;Never did I ever dream that I would actually get something this far.&lt;&#x2F;li&gt;
&lt;li&gt;Everyone knows that a good compiler eventually self-hosts, and the goal was - like Crystal - my language would be quite close to Ruby (so LLMs should be able to migrate it easily).&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Anyway, Ruby has decent tooling around “code health” like SimpleCov &#x2F; Flay &#x2F; Flog &#x2F; Reek &#x2F; Debride, etc.&lt;&#x2F;p&gt;
&lt;p&gt;The problem is, if you’re building a compiler with LLMs these aren’t the core metrics you need.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;LLMs repeat themselves constantly... but then forget to do something the right way in one place... and then also don’t test it.&lt;&#x2F;li&gt;
&lt;li&gt;Especially in a dynamically-typed language, LLMs will randomly decide to use strings or symbols or nil to represent something, and then make thousands of defensive checks throughout your codebase... rather than fixing the problem at the source.&lt;&#x2F;li&gt;
&lt;li&gt;LLMs will regularly “refactor” your code and remove 99% of usage, but still leave 1% and then move on - leaving you with competing systems... and then later use the old one that doesn’t do everything you need, and get that usage back up to 10% (plus bugs).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The list goes on.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-did-they-build&quot;&gt;What did they build?&lt;&#x2F;h2&gt;
&lt;p&gt;I’m used to developing... like myself.  LLMs are different.  It’s sort of like pair-programming with a genius who is occasionally extremely dumb and sometimes downright adversarial.&lt;&#x2F;p&gt;
&lt;p&gt;How do you learn to work with this crazy partner?&lt;&#x2F;p&gt;
&lt;p&gt;I rarely need to think to implement code, and I type quite fast... So LLMs are not that much faster than me at implementation.  They are faster at design, but definitely not better.&lt;&#x2F;p&gt;
&lt;p&gt;Regardless, the enormous benefit they have is that they &lt;em&gt;scale&lt;&#x2F;em&gt;, whereas I do not.&lt;&#x2F;p&gt;
&lt;p&gt;If I have to review all of their code line-by-line, I’d rather just write it myself.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;I don&#x27;t have enough time to review the Rust code base line-by-line.&lt;&#x2F;li&gt;
&lt;li&gt;If I want a safer and more intuitive Rust, no one is going to build it for me.&lt;&#x2F;li&gt;
&lt;li&gt;I either get LLMs to do it, or it never gets done.  Period.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The goal wasn’t to try LLMs and find a reason not to use them... The goal was to find a way &lt;em&gt;TO&lt;&#x2F;em&gt; use them effectively.&lt;&#x2F;p&gt;
&lt;p&gt;If I have to review &lt;em&gt;EVERYTHING&lt;&#x2F;em&gt; LLMs write line-by-line, the bottle neck is me.  The entire goal of LLM development is to get the bottleneck NOT to be me - i.e. to scale.&lt;&#x2F;p&gt;
&lt;p&gt;You can’t scale yourself... but &lt;em&gt;maybe&lt;&#x2F;em&gt; you can scale with LLMs.&lt;&#x2F;p&gt;
&lt;p&gt;So, rather than say:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I’ll just insert myself as a bottleneck and review everything line-by-line with caution…&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I thought:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;What if I put a system in place that makes it very hard for them to poke holes in?&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;what-does-the-system-look-like&quot;&gt;What does the system look like?&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Save almost everything to docs&#x2F;agents (compressed)
&lt;ul&gt;
&lt;li&gt;This gives LLMs a review signal to see if what was implemented is 1) fully implemented, and 2) matches the agreement&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Competing sets of tests. An individual LLM that touches more than 1 set of tests when not &lt;em&gt;specifically&lt;&#x2F;em&gt; asked immediately warrants manual review.
&lt;ul&gt;
&lt;li&gt;At a minimum, I need to know that they didn’t put an exception in for their new feature to be allowed to leak memory or segfault… Because they regularly try to do that rather than write working code.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Mutation tests
&lt;ul&gt;
&lt;li&gt;This helps you find all of their do-nothing tests that are giving you an illusion of safety, rather than providing any real value&lt;&#x2F;li&gt;
&lt;li&gt;Typically, I trust myself to be able to write tests, so I don’t mutant test my own codebase.&lt;&#x2F;li&gt;
&lt;li&gt;Where I work - they don’t trust me. We have mutant testing. More than once, I’ve found more than once that I’ve written a do nothing test, so, hey, maybe we should all be mutant testing anyway!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Tooling &amp;amp; Reporting
&lt;ul&gt;
&lt;li&gt;I’ll cover this next&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Review
&lt;ul&gt;
&lt;li&gt;I’ve found the typical review process looks like:&lt;&#x2F;li&gt;
&lt;li&gt;LLM screams done&lt;&#x2F;li&gt;
&lt;li&gt;I ask a different LLM to check the spec and see if it’s done&lt;&#x2F;li&gt;
&lt;li&gt;The LLM points out 2-3 major things NOT implemented, 2-3 things extremely poorly implemented, and 10+ things that are almost certainly bugs&lt;&#x2F;li&gt;
&lt;li&gt;Feed that back to the implementation LLM&lt;&#x2F;li&gt;
&lt;li&gt;Repeat for 3-5 rounds&lt;&#x2F;li&gt;
&lt;li&gt;Only here do I look at anything they’ve done.&lt;&#x2F;li&gt;
&lt;li&gt;This is typically ~20k lines of code per week...&lt;&#x2F;li&gt;
&lt;li&gt;I can&#x27;t look it over with a jade-handled spyglass inquisitively.&lt;&#x2F;li&gt;
&lt;li&gt;I need to be able to pinpoint the things that &lt;em&gt;NEED&lt;&#x2F;em&gt; to be reviewed so I can review them.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;tooling-reporting&quot;&gt;Tooling &amp;amp; Reporting&lt;&#x2F;h2&gt;
&lt;p&gt;Tooling &amp;amp; Reporting in general is a sweet spot for LLMs.  They are very good at getting things &lt;em&gt;nearly&lt;&#x2F;em&gt; working.&lt;&#x2F;p&gt;
&lt;p&gt;The problem is: most things need to &lt;em&gt;actually&lt;&#x2F;em&gt; work.&lt;&#x2F;p&gt;
&lt;p&gt;In some cases, you are far better off with nothing than something that has very bad failure methods.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re using a report to give out a billion dollars, you probably want a report that &lt;em&gt;actually&lt;&#x2F;em&gt; works.&lt;&#x2F;p&gt;
&lt;p&gt;But if you want a report that just gives you a probability of how much AI slop there is in a commit, and how dangerous that AI slop might be... something is far better than nothing.&lt;&#x2F;p&gt;
&lt;p&gt;The buzz phrase going around is:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;LLMs increase implementation throughput far faster than they increase verification throughput.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;What does that mean?&lt;&#x2F;p&gt;
&lt;p&gt;Invest in verification throughput!&lt;&#x2F;p&gt;
&lt;p&gt;I will continue to invest in layers of defense to protect myself from their common pitfalls and accept that 1) almost no software is perfect, even compilers, and 2) the system I have in place with LLMs is doing at least 10x better than I could do on my own.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;&#x2F;h2&gt;
&lt;p&gt;Interestingly, I&#x27;m building a language that syntically makes the vast majority of bugs simply impossible to represent, and - when possible - the compiler autogenerates all the failure methods that might unfold, so you can see exactly where a bug &lt;em&gt;might&lt;&#x2F;em&gt; be.&lt;&#x2F;p&gt;
&lt;p&gt;I wanted to do this &lt;em&gt;before&lt;&#x2F;em&gt; working with LLMs.  Now I want it more than ever before!&lt;&#x2F;p&gt;
&lt;p&gt;The question is: can LLMs ever get this language to work?&lt;&#x2F;p&gt;
&lt;p&gt;Time will tell... but - what I can tell you is - there’s not a shot in hell I’d ever get this done myself.&lt;&#x2F;p&gt;
&lt;p&gt;It at least seems &lt;em&gt;possible&lt;&#x2F;em&gt; with LLMs.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How to Vibe Code something that *actually* works</title>
        <published>2026-05-15T00:00:00+00:00</published>
        <updated>2026-05-15T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/blog/how-to-vibe-code-something-that-actually-works/"/>
        <id>https://cuzzo.github.io/clear/blog/how-to-vibe-code-something-that-actually-works/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/blog/how-to-vibe-code-something-that-actually-works/">&lt;p&gt;LLMs are outstanding at writing code that &lt;em&gt;sort of&lt;&#x2F;em&gt; works, and finding &lt;em&gt;some&lt;&#x2F;em&gt; bugs.&lt;&#x2F;p&gt;
&lt;p&gt;The problem is: production systems need to &lt;strong&gt;actually&lt;&#x2F;strong&gt; work, and bugs need to be fixed &lt;strong&gt;correctly&lt;&#x2F;strong&gt;, otherwise it&#x27;s turtles-all-the-way-down with bugs.&lt;&#x2F;p&gt;
&lt;p&gt;If you rely on LLMs to blindly fix bugs in a system that is not &lt;em&gt;extremely&lt;&#x2F;em&gt; well tested, they’ll likely “fix” one bug, and silently introduce 3 others.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;some-things-you-can-count-on&quot;&gt;Some things you can count on:&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;If you ask an LLM to build you something non trivial, at best, it will be &lt;em&gt;sort of&lt;&#x2F;em&gt; architecturally correct.&lt;&#x2F;li&gt;
&lt;li&gt;Everything fails from here. It is very hard to arrive at something that &lt;em&gt;actually&lt;&#x2F;em&gt; works when you have the fundamentally wrong design.&lt;&#x2F;li&gt;
&lt;li&gt;LLMs simply do not have the contextual capability yet to analyze medium+ sized codebases and figure out:
&lt;ul&gt;
&lt;li&gt;Is this actually broken?&lt;&#x2F;li&gt;
&lt;li&gt;If so, how do I fix it?&lt;&#x2F;li&gt;
&lt;li&gt;And what is the realistic path to &lt;em&gt;actually&lt;&#x2F;em&gt; fixing it without just re-inventing another system with all of the same problems (or worse)!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;what-does-not-work&quot;&gt;What DOES NOT work:&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Test coverage&lt;&#x2F;strong&gt; alone is &lt;em&gt;almost&lt;&#x2F;em&gt; meaningless in a vibe code project.
&lt;ul&gt;
&lt;li&gt;LLMs regularly test that code successfully does not work:
&lt;ul&gt;
&lt;li&gt;This feature is intended not to work at this stage (even when you told them specifically TO fix it at that stage)&lt;&#x2F;li&gt;
&lt;li&gt;Testing obviously wrong behavior: &lt;code&gt;1 + 1 = 3&lt;&#x2F;code&gt; (successfully)&lt;&#x2F;li&gt;
&lt;li&gt;Tests that test &lt;em&gt;nothing&lt;&#x2F;em&gt; - these hit lines, but don’t actually test that anything works - LLMs are famous for this type of test when you blindly tell them to increase coverage&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Branch coverage&lt;&#x2F;strong&gt; alone fails for similar reasons.
&lt;ul&gt;
&lt;li&gt;A line covered means nothing, but critically a branch taken does not imply all possible paths to that branch were taken&lt;&#x2F;li&gt;
&lt;li&gt;All possible paths in a non-trivial program is typically an undecidable halting problem: it is essentially infinite
&lt;ul&gt;
&lt;li&gt;This is exactly why writing non-trivial &lt;em&gt;working&lt;&#x2F;em&gt; code is hard!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Cyclomatic complexity scores&lt;&#x2F;strong&gt;
&lt;ul&gt;
&lt;li&gt;Some functions are inherently complex.&lt;&#x2F;li&gt;
&lt;li&gt;Breaking them up for the sake of satisfying cyclomatic complexity often makes your code worse, not better.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;goodhart-s-law&quot;&gt;Goodhart&#x27;s Law:&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;&quot;When a measure becomes a target, it ceases to be a good measure.&quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;LLMs are &lt;em&gt;VERY&lt;&#x2F;em&gt; good at gaming metrics.&lt;&#x2F;li&gt;
&lt;li&gt;If you want code that actually works, you don’t arrive at it by gaming metrics.
&lt;ul&gt;
&lt;li&gt;You arrive at it by using your brain, something LLMs don’t have.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;LLMs are a tool that can &lt;em&gt;HELP&lt;&#x2F;em&gt; you make sound decisions, and can &lt;em&gt;sometimes&lt;&#x2F;em&gt; make sound decisions.&lt;&#x2F;li&gt;
&lt;li&gt;But just like you cannot trust yourself, you can also not trust LLMs.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;what-does-help&quot;&gt;What DOES help:&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;mutation-tests&quot;&gt;Mutation Tests&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;A good test is load bearing. When production code changes, it should break it.&lt;&#x2F;li&gt;
&lt;li&gt;LLMs write tests that test nothing.&lt;&#x2F;li&gt;
&lt;li&gt;Mutation tests help you find them and turn them into load bearing tests that actually have value.
&lt;ul&gt;
&lt;li&gt;LLMs can often fix this, and the diff should be small and easy to review.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;coupling-and-cohesion&quot;&gt;Coupling and Cohesion&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;This measures how many other classes&#x2F;modules rely on a piece of code (Afferent) and how many things that code relies on (Efferent).&lt;&#x2F;li&gt;
&lt;li&gt;LLMs default to writing spaghetti code. This &lt;em&gt;helps&lt;&#x2F;em&gt; you find it.
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fixing it correctly will require using your brain.&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;The diff will typically not be small, and require a lot of review - though you can use LLM convergence to help.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;code-duplication-dryness&quot;&gt;Code Duplication (DRYness)&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;You want your production code to be DRY, your test code to repeat itself.&lt;&#x2F;li&gt;
&lt;li&gt;LLMs are famous for repeating themselves incorrectly.
&lt;ul&gt;
&lt;li&gt;LLMs can often fix this.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Though telling them to do it blindly can cause bugs rather than reduce them.&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Use your brain!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The key is: these &lt;em&gt;help&lt;&#x2F;em&gt;. But they does not &lt;em&gt;guarantee&lt;&#x2F;em&gt; you’ll get working code, or even close.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;It helps you find the most common LLM problems.&lt;&#x2F;li&gt;
&lt;li&gt;It does not help fix them correctly, and relying on LLMs to figure out how to do that on their own is a fool&#x27;s errand.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;YOU&lt;&#x2F;strong&gt;, the human, are the &lt;strong&gt;driver&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;LLMs are the &lt;strong&gt;car&lt;&#x2F;strong&gt; helping you arrive where you want to go faster than you could without them.
&lt;ul&gt;
&lt;li&gt;If you ask the car to drive you somewhere, it might drive you off a cliff.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;the-key-to-success-signal-diversity&quot;&gt;The Key to Success - Signal Diversity&lt;&#x2F;h2&gt;
&lt;p&gt;LLMs are &lt;em&gt;sort of&lt;&#x2F;em&gt; good at everything.&lt;&#x2F;p&gt;
&lt;p&gt;You can make them far better if you build a self-correcting fortress to: 1) reject their failures, and 2) accept their wins.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;how-do-you-do-that&quot;&gt;How do you do that?&lt;&#x2F;h3&gt;
&lt;p&gt;A system that has worked for me seems related to how hedge funds like Bridgewater think about investments:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Ray Dalio advises that, rather than focusing on a specific number of individual stocks, true diversification requires 15 or more good, uncorrelated return streams to significantly lower risk.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;If you vibe code, and you want code that works, do it in a way that you have several streams &lt;strong&gt;independently&lt;&#x2F;strong&gt; verifying that your code is implemented correctly.&lt;&#x2F;p&gt;
&lt;p&gt;You do not need to solve the halting problem to vibe code with LLMs and get &lt;em&gt;reasonable&lt;&#x2F;em&gt; results. All you need is diversity:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Your design docs
&lt;ul&gt;
&lt;li&gt;Have LLMs spec out a design for you. Compress it to something actionable for them to look back on.&lt;&#x2F;li&gt;
&lt;li&gt;They can use this as a first layer of defense to check if what was done actually works.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Your actual code
&lt;ul&gt;
&lt;li&gt;LLMs are decent at finding some bugs.&lt;&#x2F;li&gt;
&lt;li&gt;They can look directly at code and get a signal if it actually works.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Your unit tests
&lt;ul&gt;
&lt;li&gt;Advise LLMs to independently write tests without looking at implementation, only function signatures and the compressed design doc.&lt;&#x2F;li&gt;
&lt;li&gt;They can look at the test code independent of the actual code to see if it’s a 1) test nothing test, 2) a test this successfully fails test, or 3) what you want - a test that actually tests it works correctly according to your spec &#x2F; design.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Your integration tests
&lt;ul&gt;
&lt;li&gt;Advise LLMs to independently write feature&#x2F;integration tests without looking at implementation, and to avoid unnecessary mocks at all costs.&lt;&#x2F;li&gt;
&lt;li&gt;LLMs can easily write do-nothing integration tests that mock literally everything and test nothing.&lt;&#x2F;li&gt;
&lt;li&gt;Just as with unit tests, this is yet another layer for them to independently look at as a signal for if the code is adequately tested&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Fuzz Tests
&lt;ul&gt;
&lt;li&gt;Integration tests mainly test happy paths.&lt;&#x2F;li&gt;
&lt;li&gt;Without fuzzing &#x2F; formal verification, it is difficult to explore all the necessary paths to ensure your code actually works.&lt;&#x2F;li&gt;
&lt;li&gt;Integration tests are a minimal first line of defense.&lt;&#x2F;li&gt;
&lt;li&gt;The reason fuzz testing is great to combine with integration testing, implemented separately - is diversity.&lt;&#x2F;li&gt;
&lt;li&gt;You will find several bugs here - often times the first bugs will be that the LLM wrote the fuzz testing incorrectly. But almost always they will find the gaps in your unit tests and integration tests.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Mutant Tests
&lt;ul&gt;
&lt;li&gt;Fuzz tests are valuable on their own, but mutant testing is how you know they are load bearing.&lt;&#x2F;li&gt;
&lt;li&gt;When combined with Fuzz testing, written independently, looking only at your docs, you are unlikely to arrive at a situation where 5 layers of code and testing &lt;strong&gt;all&lt;&#x2F;strong&gt; test that your code either 1) does nothing or 2) fails successfully.&lt;&#x2F;li&gt;
&lt;li&gt;Though LLMs can do it!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Tooling
&lt;ul&gt;
&lt;li&gt;You need reports that show all the common pitfalls LLMs have:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Code Duplication - especially PARTIAL:&lt;&#x2F;strong&gt; where they checked some invariant in slightly different ways - more times than not a bug when working with LLMs - have them review each case.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Branch coverage - especially DECISION based:&lt;&#x2F;strong&gt; where you have untested branches specifically on key decision points - the pillars of your system &#x2F; product.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Afferent and Efferent Reporting:&lt;&#x2F;strong&gt; to give you insights into where LLMs inevitably turned your code into spaghetti.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Review!!!&lt;&#x2F;strong&gt;
&lt;ul&gt;
&lt;li&gt;Even with 6 layers of protection and tooling &amp;amp; reporting on code health specifically for LLM pitfalls, you need to review their work after they’ve screamed done and written all the tests.&lt;&#x2F;li&gt;
&lt;li&gt;Have 2-3 LLMs review on 1) architecture, 2) bugs, 3) gaps, 4) tech debt. Have them converge on which of the feedbacks are actually worth doing, and which are hallucinations or moving in the wrong direction.
&lt;ul&gt;
&lt;li&gt;Save this plan to docs&#x2F;agents&#x2F;*.md design doc.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Have one LLM implement the plan until the 2-3 others converge on the plan being done correctly.&lt;&#x2F;li&gt;
&lt;li&gt;At a &lt;em&gt;BARE&lt;&#x2F;em&gt; minimum, get the LLMs to converge on how &lt;em&gt;YOU&lt;&#x2F;em&gt; can be convinced the code actually works. Check that it works! Even at this stage, you should not be surprised if it is completely broken…&lt;&#x2F;li&gt;
&lt;li&gt;At a &lt;em&gt;REASONABLE&lt;&#x2F;em&gt; minimum, review the final integration testing to make sure it’s not mocking everything important.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;what-is-convergence&quot;&gt;What is Convergence?&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;If one LLM tells you something, there&#x27;s some unknown probability that it&#x27;s wrong.&lt;&#x2F;li&gt;
&lt;li&gt;If 2-3 tell you the same thing, it certainly does not mean it&#x27;s right, but it does mean it&#x27;s more likely to be right.&lt;&#x2F;li&gt;
&lt;li&gt;If they all agree and something &lt;em&gt;and&lt;&#x2F;em&gt; it makes sense to you, that&#x27;s &lt;em&gt;probably&lt;&#x2F;em&gt; the best you&#x27;re going to do on your own.&lt;&#x2F;li&gt;
&lt;li&gt;Never take &lt;strong&gt;DESIGN&lt;&#x2F;strong&gt; from LLMs blindly - i.e. just one.
&lt;ul&gt;
&lt;li&gt;This is letting the car pick where to drive.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;If you personally don&#x27;t know where to go, have the LLMs first agree, and then &lt;strong&gt;use your brain&lt;&#x2F;strong&gt; to make sure it makes sense.&lt;&#x2F;li&gt;
&lt;li&gt;Then, and only then, should you proceed.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Here is my &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;blog&#x2F;what-i-learned-the-hard-way&#x2F;&quot;&gt;Review Process&lt;&#x2F;a&gt;, complete with the magic words I use at different stages of development that have led to far better outcomes.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>What I learned (the hard way) Building a Memory Safe Programming Language with LLMs over the last 6 months</title>
        <published>2026-05-11T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/blog/what-i-learned-the-hard-way/"/>
        <id>https://cuzzo.github.io/clear/blog/what-i-learned-the-hard-way/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/blog/what-i-learned-the-hard-way/">&lt;h2 id=&quot;background&quot;&gt;Background&lt;&#x2F;h2&gt;
&lt;p&gt;For years, I dreamed up a language like Rust, but substantially safer and more intuitive.&lt;&#x2F;p&gt;
&lt;p&gt;I thought outsourcing this to LLMs was reasonable. The goal was primarily to understand their capabilities and limitations. My initial expectations were low.&lt;&#x2F;p&gt;
&lt;p&gt;Verifying compiler correctness is notoriously difficult. While harder problems exist, compilers are challenging. Controlling the language limits the problem space, yet for the goals I had - the problem space would be inherently difficult to verify correctness. Even though LLMs are particularly weak here, they have completely blown away my expectations. I have been both humbled and endlessly frustrated by their powers and limitations.&lt;&#x2F;p&gt;
&lt;p&gt;The language is &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cuzzo&#x2F;clear&quot;&gt;CLEAR&lt;&#x2F;a&gt;, and these are my learnings from this six-month adventure.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;where-llms-excel&quot;&gt;Where LLMs excel&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Generating ideas and signals&lt;&#x2F;li&gt;
&lt;li&gt;Filtering and reducing noise&lt;&#x2F;li&gt;
&lt;li&gt;Identifying problems&lt;&#x2F;li&gt;
&lt;li&gt;Applying optimizations (with strict guardrails)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;where-llms-are-decent-but-not-as-good-as-i-expected&quot;&gt;Where LLMs are decent, but not as good as I expected&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Refactoring—especially re-architecting&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;where-llms-do-not-excel&quot;&gt;Where LLMs do not excel&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Getting things correct&lt;&#x2F;li&gt;
&lt;li&gt;Obeying design principles&lt;&#x2F;li&gt;
&lt;li&gt;Resolving merge conflicts&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Finding a hole in a ship is easier than building one that never leaks.&lt;&#x2F;p&gt;
&lt;p&gt;Extracting high value from LLMs requires strict discipline. They make it easy to cut corners, even unintentionally.&lt;&#x2F;p&gt;
&lt;p&gt;When you lack ideas, LLMs can flood you with them. Usually, you can weed out the bad ones.&lt;&#x2F;p&gt;
&lt;p&gt;When flooded with data, LLMs sort it reasonably well, though they will make mistakes.&lt;&#x2F;p&gt;
&lt;p&gt;You can solve many problems by having LLMs generate scripts to produce and sift through data.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;I’m planning to release a tool that allows LLMs to loop until they fully type a Ruby codebase.
&lt;ul&gt;
&lt;li&gt;They did this for a ~40k line transpiler in a day after tooling was built.&lt;&#x2F;li&gt;
&lt;li&gt;The tooling took another 1-2 days to develop.&lt;&#x2F;li&gt;
&lt;li&gt;You can see it in &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cuzzo&#x2F;clear&#x2F;blob&#x2F;master&#x2F;tools&#x2F;nil-kill&quot;&gt;nil-kill&lt;&#x2F;a&gt;; I’ll release this as a standalone Gem shortly.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;I could never find the signal in that data without spending significant time on tooling.
&lt;ul&gt;
&lt;li&gt;Without LLMs, I wouldn’t have spent the time to build that tooling by hand.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;LLMs will miss things, but they can find a shocking amount of signal in data that is easy to generate but impossible for me to derive value from manually.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;LLMs struggle when absolute correctness is required, as in language development. They are good at getting &lt;em&gt;close&lt;&#x2F;em&gt; quickly, but bad at being &lt;em&gt;actually&lt;&#x2F;em&gt; correct independently.&lt;&#x2F;p&gt;
&lt;p&gt;The goal of any tool is to maximize value without introducing negatives.&lt;&#x2F;p&gt;
&lt;p&gt;A hammer is great for hitting nails but terrible for knitting sweaters.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;where-to-use-llms-aggressively&quot;&gt;Where to use LLMs aggressively&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;strong&gt;LLMs can prototype things unbelievably fast.&lt;&#x2F;strong&gt; In many cases, a &quot;mostly correct&quot; prototype is valuable. However, think twice before prototyping even with an LLM:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;If speed AND correctness are required, there may be significant performance implications.&lt;&#x2F;li&gt;
&lt;li&gt;A prototype’s simplicity often comes from its incompleteness or incorrectness.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;Second opinions generally&lt;&#x2F;strong&gt;: Two heads are better than one. LLM commit reviews may be noisy, but the signal is often worth it.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Second opinions specifically for reasons to reject something&lt;&#x2F;strong&gt;: Signal on a critical bug is worth the noise. I have had success having LLMs hunt for bugs. If 1 in 10 is a signal, that’s a win; I’ve seen rates closer to 1 in 3. It’s easier for LLMs to find bugs in code than to write correct code initially.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Second opinions on design&lt;&#x2F;strong&gt;: Several designs I was excited about were shattered by an LLM pointing out a flaw I hadn’t considered. I’m not a language expert, and even after six months, I still feel like a novice. Experts might have better first attempts.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;where-to-use-llms-with-caution&quot;&gt;Where to use LLMs with caution&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;strong&gt;Starting points&lt;&#x2F;strong&gt;: An LLM-designed system is often mediocre.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Workaround:&lt;&#x2F;em&gt; Treat the LLM’s output as an initial idea. Feed it to other LLMs, noting that while you want to move in that direction, the specific design is flawed. This turns a weakness into a strength by using them as second opinions. Results improve if you start with a strong personal opinion and iterate between multiple models.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;Testing their own code&lt;&#x2F;strong&gt;: LLMs often verify that broken code &quot;works&quot; correctly. Even in reviews, they may miss bugs and praise flawed commits.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Workaround 1:&lt;&#x2F;em&gt; Don’t ask an LLM to test its own code. Instead, ask a different model for the ideal strategy to test &lt;em&gt;similar&lt;&#x2F;em&gt; code.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;Workaround 2:&lt;&#x2F;em&gt; Use multiple LLMs to review code, specifically asking them to find bugs or poor implementations. This iterative process often reveals hidden issues.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;where-to-use-llms-as-a-last-resort&quot;&gt;Where to use LLMs as a last resort&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;strong&gt;Following directions&lt;&#x2F;strong&gt;: LLMs won&#x27;t always run tests, even when instructed. If you need a task performed reliably, use tooling. Integrate CI&#x2F;CD (like GitHub Actions) immediately; LLMs can set this up quickly, but they cannot be trusted to run tests manually every time.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Verifying correctness&lt;&#x2F;strong&gt;: LLMs are disappointing here. They can generate complex SVGs but fail to count the &quot;r&#x27;s&quot; in &quot;strawberry.&quot;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Workaround 1:&lt;&#x2F;em&gt; Use LLMs for search. Ask for the best ways to verify correctness.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;Workaround 2:&lt;&#x2F;em&gt; Iterate between models to refine verification methods.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;Workaround 3:&lt;&#x2F;em&gt; Build tooling that provides a high signal-to-noise ratio regarding code quality. Code coverage is a start, but focus on building project-specific tooling for deeper insights.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;what-llms-i-use-and-how&quot;&gt;What LLMs I use and how&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Model&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Implementation&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Speed&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Design&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Review Signal&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Codex&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;B&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;C&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;D&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Claude Code&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;A-&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;D&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;B&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;B&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Gemini CLI&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;C&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;D&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;B&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;B+&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Gemini CLI is currently free and excellent as a second opinion. I haven’t tried Open Code or DeepSeek yet, but hear they excel at implementation over design.&lt;&#x2F;p&gt;
&lt;p&gt;For the cost-conscious:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Claude Code (Opus)&lt;&#x2F;strong&gt; for design ONLY.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Codex&lt;&#x2F;strong&gt; for implementation.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Gemini CLI&lt;&#x2F;strong&gt; for review and second opinions.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;DeepSeek&lt;&#x2F;strong&gt; as a budget-friendly third opinion.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;the-magic-words&quot;&gt;The Magic Words&lt;&#x2F;h2&gt;
&lt;p&gt;I’ve found that no amount of CLAUDE.md &#x2F; AGENTS.md &#x2F; skills beats manually prompting them at specific points.&lt;&#x2F;p&gt;
&lt;p&gt;You will obviously get better results the more attention you pay to what they&#x27;ve done, giving them more specific instruction. However, even broad ones like these can work wonders:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;For design and review:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&quot;I suspect this design is unsafe, unscalable, or won&#x27;t integrate well, but I can’t articulate why. Please find the holes in this design, especially where a better solution is obvious.&quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;&lt;strong&gt;For test reviews:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&quot;Carefully review these tests. Are they verifying that the code is CORRECT or just that it&#x27;s successfully broken? Are they testing robust invariants of the system, or just that THIS specific marginal case works?&quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;&lt;strong&gt;For implementation reviews:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&quot;Review this implementation for bugs. If you find one, add a test that proves it. Does this introduce redundant systems? Should it integrate with existing authorities? Look for tech debt and hacks. Determine if the test coverage is robust and sufficient.&quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;claude-md-agents-md&quot;&gt;CLAUDE.md &#x2F; AGENTS.md&lt;&#x2F;h2&gt;
&lt;p&gt;See my &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cuzzo&#x2F;clear&#x2F;blob&#x2F;master&#x2F;CLAUDE.md&quot;&gt;CLAUDE.md&lt;&#x2F;a&gt;. The sections below &quot;Output&quot; are safe to copy. The &quot;Contributing&quot; section should be tailored to your project.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;&#x2F;h2&gt;
&lt;p&gt;LLMs can suggest a 100x velocity increase, but the reality is closer to 10x. Parallelizing work streams (compiler, runtime, VM) can multiply this, potentially reaching 40x.&lt;&#x2F;p&gt;
&lt;p&gt;However, LLMs struggle with merge conflicts and may ignore test failures. They also tend to change unrelated code, like comments.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Workaround 1:&lt;&#x2F;em&gt; Instruct them to remove non-essential comment changes or irrelevant edits before committing.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;Workaround 2:&lt;&#x2F;em&gt; Make sure you have CI setup so that they can&#x27;t pretend the system already didn&#x27;t work and that they didn&#x27;t break it (they will).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;biggest-mistakes&quot;&gt;Biggest Mistakes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;1-assuming-llms-could-re-architect&quot;&gt;1. Assuming LLMs could re-architect&lt;&#x2F;h3&gt;
&lt;p&gt;I initially allowed LLMs to build a &quot;pile of crap,&quot; assuming they could fix it later. They are great at building such piles but struggle to refine them into a functioning language. I could have saved 66% of my headaches by enforcing design guardrails early.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;2-moving-too-fast&quot;&gt;2. Moving too fast&lt;&#x2F;h3&gt;
&lt;p&gt;Blitzing through features usually resulted in more work and headaches. Even with LLMs, rushing is costly. Delivering at 100x is tempting, but the &quot;headache factor&quot; of LLM mistakes is significant.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;I had great success when I followed my learnings closely for this &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cuzzo&#x2F;clear&#x2F;pull&#x2F;3&quot;&gt;FSM &#x2F; Thunks &#x2F; Streams PR&lt;&#x2F;a&gt;.
&lt;ul&gt;
&lt;li&gt;The FSM implementation went especially well, which is where I slowed down the most.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;I had much pain and suffering when I ignored my learnings, and prematurely merged in a &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cuzzo&#x2F;clear&#x2F;pull&#x2F;31&quot;&gt;&quot;hotfix&quot;&lt;&#x2F;a&gt;.
&lt;ul&gt;
&lt;li&gt;It ended up being a &quot;Hot Bug Party&quot; instead.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;3-not-understanding-llm-limitations-early&quot;&gt;3. Not understanding LLM limitations early&lt;&#x2F;h3&gt;
&lt;p&gt;I should have generated a robust test suite from the start. LLMs break architectural invariants easily. They can generate testing frameworks quickly; use them to create &quot;fortress files&quot; that protect your design goals.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-software-jobs-aren-t-imminent-targets&quot;&gt;Why Software Jobs Aren&#x27;t Imminent Targets&lt;&#x2F;h2&gt;
&lt;p&gt;Engineering was never about typing speed. It’s about ensuring code works as intended. While LLMs could generate my project in days - it wouldn&#x27;t &lt;em&gt;actually&lt;&#x2F;em&gt; work, and the bottleneck is review, ensuring it&#x27;s implemented correctly and architecturally soundly, that it&#x27;s sufficiently tested to have any guarantees it &lt;em&gt;actually&lt;&#x2F;em&gt; works, rather than it just happens to pass a slim set of tests, which may in fact be testing nothing.&lt;&#x2F;p&gt;
&lt;p&gt;Most engineers spend only a third of their time writing code or less. Even if LLMs automate that, cheaper code will likely increase demand for engineering. The market will lag technological possibility by 5–10 years.&lt;&#x2F;p&gt;
&lt;p&gt;Disruption will be asymmetric. Startups, new grads, and managers may see more impact than the general engineering population (or vice versa).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;&#x2F;h2&gt;
&lt;p&gt;In six months of part-time tinkering, I’ve built a competitive runtime and language. This would have been impossible without LLMs acting as a 50x force multiplier.&lt;&#x2F;p&gt;
&lt;p&gt;I can &quot;code&quot; while walking the dog, at the gym, during lunch, instead of doom scrolling before bed, etc.&lt;&#x2F;p&gt;
&lt;p&gt;While LLMs can be frustratingly inconsistent, they are the most amazing tools I’ve used. I’ve never been more excited about the future of engineering.&lt;&#x2F;p&gt;
&lt;p&gt;You can see my full &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;blog&#x2F;how-to-vibe-code-something-that-actually-works&#x2F;&quot;&gt;Development Process&lt;&#x2F;a&gt; for how I built a complex language that competes with Rust and Go on concurrent performance and &lt;em&gt;nearly&lt;&#x2F;em&gt; works.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>pprof integration</title>
        <published>2026-05-08T00:00:00+00:00</published>
        <updated>2026-05-08T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/pprof/"/>
        <id>https://cuzzo.github.io/clear/docs/pprof/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/pprof/">&lt;p&gt;&lt;code&gt;clear profile&lt;&#x2F;code&gt; emits its runtime profile data in pprof&#x27;s gzipped
protobuf format alongside the existing text dumps, so you can use
the standard &lt;code&gt;pprof&lt;&#x2F;code&gt; tool for flamegraphs, call graphs, and source
views.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;install&quot;&gt;Install&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Tool&lt;&#x2F;th&gt;&lt;th&gt;When you need it&lt;&#x2F;th&gt;&lt;th&gt;Install&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;pprof&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Always (the viewer)&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;go install github.com&#x2F;google&#x2F;pprof@latest&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;perf_to_profile&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;If you want CPU flamegraphs from &lt;code&gt;perf.data&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;go install github.com&#x2F;google&#x2F;perf_data_converter&#x2F;src&#x2F;cmd&#x2F;perf_to_profile@latest&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;graphviz&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;If you use &lt;code&gt;pprof -svg&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;pprof -dot&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;apt install graphviz&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;brew install graphviz&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;The web UI (&lt;code&gt;pprof -http=:8080&lt;&#x2F;code&gt;) and &lt;code&gt;pprof -top&lt;&#x2F;code&gt; text view do not
need graphviz.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;use&quot;&gt;Use&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; profile foo.cht
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# -&amp;gt; writes foo.profile&#x2F;heap.pb.gz, lock.pb.gz, mvcc.pb.gz
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;#    (and cpu.pb.gz if perf_to_profile is on PATH)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;pprof -http&lt;&#x2F;span&gt;&lt;span&gt;=:8080 .&#x2F;foo foo.profile&#x2F;heap.pb.gz
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;pprof -top -alloc_space&lt;&#x2F;span&gt;&lt;span&gt;  foo.profile&#x2F;heap.pb.gz
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;pprof -top -inuse_space&lt;&#x2F;span&gt;&lt;span&gt;  foo.profile&#x2F;heap.pb.gz
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;pprof -top -delay&lt;&#x2F;span&gt;&lt;span&gt;        foo.profile&#x2F;lock.pb.gz
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;pprof -base&lt;&#x2F;span&gt;&lt;span&gt; before&#x2F;heap.pb.gz after&#x2F;heap.pb.gz   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# regression diff
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;what-s-in-each-file&quot;&gt;What&#x27;s in each file&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;heap-pb-gz&quot;&gt;&lt;code&gt;heap.pb.gz&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Sample columns: &lt;code&gt;alloc_objects&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;alloc_space&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;inuse_objects&lt;&#x2F;code&gt; &#x2F;
&lt;code&gt;inuse_space&lt;&#x2F;code&gt;. Each call site is one sample with its hex address as
a label (&lt;code&gt;pprof -tags heap.pb.gz&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;h3 id=&quot;lock-pb-gz&quot;&gt;&lt;code&gt;lock.pb.gz&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Sample columns: &lt;code&gt;contentions&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;delay&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;hold&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;acquisitions&lt;&#x2F;code&gt;.
Read+write contention sums into &lt;code&gt;contentions&lt;&#x2F;code&gt;; &lt;code&gt;delay&lt;&#x2F;code&gt; is the total
wait (read+write); &lt;code&gt;hold&lt;&#x2F;code&gt; is total exclusive hold time.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;mvcc-pb-gz&quot;&gt;&lt;code&gt;mvcc.pb.gz&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Sample columns: &lt;code&gt;reads&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;commits&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;retries&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;cow_bytes&lt;&#x2F;code&gt;.
&lt;code&gt;cow_bytes = struct_size * (commits + retries)&lt;&#x2F;code&gt; — the byte volume
moved by copy-on-write commits, the most direct cost signal for
&lt;code&gt;@shared:versioned&lt;&#x2F;code&gt; cells.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;channels-pb-gz&quot;&gt;&lt;code&gt;channels.pb.gz&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Sample columns: &lt;code&gt;pushes&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;pops&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;push_blocked&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;pop_blocked&lt;&#x2F;code&gt; &#x2F;
&lt;code&gt;max_depth&lt;&#x2F;code&gt;. One sample per registered channel; the synthetic
function name is &lt;code&gt;channel#&amp;lt;id&amp;gt;&lt;&#x2F;code&gt; and the channel&#x27;s capacity travels
as a label (&lt;code&gt;pprof -tags channels.pb.gz&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;h3 id=&quot;cpu-pb-gz&quot;&gt;&lt;code&gt;cpu.pb.gz&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Standard CPU profile from &lt;code&gt;perf.data&lt;&#x2F;code&gt;, converted by
&lt;code&gt;perf_to_profile&lt;&#x2F;code&gt;. Sample columns are whatever Go&#x27;s pprof shows
(&lt;code&gt;samples&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;cpu&lt;&#x2F;code&gt; ns).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;clear-source-mapping&quot;&gt;CLEAR source mapping&lt;&#x2F;h2&gt;
&lt;p&gt;The transpiler emits &lt;code&gt;&#x2F;&#x2F; CLR:N&lt;&#x2F;code&gt; markers in &lt;code&gt;transpiled.zig&lt;&#x2F;code&gt;. Our
converter walks those back to the user&#x27;s &lt;code&gt;.cht&lt;&#x2F;code&gt; line and stamps it
onto each pprof Location, so &lt;code&gt;pprof -list &amp;lt;fn&amp;gt;&lt;&#x2F;code&gt; shows CLEAR source
lines (not Zig).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;sampling&quot;&gt;Sampling&lt;&#x2F;h2&gt;
&lt;p&gt;Stack traces for &lt;strong&gt;alloc-profile&lt;&#x2F;strong&gt; are captured on every alloc by
default. For workloads where the per-alloc unwind cost matters,
&lt;code&gt;--sample=N&lt;&#x2F;code&gt; records every Nth event and scales the captured values
by N so doctor &#x2F; pprof see estimated totals:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; profile foo.cht&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --sample&lt;&#x2F;span&gt;&lt;span&gt;=100
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Header records the chosen &lt;code&gt;sample_n&lt;&#x2F;code&gt; so consumers can rescale or
flag the approximation.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;stack-traces-for-lock-and-mvcc-profiles&quot;&gt;Stack traces for lock and mvcc profiles&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;--sync-callstacks&lt;&#x2F;code&gt; (off by default) turns on per-record stack
capture in lock-profile and mvcc-profile, so pprof&#x27;s tree&#x2F;flame
views and per-caller attribution work for these profiles too:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; profile foo.cht&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --sync-callstacks            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# auto-bumps --sample to 100
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; profile foo.cht&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --sync-callstacks --sample&lt;&#x2F;span&gt;&lt;span&gt;=1  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# full capture, full cost
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Off by default because the FP walk costs ~100-500ns per record.
Uncontended mutex acquire is ~10-20ns and MVCC commit fast paths
are ~20-50ns, so the trace can dominate the operation it&#x27;s measuring.
When the flag is set without an explicit &lt;code&gt;--sample&lt;&#x2F;code&gt;, we auto-default
to &lt;code&gt;--sample=100&lt;&#x2F;code&gt; to keep the cost manageable.&lt;&#x2F;p&gt;
&lt;p&gt;With &lt;code&gt;--sync-callstacks&lt;&#x2F;code&gt; on, each (lock, caller-trace) pair becomes
its own row in lock-profile, and same for (cell, caller-trace) in
mvcc-profile. Doctor aggregates rows back to one-per-lock for its
existing diagnoses; pprof tree views show the per-caller breakdown.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;doctor-flags-built-on-this-data&quot;&gt;Doctor flags built on this data&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;clear doctor&lt;&#x2F;code&gt; consumes the same profile dirs and grew three new
flags that draw on the multi-frame trace data:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; doctor foo.profile&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --cumulative           &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# rank functions by cum bytes
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; doctor foo.profile&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --focus&lt;&#x2F;span&gt;&lt;span&gt;=intToString    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# filter to traces that touch this function
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; doctor foo.profile&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --ignore&lt;&#x2F;span&gt;&lt;span&gt;=intToString   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# drop traces that touch this function
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; doctor foo.profile&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --peek&lt;&#x2F;span&gt;&lt;span&gt;=processRequest  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# callers + callees of one function
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; doctor foo.profile&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --by&lt;&#x2F;span&gt;&lt;span&gt;=allocs            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# sort heap by allocation count, not bytes
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; doctor foo.profile&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --by&lt;&#x2F;span&gt;&lt;span&gt;=inuse_bytes       &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# sort by allocs - frees (live bytes)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;clear&lt;&#x2F;span&gt;&lt;span&gt; doctor old.profile&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --diff&lt;&#x2F;span&gt;&lt;span&gt; new.profile&#x2F;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# perf-regression diff between two runs
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;--cumulative&lt;&#x2F;code&gt; aggregates bytes&#x2F;allocs across every frame in each
trace, so a function high in the call stack accrues its callees&#x27;
costs. &lt;code&gt;--focus=REGEX&lt;&#x2F;code&gt; keeps only sites whose trace touches a function
matching the pattern. &lt;code&gt;--diff&lt;&#x2F;code&gt; reports per-function deltas in
allocation, lock contention, and MVCC retries, with directional arrows
and &quot;newly contended&quot; &#x2F; &quot;retries eliminated&quot; annotations.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;notes&quot;&gt;Notes&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;We do not emit a Mapping message for the binary, so &lt;code&gt;pprof&lt;&#x2F;code&gt; prints
&quot;Main binary filename not available&quot; and skips its own symbolization.
Function names still appear because we resolve via &lt;code&gt;addr2line&lt;&#x2F;code&gt; at
conversion time.&lt;&#x2F;li&gt;
&lt;li&gt;alloc-profile captures stacks unconditionally (multi-frame v2,
comma-separated leaf-first in &lt;code&gt;alloc.txt&lt;&#x2F;code&gt;).&lt;&#x2F;li&gt;
&lt;li&gt;lock-profile (v3) and mvcc-profile (v2) capture stacks only when
&lt;code&gt;--sync-callstacks&lt;&#x2F;code&gt; is on. The 12th column of &lt;code&gt;locks.txt&lt;&#x2F;code&gt; and the
8th column of &lt;code&gt;mvcc.txt&lt;&#x2F;code&gt; carry &lt;code&gt;-&lt;&#x2F;code&gt; (off) or comma-separated leaf-
first addrs (on). Tab-separated to allow commas in the trace field.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>STRICT EXTREME: The Path to High-Integrity CLEAR (@strict:extreme)</title>
        <published>2026-05-01T00:00:00+00:00</published>
        <updated>2026-05-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/strict-extreme/"/>
        <id>https://cuzzo.github.io/clear/docs/strict-extreme/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/strict-extreme/">&lt;div class=&quot;gh-alert gh-alert-note&quot;&gt;
&lt;p class=&quot;gh-alert-title&quot;&gt;&lt;svg class=&quot;gh-alert-icon&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z&quot;&#x2F;&gt;&lt;&#x2F;svg&gt; Note&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;STRICT&lt;&#x2F;code&gt; and &lt;code&gt;STRICT EXTREME&lt;&#x2F;code&gt; mode are not yet available. &lt;code&gt;DEFAULT&lt;&#x2F;code&gt; mode is the focus for the v0.1 release.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;&#x2F;h2&gt;
&lt;p&gt;The &quot;CLEAR Story&quot; is a transition from &lt;strong&gt;Productivity&lt;&#x2F;strong&gt; (Ruby-like ease) to &lt;strong&gt;Performance&lt;&#x2F;strong&gt; (C-like speed) to &lt;strong&gt;Integrity&lt;&#x2F;strong&gt; (Ada&#x2F;SPARK-level safety). While standard CLEAR provides memory and concurrency safety, &lt;strong&gt;STRICT EXTREME&lt;&#x2F;strong&gt; is a compilation mode designed for mission-critical systems (HFT, Aerospace, Medical) where runtime failures (Panics) are unacceptable.&lt;&#x2F;p&gt;
&lt;p&gt;Unlike other high-integrity languages, CLEAR does not require a different syntax for this level of safety. Instead, it uses &lt;strong&gt;Progressive Formal Verification&lt;&#x2F;strong&gt; to prove properties about the code that the &lt;code&gt;Annotator&lt;&#x2F;code&gt; and &lt;code&gt;OwnershipGraph&lt;&#x2F;code&gt; are already tracking silently.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-integrity-spectrum&quot;&gt;The Integrity Spectrum&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Mode&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Safety Guarantee&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Developer Experience&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Standard&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Memory &amp;amp; Concurrency Safety&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&quot;It just works&quot; (Ruby-like)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;STRICT&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Performance &amp;amp; Effect Safety&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;No hidden HEAP&#x2F;BLOCKING&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;STRICT EXTREME&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Liveness &amp;amp; Panic Safety&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Formally Proven (Ada-like)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;core-pillars-of-strict-extreme&quot;&gt;Core Pillars of STRICT EXTREME&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;1-the-no-panic-guarantee-formal-proof&quot;&gt;1. The &quot;No-Panic&quot; Guarantee (Formal Proof)&lt;&#x2F;h3&gt;
&lt;p&gt;In standard mode, CLEAR prevents memory corruption but may &lt;code&gt;!!&lt;&#x2F;code&gt; (Panic) on an out-of-bounds index or an integer overflow. In &lt;strong&gt;STRICT EXTREME&lt;&#x2F;strong&gt;, the compiler uses a SMT solver (like Z3) to prove that &lt;strong&gt;no runtime panic is possible&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Constraint Propagation&lt;&#x2F;strong&gt;: The compiler tracks value ranges. If it cannot prove &lt;code&gt;idx &amp;lt; list.length()&lt;&#x2F;code&gt;, it rejects the build.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Proof Assistance&lt;&#x2F;strong&gt;: The &lt;code&gt;clear fix&lt;&#x2F;code&gt; tool suggests &lt;code&gt;@pre&lt;&#x2F;code&gt; (pre-conditions) or &lt;code&gt;@post&lt;&#x2F;code&gt; (post-conditions) to satisfy the prover.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;2-guaranteed-bounded-execution-stack-time&quot;&gt;2. Guaranteed Bounded Execution (Stack &amp;amp; Time)&lt;&#x2F;h3&gt;
&lt;p&gt;Ada-level safety requires knowing that a program will not run out of memory or hang.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Stack Depth Proof&lt;&#x2F;strong&gt;: The compiler walks the call graph and proves the maximum possible stack usage. Recursive functions without a proven base case are rejected.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;TIGHT Loop Validation&lt;&#x2F;strong&gt;: Loops must be proven to terminate. &quot;Infinite&quot; loops are only allowed in dedicated &quot;Supervisor&quot; fibers.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;3-total-effect-isolation&quot;&gt;3. Total Effect Isolation&lt;&#x2F;h3&gt;
&lt;p&gt;While &lt;code&gt;STRICT&lt;&#x2F;code&gt; mode requires annotations for HEAP and BLOCKING, &lt;strong&gt;STRICT EXTREME&lt;&#x2F;strong&gt; requires a &lt;strong&gt;Total Effect Signature&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Deterministic Paths&lt;&#x2F;strong&gt;: Functions can be marked &lt;code&gt;@pure&lt;&#x2F;code&gt; (no side effects) or &lt;code&gt;@deterministic&lt;&#x2F;code&gt; (identical inputs always yield identical timing&#x2F;output).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Alloc-Free Zones&lt;&#x2F;strong&gt;: Proves that a &quot;Hot Path&quot; performs zero allocations (not even arena allocations) to guarantee zero jitter.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;4-liveness-deadlock-immunity&quot;&gt;4. Liveness &amp;amp; Deadlock Immunity&lt;&#x2F;h3&gt;
&lt;p&gt;Leveraging the &lt;code&gt;OwnershipGraph&lt;&#x2F;code&gt;, the compiler proves that no circular dependency of &lt;code&gt;@locked&lt;&#x2F;code&gt; or &lt;code&gt;@shared&lt;&#x2F;code&gt; objects exists.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lock-Ordering&lt;&#x2F;strong&gt;: The compiler enforces a global &quot;Acquisition Hierarchy.&quot; If you try to acquire &lt;code&gt;Lock B&lt;&#x2F;code&gt; while holding &lt;code&gt;Lock A&lt;&#x2F;code&gt;, but elsewhere &lt;code&gt;Lock A&lt;&#x2F;code&gt; is acquired after &lt;code&gt;Lock B&lt;&#x2F;code&gt;, the build fails.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;implementation-path-progressive-disclosure&quot;&gt;Implementation Path: &quot;Progressive Disclosure&quot;&lt;&#x2F;h2&gt;
&lt;p&gt;The beauty of the CLEAR architecture is that &lt;strong&gt;STRICT EXTREME&lt;&#x2F;strong&gt; does not hinder the early-stage developer:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Draft Phase&lt;&#x2F;strong&gt;: The developer writes code in Standard mode. The compiler silently tracks ownership and effects.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Optimization Phase&lt;&#x2F;strong&gt;: The developer turns on &lt;code&gt;STRICT&lt;&#x2F;code&gt; mode to remove bottlenecks (allocations&#x2F;blocking).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Certification Phase&lt;&#x2F;strong&gt;: The developer turns on &lt;code&gt;STRICT EXTREME&lt;&#x2F;code&gt;. The compiler takes the existing metadata and &quot;Hardens&quot; it using formal verification.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;architecture-logic&quot;&gt;Architecture &amp;amp; Logic&lt;&#x2F;h2&gt;
&lt;p&gt;Because CLEAR&#x27;s memory model is a &lt;strong&gt;Directed Acyclic Graph (DAG)&lt;&#x2F;strong&gt; (enforced by Affine movement and Arena scopes), it is mathematically &quot;Decidable.&quot; Proving properties about CLEAR code is significantly simpler than proving properties about C++ or Rust because &lt;strong&gt;aliasing is strictly controlled and visible&lt;&#x2F;strong&gt; to the &lt;code&gt;Annotator&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;goal-for-v0-3-roadmap&quot;&gt;Goal for v0.3 Roadmap&lt;&#x2F;h3&gt;
&lt;p&gt;Integration of a formal solver into the &lt;code&gt;Annotator&lt;&#x2F;code&gt; to provide &quot;Panic-Free&quot; proofs for core data-processing pipelines.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Deadlock in CLEAR</title>
        <published>2026-04-22T00:00:00+00:00</published>
        <updated>2026-05-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/deadlock/"/>
        <id>https://cuzzo.github.io/clear/docs/deadlock/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/deadlock/">&lt;p&gt;&lt;strong&gt;Matrix row:&lt;&#x2F;strong&gt; Deadlock — C: F, Rust: F, Go: F, Pony: A+, BEAM: A+, CLEAR: A-*&lt;&#x2F;p&gt;
&lt;p&gt;The asterisk: CLEAR uses locks for read-heavy workloads where MVCC unpredictability is a non-starter. Locks can deadlock in standard mode. CLEAR provides runtime detection + recovery, and &lt;code&gt;STRICT EXTREME&lt;&#x2F;code&gt; (roadmap) will add compile-time lock-ordering enforcement.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;why-the-ab-ba-pattern-is-not-the-main-clear-footgun&quot;&gt;Why the AB&#x2F;BA Pattern Is Not the Main CLEAR Footgun&lt;&#x2F;h2&gt;
&lt;p&gt;The classic two-thread deadlock (thread A holds lock 1, waits for lock 2; thread B holds lock 2, waits for lock 1) requires two actors holding their respective lock simultaneously. In CLEAR&#x27;s cooperative fiber scheduler, fibers only yield at explicit yield points (&lt;code&gt;NEXT&lt;&#x2F;code&gt;, I&#x2F;O). There is no yield between acquiring the first lock and acquiring the second inside a &lt;code&gt;WITH EXCLUSIVE&lt;&#x2F;code&gt; block, so the AB&#x2F;BA cycle cannot form on a single scheduler: the first fiber grabs both locks before the second fiber ever runs.&lt;&#x2F;p&gt;
&lt;p&gt;The AB&#x2F;BA pattern does become dangerous with &lt;code&gt;@parallel&lt;&#x2F;code&gt; (multi-scheduler, multiple OS threads), because the fibers then run on different OS threads simultaneously. But in the common single-scheduler case, it is not the footgun to worry about.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;the-real-footgun-re-entrant-locking&quot;&gt;The Real Footgun: Re-Entrant Locking&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR&#x27;s &lt;code&gt;@locked&lt;&#x2F;code&gt; uses a non-recursive &lt;code&gt;pthread_mutex_t&lt;&#x2F;code&gt;. If a fiber tries to acquire a lock it already holds, &lt;code&gt;pthread_mutex_lock&lt;&#x2F;code&gt; blocks the OS thread — and since the fiber holding the lock IS that OS thread, it can never release it. Deadlock.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT State &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    s = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;State&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@locked&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    t = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH EXCLUSIVE&lt;&#x2F;span&gt;&lt;span&gt; s &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; outer {
&lt;&#x2F;span&gt;&lt;span&gt;            outer.value = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# DEADLOCK: trying to re-acquire the same mutex this fiber holds.
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# pthread_mutex_lock blocks the OS thread. The lock is never
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# released because the releaser IS the blocked fiber.
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH EXCLUSIVE&lt;&#x2F;span&gt;&lt;span&gt; s &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; inner {
&lt;&#x2F;span&gt;&lt;span&gt;                inner.value = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            }
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    };
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; t;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# hangs here
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This compiles without error and hangs at runtime.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Fix:&lt;&#x2F;strong&gt; restructure so the same lock is never acquired twice on the same call path. Pass the already-locked inner value to helper functions instead of locking again:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; update_inner(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;inner: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;State&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Takes the already-unlocked value; no lock needed here.
&lt;&#x2F;span&gt;&lt;span&gt;    inner.value = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    s = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;State&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@locked&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    t = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH EXCLUSIVE&lt;&#x2F;span&gt;&lt;span&gt; s &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; inner {
&lt;&#x2F;span&gt;&lt;span&gt;            inner.value = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            update_inner(inner);  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# pass the unlocked value, not the lock
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    };
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; t;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;the-next-inside-with-footgun&quot;&gt;The NEXT-Inside-WITH Footgun&lt;&#x2F;h2&gt;
&lt;p&gt;A subtler variant: fiber A holds a lock and calls &lt;code&gt;NEXT&lt;&#x2F;code&gt; on a promise produced by fiber B — but fiber B also needs that lock to complete.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT State &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    s = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;State&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@locked&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    producer = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# producer needs &amp;#39;s&amp;#39; to do its work
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH EXCLUSIVE&lt;&#x2F;span&gt;&lt;span&gt; s &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; inner {
&lt;&#x2F;span&gt;&lt;span&gt;            inner.value = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;42&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    };
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    consumer = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH EXCLUSIVE&lt;&#x2F;span&gt;&lt;span&gt; s &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; outer {
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# consumer holds &amp;#39;s&amp;#39;, then waits for producer
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; producer;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# DEADLOCK: producer can&amp;#39;t acquire &amp;#39;s&amp;#39; — consumer holds it
&lt;&#x2F;span&gt;&lt;span&gt;            print(outer.value.toString());
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    };
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; consumer;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# hangs here
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The fiber holding the lock yields via &lt;code&gt;NEXT&lt;&#x2F;code&gt;, but the lock is NOT released when a fiber yields — &lt;code&gt;WITH EXCLUSIVE&lt;&#x2F;code&gt; holds the lock for the duration of the block, not just until the next yield point. The producer is stuck waiting for the lock that the consumer holds while waiting for the producer.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Fix:&lt;&#x2F;strong&gt; resolve the promise before entering the lock, or restructure so the two operations don&#x27;t depend on each other:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    s = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;State&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@locked&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    producer = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH EXCLUSIVE&lt;&#x2F;span&gt;&lt;span&gt; s &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; inner {
&lt;&#x2F;span&gt;&lt;span&gt;            inner.value = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;42&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    };
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; producer;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# wait for producer BEFORE acquiring the lock
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; s &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; inner {
&lt;&#x2F;span&gt;&lt;span&gt;        print(inner.value.toString());  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 42
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;strict-extreme-compile-time-lock-ordering-roadmap&quot;&gt;STRICT EXTREME: Compile-Time Lock Ordering (Roadmap)&lt;&#x2F;h2&gt;
&lt;p&gt;In &lt;code&gt;STRICT EXTREME&lt;&#x2F;code&gt; mode (planned, not yet implemented), the compiler will enforce a global acquisition hierarchy via the &lt;code&gt;OwnershipGraph&lt;&#x2F;code&gt;. Re-entrant acquisition and AB&#x2F;BA cycles will be detected at build time:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;error: re-entrant lock acquisition
&lt;&#x2F;span&gt;&lt;span&gt;  fiber acquires &amp;#39;s&amp;#39; at line 8 (WITH EXCLUSIVE)
&lt;&#x2F;span&gt;&lt;span&gt;  then acquires &amp;#39;s&amp;#39; again at line 11 (WITH EXCLUSIVE)
&lt;&#x2F;span&gt;&lt;span&gt;  fix: pass the already-locked pointer to helper functions instead
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;See &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;docs&#x2F;strict-extreme&#x2F;&quot;&gt;docs&#x2F;strict-extreme.md&lt;&#x2F;a&gt; for the full STRICT EXTREME roadmap.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;fix-single-lock-scope-always-safe&quot;&gt;Fix: Single Lock Scope (Always Safe)&lt;&#x2F;h2&gt;
&lt;p&gt;Restructure so each operation needs only one lock at a time. No re-entrancy, no NEXT-inside-WITH:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    a = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Account&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;balance: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@locked&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    b = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Account&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;balance: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;200 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@locked&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    t1 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        amount = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH EXCLUSIVE&lt;&#x2F;span&gt;&lt;span&gt; a &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; ra {
&lt;&#x2F;span&gt;&lt;span&gt;            amount = ra.balance &#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            ra.balance = ra.balance - amount;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# a is unlocked here. No re-entrancy possible.
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH EXCLUSIVE&lt;&#x2F;span&gt;&lt;span&gt; b &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; rb {
&lt;&#x2F;span&gt;&lt;span&gt;            rb.balance = rb.balance + amount;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    };
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; t1;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The tradeoff: releasing between the two operations creates a TOCTOU window (see &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cuzzo&#x2F;clear&#x2F;blob&#x2F;master&#x2F;examples&#x2F;footguns&#x2F;05_toctou&#x2F;main.cht&quot;&gt;examples&#x2F;footguns&#x2F;05_toctou&lt;&#x2F;a&gt;).&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;why-c-go-and-rust-get-f&quot;&gt;Why C, Go, and Rust Get F&lt;&#x2F;h2&gt;
&lt;p&gt;All three languages expose the same non-recursive mutex with no re-entrancy detection and no built-in deadlock timeout:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;C&lt;&#x2F;strong&gt; (&lt;code&gt;pthread_mutex_lock&lt;&#x2F;code&gt;): hangs forever on re-entrant lock or AB&#x2F;BA cycle. No detection without Helgrind or TSan.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Go&lt;&#x2F;strong&gt; (&lt;code&gt;sync.Mutex&lt;&#x2F;code&gt;): hangs forever for partial deadlocks. Detects global deadlock (all goroutines blocked) with a panic. Race detector does not catch deadlocks.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Rust&lt;&#x2F;strong&gt; (&lt;code&gt;std::sync::Mutex&lt;&#x2F;code&gt;): hangs forever. Attempting to lock from the same thread panics on some platforms (documented as &quot;may panic or deadlock&quot;). &lt;code&gt;parking_lot&lt;&#x2F;code&gt; adds optional cycle detection.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Pattern&lt;&#x2F;th&gt;&lt;th&gt;Current CLEAR behavior&lt;&#x2F;th&gt;&lt;th&gt;Planned fix&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Re-entrant lock (same fiber re-acquires)&lt;&#x2F;td&gt;&lt;td&gt;Hangs — non-recursive mutex&lt;&#x2F;td&gt;&lt;td&gt;STRICT EXTREME: compile error&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;NEXT inside WITH (holding lock while awaiting)&lt;&#x2F;td&gt;&lt;td&gt;Hangs — lock not released on yield&lt;&#x2F;td&gt;&lt;td&gt;STRICT EXTREME: compile error&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;AB&#x2F;BA across @parallel fibers&lt;&#x2F;td&gt;&lt;td&gt;Hangs — same as C&#x2F;Go&#x2F;Rust&lt;&#x2F;td&gt;&lt;td&gt;STRICT EXTREME: compile error&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;AB&#x2F;BA on single scheduler&lt;&#x2F;td&gt;&lt;td&gt;Does not occur — no yield between lock acquisitions&lt;&#x2F;td&gt;&lt;td&gt;N&#x2F;A&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Why CLEAR</title>
        <published>2026-04-20T00:00:00+00:00</published>
        <updated>2026-05-11T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/why-these-priorities/"/>
        <id>https://cuzzo.github.io/clear/docs/why-these-priorities/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/why-these-priorities/">&lt;p&gt;CLEAR is designed to be:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Correct&lt;&#x2F;li&gt;
&lt;li&gt;Safe&lt;&#x2F;li&gt;
&lt;li&gt;Understandable&lt;&#x2F;li&gt;
&lt;li&gt;Scalable&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;BLAZING&lt;&#x2F;em&gt; fast&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;but-why&quot;&gt;But Why?&lt;&#x2F;h2&gt;
&lt;p&gt;Rust to have memory safety with no overhead - primarily to use for Servo to replace C for Browser Engines and for Kernel development. There are a number of tradeoffs Rust was not willing to make for it to be either 1) easy &#x2F; understandable, or 2) a better Go.&lt;&#x2F;p&gt;
&lt;p&gt;Yet people are desperate to use Rust as a better Go because it has so much potential to be that.&lt;&#x2F;p&gt;
&lt;p&gt;Pony eliminates nearly all concurrency hazards by design. Rust merely ensures memory safety - which is perhaps the most common and critical concurrency hazard. But despite its safety, Pony is not widely used because the learning curve is too steep.&lt;&#x2F;p&gt;
&lt;p&gt;Rust &amp;amp; Pony were both not willing to make tradeoffs to prioritize ease-of-use or understandability.&lt;&#x2F;p&gt;
&lt;p&gt;Go made those trade-offs. But Go is a thin veneer over C with the most sophisticated runtime in the world bolted on. To achieve best in class speeds Go - like C - relies on loading a footgun and exposing yourself to a number of hazards and developer discipline and&#x2F;or choosing the right libraries to get it right. It provides valuable best-in-class tooling to help mitigate &lt;em&gt;some&lt;&#x2F;em&gt; of these problems.&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR exists because it thinks Rust is not truly safe enough inherently, Pony is not easy enough, and Go is currently the most practical trade-off but is too dangerous and cannot fix its inherent problems.&lt;&#x2F;p&gt;
&lt;p&gt;Further, although Pony literally forces you into the actor pattern - at least at this stage, it is not inherently distributive. The actor model does not require serialization, distributed fault tolerance, supervision, etc. Pony uses the ideas to achieve safety on a single machine, but just because you wrote the code that &lt;em&gt;allows&lt;&#x2F;em&gt; for distribution easily, does not mean it actually can be distributed effectively by default.&lt;&#x2F;p&gt;
&lt;p&gt;Pony did not want to make any sacrifices on safety. This led to a language that is impractical and&#x2F;or not competitive for many of workloads (with a high cognitive burden).&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR &lt;strong&gt;aims&lt;&#x2F;strong&gt; to take the lessons of Pony, Rust, Go, and BEAM and combine them. The goal is to make trade-offs to achieve understandability, and to sacrifice &lt;em&gt;some&lt;&#x2F;em&gt; safety if it means giving you tools necessary to realistically accomplish common workloads.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rubric&quot;&gt;Rubric&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Feature&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: center&quot;&gt;C&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: center&quot;&gt;Rust&#x2F;Tokio&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: center&quot;&gt;Go&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: center&quot;&gt;Pony&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: center&quot;&gt;BEAM&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: center&quot;&gt;CLEAR&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Cognitive Load&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F *&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;D+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;D-&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;C+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A-&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Memory Safety&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B *&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A+&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Raw Speed&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A-&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;C&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A-&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Throughput&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Memory Usage&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B-&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;C-&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A-&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Predictability&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B-&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A-&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A-&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Backpressure&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;C&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Starvation&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A-&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Fault Tolerance&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;?&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Deadlock&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;C&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;C+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A- *&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Memory Ordering&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;C&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;A-&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Logical TOCTOU&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;A-&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;B+&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Causal Ordering&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;B+&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;C&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;B *&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Stream Ordering&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;F&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;?&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;non-clear-ratings-context-justification&quot;&gt;Non-CLEAR Ratings: Context &amp;amp; Justification&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;All ratings are inherently subjective.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The C Cognitive Load Controversy:&lt;&#x2F;strong&gt; C scoring an &lt;strong&gt;F&lt;&#x2F;strong&gt; may be controversial, but &quot;Cognitive Load&quot; here captures the true difficulty of writing &lt;em&gt;correct&lt;&#x2F;em&gt; concurrent systems. C’s F is the price it pays for A+ ratings elsewhere; you could write C with a B in cognitive load (e.g., using a single global lock), but throughput would plummet to an F. Similarly, you could bolt on a Garbage Collector to improve safety, but speed and predictability would drop to a C.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;The “Best Practices Fallacy”:&lt;&#x2F;strong&gt; Given perfect discipline and SOTA libraries, one can achieve better ratings in C, Rust, or Go. However, &quot;doing it right&quot; is not a scalable systems architecture. These ratings reflect the language’s inherent, default guarantees.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;The Rust&#x2F;Tokio Note:&lt;&#x2F;strong&gt; Rust is graded slightly unfairly as its evaluation includes Tokio. While not part of the core language, it is the &lt;em&gt;de facto&lt;&#x2F;em&gt; production standard and its semantics must be evaluated.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;The Go Scheduler:&lt;&#x2F;strong&gt; Go experts may feel there isn&#x27;t enough separation in Throughput&#x2F;Backpressure. CLEAR praises Go’s runtime and scheduler as one of the most sophisticated pieces of software ever written; these ratings may not do its operational excellence enough justice.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Go Memory Safety:&lt;&#x2F;strong&gt; Go is memory-safe in the conventional sense, but it does not provide strong concurrency-safety or invariant-safety by default. Its practical model often relies on discipline around shared mutable state.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;The Pony Asterisk:&lt;&#x2F;strong&gt; Pony’s flawless safety comes at a hit to expressiveness. By forbidding shared mutable state, certain highly efficient data structures (like lock-free graphs) are nearly impossible to write idiomatically.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;clear-ratings-the-architecture&quot;&gt;CLEAR Ratings: The Architecture&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cognitive Load:&lt;&#x2F;strong&gt; CLEAR is designed so that &lt;strong&gt;Profile Guided Optimization (PGO)&lt;&#x2F;strong&gt; and automated tooling solve the heavy lifting. You write intuitive, sequential code, and the profiler suggests (and injects) the necessary optimization directives based on actual workloads.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Memory Safety:&lt;&#x2F;strong&gt; Like Rust, CLEAR utilizes &lt;strong&gt;Affine Ownership&lt;&#x2F;strong&gt; to guarantee memory safety.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Logical TOCTOU:&lt;&#x2F;strong&gt; Values behind Arcs&#x2F;Locks cannot escape lexical scope. The compiler can generate &lt;strong&gt;Loom tests&lt;&#x2F;strong&gt; in a deterministic VM to catch dependencies and break them. Use-after-free and race conditions are included in Memory Safety. Time-related bugs are captured in Causal &amp;amp; Stream Ordering categories.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Deadlock:&lt;&#x2F;strong&gt; Technical deadlock is not part of CLEAR’s intended concurrency model, and by v0.3 the runtime aims to detect and prevent unbounded lock-wait cycles from silently persisting. Locks are intentionally more cumbersome to use because they are rarely the best-performing or safest solution. When developers opt into lock-based coordination anyway, they are also opting into explicit responsibility for handling lock-related failures correctly. A language like Pony or BEAM which does not have locks deserves a better ranking.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Starvation &amp;amp; Backpressure:&lt;&#x2F;strong&gt; Like BEAM, CLEAR &lt;em&gt;will&lt;&#x2F;em&gt; prevent CPU starvation via its cooperative scheduler with automatically injected yielding. It separately tracks per-task memory consumption to kill runaway tasks and enforce backpressure.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Memory Consumption:&lt;&#x2F;strong&gt; CLEAR uses &lt;strong&gt;MVCC&lt;&#x2F;strong&gt; as a default synchronization technique. This adds memory overhead to eliminate common classes of bugs (deadlocks, contention).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Causal Ordering:&lt;&#x2F;strong&gt; CLEAR separates time as a &lt;strong&gt;tense&lt;&#x2F;strong&gt; in the type system, and offers &lt;strong&gt;A+&lt;&#x2F;strong&gt; causal ordering with &lt;code&gt;@split&lt;&#x2F;code&gt; streams and solves the concurrent write problem with MVCC and transaction failure handling. But it allows you to &quot;load the foot-gun&quot; (unsafe escape hatches) for specific workloads where predictability is paramount.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Stream Ordering:&lt;&#x2F;strong&gt; CLEAR has not yet determined if it will offer any guarantees to protect against stream ordering related bugs. Frameworks like Flink and Kafka exist to solve this problem. It may not make sense to try to solve it in the runtime&#x2F;language.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Fault Tolerance:&lt;&#x2F;strong&gt; It is still too early in the design stage to determine a realistic score for CLEAR&#x27;s fault tolerance story—particularly regarding issues that arise from shared mutable memory and the fact that idempotence is not a first-class function color.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;fault-tolerance&quot;&gt;Fault Tolerance&lt;&#x2F;h3&gt;
&lt;p&gt;CLEAR hopes to have a reasonable ceiling of a &lt;strong&gt;B&lt;&#x2F;strong&gt; (similar to Causal Ordering). It will likely give you tools to shoot yourself in the foot to prioritize understandability and broad workload support—for example, you could mark tasks as killable which aren&#x27;t, or tasks as retrying which aren&#x27;t idempotent. But CLEAR will have the systems in place to easily support an &lt;strong&gt;A+&lt;&#x2F;strong&gt; architecture when paired with modern infrastructure.&lt;&#x2F;p&gt;
&lt;p&gt;The fact that everything else scores an &lt;strong&gt;F&lt;&#x2F;strong&gt; besides BEAM is evidence that solving these problems purely at the language level may no longer be the best choice.&lt;&#x2F;p&gt;
&lt;p&gt;The approach CLEAR is currently most interested in is targeting the five most common catastrophic faults:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;CPU Starvation&lt;&#x2F;strong&gt; (Time)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Local Heap Exhaustion&lt;&#x2F;strong&gt; (Space)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Lexical Orphanhood&lt;&#x2F;strong&gt; (The spawning task died; the work is no longer relevant)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Data-Flow Severance&lt;&#x2F;strong&gt; (Producing a stream that no one is listening to)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Deadlocks&lt;&#x2F;strong&gt; (Unbounded lock-wait cycles)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;CLEAR aims to either safely assassinate the offending fibers automatically (Deadlocks&#x2F;Orphans) or detect the threshold and force the developer to handle the outcome (OOM limits).&lt;&#x2F;p&gt;
&lt;p&gt;Whatever CLEAR&#x27;s final solution ends up being, BEAM folks are likely to look at it and say, &quot;That&#x27;s basically an F.&quot; But CLEAR aims to provide pragmatic value.  Like BEAM folks, CLEAR is of the view that killing entire processes with important state just because you have no built-in fault tolerance is insane.  Unlike BEAM, CLEAR is unlikely to eliminate the possibility of &lt;em&gt;needing&lt;&#x2F;em&gt; to do that &lt;em&gt;occasionally&lt;&#x2F;em&gt;, but it aims to reduce that need to practically zero.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;how-does-clear-think-about-cognitive-burden&quot;&gt;How Does CLEAR think about Cognitive Burden&lt;&#x2F;h2&gt;
&lt;p&gt;In CLEAR&#x27;s perspective, a program becomes difficult to understand because of global complexity.&lt;&#x2F;p&gt;
&lt;p&gt;A function is impossible to understand if the entire codebase must be understood to understand the function and line of code you are looking at.&lt;&#x2F;p&gt;
&lt;p&gt;This is why CLEAR aims to completely eradicate all forms of global complexity. If you can understand any function fully by just looking at the function, it is simple.&lt;&#x2F;p&gt;
&lt;p&gt;Rust is not considered difficult because of Affine Ownership.  It is considered difficult because of &quot;Fighting the Borrow Checker&quot; which mainly boils down to Rust&#x27;s obsession that it must achieve zero-cost abstractions in &lt;em&gt;ALL&lt;&#x2F;em&gt; cases - which includes shared-mutable borrows. This is almost entirely the source of confusing lifetime annotations in Rust. If you eliminate this demand, you eliminate most of the &quot;Fighting the Borrow Checker&quot; in Rust complaints. CLEAR has done this. This is because this is Rust&#x27;s main source of global complexity.&lt;&#x2F;p&gt;
&lt;p&gt;Pony is not considered difficult because it merely has capabilities or because it forces you into the actor pattern. It is difficult because capabilities do are not intuitive. You aren&#x27;t describing what you &lt;em&gt;want&lt;&#x2F;em&gt; to do, you are describing what &lt;em&gt;can be done&lt;&#x2F;em&gt;. This is less intuitive.&lt;&#x2F;p&gt;
&lt;p&gt;Go claims to be &lt;em&gt;easy&lt;&#x2F;em&gt; - which implies simplicity. But Go allows and often forces you to load footguns to achieve decent performance, lending itself to global complexity and hard-to-understand programs.&lt;&#x2F;p&gt;
&lt;p&gt;Go may claim to be easy, but if you need to write 20 lines of imperative arcana in the precise ceremonial order or rely on a set of libraries to do common things efficiently - it is not truly easy.&lt;&#x2F;p&gt;
&lt;p&gt;In essence, CLEAR thinks SQL proved that it is relatively easy to describe &lt;em&gt;what&lt;&#x2F;em&gt; you want to do (your intent), and it is certainly easy to recognize it after the Profiler points you in the right direction for efficiency and safety (one-line optimizations clearly separate from code).&lt;&#x2F;p&gt;
&lt;p&gt;It is much harder to think like the computer and tell it &lt;em&gt;HOW&lt;&#x2F;em&gt; to do that, or list what &lt;em&gt;CAN&lt;&#x2F;em&gt; be done and hope that matches what you want to do.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;how-does-clear-think-about-performance-and-speed&quot;&gt;How Does CLEAR think about Performance and Speed&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;strong&gt;Raw Speed&lt;&#x2F;strong&gt; being a metric should raise some eyebrows.  Performance is not a monolith. It is a balance of competing trade-offs.&lt;&#x2F;p&gt;
&lt;p&gt;From CLEAR&#x27;s perspective - Correct, Safe, and Understandable are by far the most important pillars of the design that are being balanced.&lt;&#x2F;p&gt;
&lt;p&gt;When CLEAR thinks about speed, it mainly thinks about &lt;strong&gt;single machine&lt;&#x2F;strong&gt; concurrent throughput in compute heavy workloads. CLEAR is looking toward the future of compute rather than the present.&lt;&#x2F;p&gt;
&lt;p&gt;In the future, core count is expected to continue growing faster than memory.  Cache per core has not meaningfully grown much in decades, and CLEAR &lt;em&gt;assumes&lt;&#x2F;em&gt; this will not grow as meaningfully as core count in the future.&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR thinks the main &lt;strong&gt;Raw Speed&lt;&#x2F;strong&gt; metrics are: 1) compiling via Zig to get LLVM best in class optimizations to single-core performance, 2) maximizing for &lt;strong&gt;cache locality&lt;&#x2F;strong&gt; as memory read stalls can dominate compute performance benchmarks.&lt;&#x2F;p&gt;
&lt;p&gt;In general, CLEAR aims to &lt;em&gt;overcome&lt;&#x2F;em&gt; added memory, co-operative yielding, and any safety checks by gaining a level of cache locality that is nearly impossible to reach in any other language.&lt;&#x2F;p&gt;
&lt;p&gt;How?&lt;&#x2F;p&gt;
&lt;p&gt;The core pillar of CLEAR&#x27;s design is to maximize local reasoning and minimize global complexity. This is what makes CLEAR &lt;strong&gt;simple&lt;&#x2F;strong&gt;, even if it may not be as &lt;strong&gt;easy&lt;&#x2F;strong&gt; as Go. It also &lt;strong&gt;should&lt;&#x2F;strong&gt; allow CLEAR to make compiler optimizations WRT escape analysis that no other language (that we are aware of) can make to maximize cache locality.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PROPAGANDA</title>
        <published>2026-04-05T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-readme/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-readme/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-readme/">&lt;p&gt;&lt;em&gt;Cheating is all you need.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Software should be performant, robust, AND resilient.&lt;&#x2F;li&gt;
&lt;li&gt;It should also be effortless to write and understand.&lt;&#x2F;li&gt;
&lt;li&gt;It should be able to run anywhere, optimized for distributed parallelism and concurrency.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;They told you &quot;Pick one.&quot; They lied.&lt;&#x2F;p&gt;
&lt;p&gt;You can have it all, if you&#x27;re willing to CHEAT.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Commands like SQL. Pipelines like Bash. Easy like Ruby. Speed like C.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Being a genius like &lt;em&gt;antirez&lt;&#x2F;em&gt; isn&#x27;t scalable. It&#x27;s not something everyone can be.&lt;&#x2F;p&gt;
&lt;p&gt;Everyone else can CHEAT.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-cheat&quot;&gt;WHAT IS CHEAT?&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR is a memory safe language like Rust, with better ergonomics than Swift.&lt;&#x2F;p&gt;
&lt;p&gt;It runs on a Go-like Runtime (the CHEAT runtime) that makes concurrent code as easy, safe, and fast as possible.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;core-clear-philosophy&quot;&gt;CORE CLEAR PHILOSOPHY&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Code should work.&lt;&#x2F;li&gt;
&lt;li&gt;Code that is easy to understand, write, AND test is more likely to work.&lt;&#x2F;li&gt;
&lt;li&gt;Dependencies should be Strictly-Correct, as that &lt;em&gt;IS&lt;&#x2F;em&gt; their business logic.&lt;&#x2F;li&gt;
&lt;li&gt;Applications should &lt;em&gt;FIRST&lt;&#x2F;em&gt; be Business-Logic correct, only Strictly-Correct if need be.&lt;&#x2F;li&gt;
&lt;li&gt;The language and compiler should never get in the way of Business-Logic correctness.&lt;&#x2F;li&gt;
&lt;li&gt;Making things Strictly-Correct, once Business-Logic correct, should be easy.&lt;&#x2F;li&gt;
&lt;li&gt;Making things &lt;em&gt;BLAZING&lt;&#x2F;em&gt; fast, once Strictly-Correct, should be easy.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>manifesto EXTRA</title>
        <published>2026-04-03T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-extra/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-extra/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-extra/">&lt;h3 id=&quot;handling-array-access&quot;&gt;Handling Array Access&lt;&#x2F;h3&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;x = getMyVector();
&lt;&#x2F;span&gt;&lt;span&gt;y = x[10]; -- compiler error!
&lt;&#x2F;span&gt;&lt;span&gt;y = x[10] OR ELSE 0; -- OKAY!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;x: Int[10] = getMyVector();
&lt;&#x2F;span&gt;&lt;span&gt;y = x[9];                                -- OK
&lt;&#x2F;span&gt;&lt;span&gt;z = x[10];                               -- COMPILER ERROR: Out of Bounds
&lt;&#x2F;span&gt;&lt;span&gt;zz = x[10] OR ELSE 0;                    -- OK - with a strong *WARNING* (compiler error in STRICT mode)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN myVectorGetterDoer(v) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- preferred to use a GUARD clause
&lt;&#x2F;span&gt;&lt;span&gt;  z = GUARD v.size &amp;gt;= 56 OR ELSE CAST(v AS Int(56)); -- TODO: Is this too hard for the compiler to know?
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  x = v[10]; -- OKAY, proven &amp;gt;10
&lt;&#x2F;span&gt;&lt;span&gt;  y = v[23]; -- OKAY, proven &amp;gt;23
&lt;&#x2F;span&gt;&lt;span&gt;  z = v[55]; -- OKAY, proven &amp;gt;55
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN x + y - z + 5;
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN myVectorGetterDoer(v) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  x = v[10];
&lt;&#x2F;span&gt;&lt;span&gt;  y = v[23];
&lt;&#x2F;span&gt;&lt;span&gt;  z = v[55];
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN x + y - z + 5;
&lt;&#x2F;span&gt;&lt;span&gt;CATCH
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN 0;                                    -- OK: caught here, returning a value
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN myVectorGetterAdder(v) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  x = v[10] OR RETURN 5;                   -- OK: IFF you return a value, not the error.
&lt;&#x2F;span&gt;&lt;span&gt;  x = v[10] OR RETURN v[0];                -- COMPILER ERROR: OBVIOUSLY!
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN x + 5;
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- here v is a DYNAMIC Vector.
&lt;&#x2F;span&gt;&lt;span&gt;FN myVectorGetterWhichTakesADynamicArrayAndResizes(v) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- ... do a bunch of stuff
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  x: Int[10] = v;                           -- COMPILER ERROR!
&lt;&#x2F;span&gt;&lt;span&gt;  xx: Int[10] = TRUNCATE(v);                -- OK: acknolwedge you *could* be losing data.
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  y = xx[9];                                -- OK: it will be 0 by default, if v was &amp;lt; 10 items.
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- ... do a bunch of stuff
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN x + 5;
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- here v is a FIXED Vector of size 1.
&lt;&#x2F;span&gt;&lt;span&gt;FN myVectorGetterWhichTakesADynamicArrayAndResizes(v) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- ... do a bunch of stuff
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  x: Int[10] = v;                           -- OK: perhaps surprisingly, you&amp;#39;re allowed to upsize, no harm no foul
&lt;&#x2F;span&gt;&lt;span&gt;  y = x[9];                                 -- OK: it will be 0 by default, if v was &amp;lt; 10 items.
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- ... do a bunch of stuff
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN x + 5;
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;handling-division-by-zero&quot;&gt;Handling Division by Zero&lt;&#x2F;h3&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;FN myDivider(x, y) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  y = GAURD y != 0 OR ELSE 1; -- OKAY, if y is MUTABLE
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN x &#x2F; y;
&lt;&#x2F;span&gt;&lt;span&gt;end
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- this is fine in a function
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN typicalFunc(myObj) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  health = GUARD myObj.health != 0 OR ELSE 1;
&lt;&#x2F;span&gt;&lt;span&gt;  -- Do a bunch of stuff
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN myObj.strength &#x2F; myObj.health;
&lt;&#x2F;span&gt;&lt;span&gt;end
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- Say you had a complex formula with lots of division
&lt;&#x2F;span&gt;&lt;span&gt;-- You might not want to have
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN typicalFunc(myObj) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  health = GUARD myObj.health != 0 OR ELSE 1;
&lt;&#x2F;span&gt;&lt;span&gt;  -- 10 more guards, needing to use local variables below
&lt;&#x2F;span&gt;&lt;span&gt;  -- Do a bunch of stuff
&lt;&#x2F;span&gt;&lt;span&gt;  -- RETURN &amp;lt;your equation with a bunch of division&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;end
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- Instead you can do:
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN typicalFunc(myObj) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- RETURN &amp;lt;your equation with a bunch of division&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;CATCH
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN -1;
&lt;&#x2F;span&gt;&lt;span&gt;end
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- HOWEVER - there is no such option for code outside of a function.
&lt;&#x2F;span&gt;&lt;span&gt;-- You can do:
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN main()
&lt;&#x2F;span&gt;&lt;span&gt;  -- Good design, no code execution outside of main
&lt;&#x2F;span&gt;&lt;span&gt;  -- In here, you do do all kind of division
&lt;&#x2F;span&gt;&lt;span&gt;CATCH
&lt;&#x2F;span&gt;&lt;span&gt;  -- Handle however you want, except with code that raises an uncaught error
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- If you just have a script like:
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;x = readSomeFileGetSomeNumber();
&lt;&#x2F;span&gt;&lt;span&gt;y = 10;
&lt;&#x2F;span&gt;&lt;span&gt;callSomeFunc(y &#x2F; x);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- You&amp;#39;ll get a DivisionByZero error, so you must do:
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;x = GUARD readSomeFileGetSomeNumber() != 0 OR ELSE 1;
&lt;&#x2F;span&gt;&lt;span&gt;y = 10
&lt;&#x2F;span&gt;&lt;span&gt;callSomeFunc(y &#x2F; x);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;async-await-collect&quot;&gt;ASYNC&#x2F;AWAIT&#x2F;COLLECT&lt;&#x2F;h3&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;listOfUsers
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; FILTER %.isActive
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; COLLECT                 -- Converts Stream&amp;lt;User&amp;gt; to List&amp;lt;User&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; map(%(x) -&amp;gt; x.size &amp;gt; 5); -- Operates on the List&amp;lt;User&amp;gt; object
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- Did not prefix with AWAIT -&amp;gt; *assumes* intentend ASYNC -&amp;gt; immediately starts next step
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;file_paths
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; concurrentRead
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; COLLECT             -- Wait for ALL files to be fetched&#x2F;materialized.
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; aggregate;          -- Start aggregation only on the complete set.
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- Did not prefix with AWAIT -&amp;gt; *assumes* intentend ASYNC -&amp;gt; immediately starts next step
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;file_paths
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; concurrentRead
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; COLLECT             -- Wait for ALL files to be fetched&#x2F;materialized.
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; aggregate
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; COLLECT;            -- waits until THIS finishes to resume (which may happen before the other two finish)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- The above is *nearly* equivalent to:
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;AWAIT file_paths
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; concurrentRead
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; COLLECT             -- Wait for ALL files to be fetched&#x2F;materialized.
&lt;&#x2F;span&gt;&lt;span&gt;  s&amp;gt; aggregate;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- This is preferred, but not enforced.
&lt;&#x2F;span&gt;&lt;span&gt;-- Ending in COLLECT will convert from Stream&amp;lt;T&amp;gt; to List&amp;lt;T&amp;gt; -&amp;gt; even if it&amp;#39;s not assigned to anything.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;mutability-vs-immutability&quot;&gt;MUTABILITY vs IMMUTABILITY&lt;&#x2F;h3&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;user = %{ name: &amp;quot;Alice&amp;quot;, active: false }
&lt;&#x2F;span&gt;&lt;span&gt;user.active = true; -- Error!
&lt;&#x2F;span&gt;&lt;span&gt;user = %{ name: &amp;quot;Alice&amp;quot;, active: true} -- Error!!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;user = %{ name: &amp;quot;Alice&amp;quot;, active: false }
&lt;&#x2F;span&gt;&lt;span&gt;upDatedUser = user MUTATE { active: true } -- No error!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;x = 5;
&lt;&#x2F;span&gt;&lt;span&gt;x += 10; -- ERROR!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;MUTABLE x = 5;
&lt;&#x2F;span&gt;&lt;span&gt;x += 10;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Example compiler errors:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;Error: Cannot set field &amp;#39;active&amp;#39; on &amp;#39;user&amp;#39; to true.
&lt;&#x2F;span&gt;&lt;span&gt;     : This is a READ-ONLY VIEW of memory owned by &amp;#39;DatabaseQueryResult&amp;#39;.
&lt;&#x2F;span&gt;&lt;span&gt;     : To modify, use:
&lt;&#x2F;span&gt;&lt;span&gt;     :
&lt;&#x2F;span&gt;&lt;span&gt;     : newUser = user MUTATE { active: true };
&lt;&#x2F;span&gt;&lt;span&gt;     :
&lt;&#x2F;span&gt;&lt;span&gt;     : Or, if you want to modify it later, you might want it to be MUTABLE, use:
&lt;&#x2F;span&gt;&lt;span&gt;     :
&lt;&#x2F;span&gt;&lt;span&gt;     : MUTABLE newUser = DEEP_COPY(user_data);
&lt;&#x2F;span&gt;&lt;span&gt;     : newUser.active = true;
&lt;&#x2F;span&gt;&lt;span&gt;     :
&lt;&#x2F;span&gt;&lt;span&gt;     : You can set fields on MUTABLE data.
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;Error: Cannot assign to &amp;#39;x&amp;#39;: it is immutable.
&lt;&#x2F;span&gt;&lt;span&gt;     : x is IMMUTABLE.
&lt;&#x2F;span&gt;&lt;span&gt;     :
&lt;&#x2F;span&gt;&lt;span&gt;     : You can create a new binding:
&lt;&#x2F;span&gt;&lt;span&gt;     :
&lt;&#x2F;span&gt;&lt;span&gt;     : newX = x + 5;
&lt;&#x2F;span&gt;&lt;span&gt;     :
&lt;&#x2F;span&gt;&lt;span&gt;     : Or, if you want to modify it later, declare it mutable:
&lt;&#x2F;span&gt;&lt;span&gt;     :
&lt;&#x2F;span&gt;&lt;span&gt;     : MUTABLE newX = x;
&lt;&#x2F;span&gt;&lt;span&gt;     : newX = 5;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;the-confusing-types&quot;&gt;THE CONFUSING TYPES&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;errors&quot;&gt;Errors&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;You don&#x27;t need to check for errors by default or specify them in your return types.&lt;&#x2F;li&gt;
&lt;li&gt;The Compiler and the SMOOTH operator takes care of this for you.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;FN myCarelessFn %(myList) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  myList
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchData -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseData -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; renderPage; -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- It&amp;#39;s fine to not catch any of them here!
&lt;&#x2F;span&gt;&lt;span&gt;-- You&amp;#39;re allowed to pass on the problem to your end user!
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN mySomewhatCarefullFn %(myList) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  myList
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchData -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseData -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; renderPage; -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;CATCH -- anything
&lt;&#x2F;span&gt;&lt;span&gt;  -- No matter what I want my users to get the default page.
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN makeDefaultPage();
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN myMoreCarefullFn %(myList) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  myList
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchData -- doesn&amp;#39;t ever throw an error!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseData -- doesn&amp;#39;t ever throw an error!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; renderPage; -- doesn&amp;#39;t ever throw an error!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;CATCH -- anything
&lt;&#x2F;span&gt;&lt;span&gt;  -- This is still allowed, since no matter what you can OOM
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN makeDefaultPage();
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN myQuiteCarefullFn %(myList) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  myList
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchData OR SKIP -- SKIP any error
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; OTHERWISE(fetchFromBackup) -- OTHERWISE only happens if an error happend, and this may raise error, it&amp;#39;s fine!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseData -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; renderPage; -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;CATCH -- anything EXCEPT fetchData error -&amp;gt; It was already handled inline
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN makeDefaultPage();
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN myReallyCarefullFn %(myList) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  myList
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchData OR SKIP -- SKIP any error
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; OTHERWISE(fetchFromBackup) OR RETURN  -- Don&amp;#39;t proceed any further, bubble this right up to the user
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseData -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; renderPage; -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;CATCH -- anything
&lt;&#x2F;span&gt;&lt;span&gt;  -- EXCEPT fetchData error -&amp;gt; It was already handled inline
&lt;&#x2F;span&gt;&lt;span&gt;  -- EXCEPT fetchFromBackup -&amp;gt; It was already handled inline
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN makeDefaultPage();
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN myVeryCarefullFn %(myList) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  myList
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchData OR SKIP -- SKIP any error
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; OTHERWISE(fetchFromBackup) OR RETURN  -- Don&amp;#39;t proceed any further, bubble this right up to the user
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseData OR EXIT -- Don&amp;#39;t proceed any further, but try to pass this to a catch block below
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; renderPage; -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;CATCH -- anything
&lt;&#x2F;span&gt;&lt;span&gt;  -- EXCEPT fetchData error -&amp;gt; It was already handled inline
&lt;&#x2F;span&gt;&lt;span&gt;  -- EXCEPT fetchFromBackup -&amp;gt; It was already handled inline
&lt;&#x2F;span&gt;&lt;span&gt;  -- DOES CATCH parseData (and renderPage) errors
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN makeDefaultPage();
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN myExtremelyCarefullFn %(myList) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  myList
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchData OR SKIP -- SKIP any error
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; OTHERWISE(fetchFromBackup) OR RETURN  -- Don&amp;#39;t proceed any further, bubble this right up to the user
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseData OR GOTO_RECOVER -- Don&amp;#39;t proceed any further, JUMP to the first RECOVER down the chain
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; renderPage -- this could return an error!
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; RECOVER(makeDefaultPage());
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;CATCH -- anything
&lt;&#x2F;span&gt;&lt;span&gt;  -- EXCEPT fetchData error -&amp;gt; It was already handled inline
&lt;&#x2F;span&gt;&lt;span&gt;  -- EXCEPT fetchFromBackup -&amp;gt; It was already handled inline
&lt;&#x2F;span&gt;&lt;span&gt;  -- DOES CATCH parseData (and renderPage) errors
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN makeDefaultPage();
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;FN myMostCarefulFn %(myList) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  myList
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchData OR SKIP -- SKIP any error
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; OTHERWISE(fetchFromBackup) OR RETURN  -- Don&amp;#39;t proceed any further, bubble this right up to the user
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseData OR GOTO_RECOVER -- Don&amp;#39;t proceed any further, JUMP to the first RECOVER down the chain
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; renderPage OR EXIT &amp;quot;RenderPage failed&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; RECOVER(makeDefaultPage()) OR EXIT &amp;quot;RenderBackupPageFailed&amp;quot;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;CATCH -- anything
&lt;&#x2F;span&gt;&lt;span&gt;  -- Here, there might be two RenderPage errors
&lt;&#x2F;span&gt;&lt;span&gt;  -- Down here, we might want to do two different things based on the same Error (with the context string from above)
&lt;&#x2F;span&gt;&lt;span&gt;  -- In both cases, we have acccess to the Error object `%e`
&lt;&#x2F;span&gt;&lt;span&gt;  -- With %e.message and %e.snapshot (whatever went into the pipe) set.
&lt;&#x2F;span&gt;&lt;span&gt;  --
&lt;&#x2F;span&gt;&lt;span&gt;  -- WARNING: To operate on %e.snapshot, you must cast it from Any to Whatever it is.
&lt;&#x2F;span&gt;&lt;span&gt;  -- This is dangerous, as it could itself raise an error.
&lt;&#x2F;span&gt;&lt;span&gt;  -- If this something like this is not acceptable, CHEAT is not for you.
&lt;&#x2F;span&gt;&lt;span&gt;  --
&lt;&#x2F;span&gt;&lt;span&gt;  -- You CAN log it without issue (with a default limit to how big the string is)
&lt;&#x2F;span&gt;&lt;span&gt;  -- Though, that could contain PII, so unless you control the parent, and can ensure it&amp;#39;s safe for logging
&lt;&#x2F;span&gt;&lt;span&gt;  -- Do so at your own risk
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  RETURN makeDefaultPage();
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- Testing Error handling is easy!
&lt;&#x2F;span&gt;&lt;span&gt;TEST &amp;quot;MyFn handles errors gracefully&amp;quot; -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;   result = ERROR(&amp;quot;Boom&amp;quot;) s&amp;gt; myFn;
&lt;&#x2F;span&gt;&lt;span&gt;   ASSERT result == defaultPage; -- Success!
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;strings-vs-bytes&quot;&gt;Strings Vs Bytes&lt;&#x2F;h3&gt;
&lt;p&gt;String by default.&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;s = &amp;quot;😊&amp;quot;;                     -- String (Immutable)
&lt;&#x2F;span&gt;&lt;span&gt;MUTABLE s = &amp;quot;😊&amp;quot;;                 -- String (Mutable, enforces UTF-8 on write)
&lt;&#x2F;span&gt;&lt;span&gt;s: String[10] = &amp;quot;😊&amp;quot;;         -- String (Immutable, fixed size UTF-8 buffer, very uncommon use case -&amp;gt; mainly for cache locality, not beginner need)
&lt;&#x2F;span&gt;&lt;span&gt;MUTABLE s: String[10] = &amp;quot;😊&amp;quot;;     -- String (Mutable, fixed size UTF-8 buffer, more common use case, but not beginner)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;b: UInt8[*] = %[0, 10, 255];  -- Buffer (Immutable -&amp;gt; common &#x2F; default use case for non-beginners)
&lt;&#x2F;span&gt;&lt;span&gt;MUTABLE b: UInt8[] = %[0, 10];    -- Buffer (Mutable, Dynamic -&amp;gt; common use case)
&lt;&#x2F;span&gt;&lt;span&gt;b: UInt8[10] = ...;           -- Buffer (Immutable, Fixed Size -&amp;gt; you might want for cache locality)
&lt;&#x2F;span&gt;&lt;span&gt;MUTABLE b: UInt8[10] = ...;       -- Buffer (Mutable, Fixed Size -&amp;gt; common use case)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;lists-vs-streams&quot;&gt;Lists vs Streams&lt;&#x2F;h3&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;users = db.all s&amp;gt; filter; -- LIST, default
&lt;&#x2F;span&gt;&lt;span&gt;users = db.all s&amp;gt; filter s&amp;gt; COLLECT; -- LIST, default, superfluous
&lt;&#x2F;span&gt;&lt;span&gt;users = AWAIT db.all s&amp;gt; filter; -- LIST, default, superfluous
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;userCursor: Stream = db.all s&amp;gt; filter; -- STREAM, not-default due to EXPLICIT type
&lt;&#x2F;span&gt;&lt;span&gt;userCursor = db.all s&amp;gt; filter s&amp;gt; ITER; -- STREAM, not-default due to EXPLICIT ITER
&lt;&#x2F;span&gt;&lt;span&gt;userCursor = ASYNC db.all s&amp;gt; filter;   -- STREAM, not-default due to EXPLICIT ASYNC
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;streams-are-handles-not-data&quot;&gt;Streams are handles, not data&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;A stream is an &lt;em&gt;immutable&lt;&#x2F;em&gt; pointer to a &lt;em&gt;mutable&lt;&#x2F;em&gt; partition data (the stream &#x2F; flow where x is &lt;code&gt;COLLECT&lt;&#x2F;code&gt;ing).&lt;&#x2F;li&gt;
&lt;li&gt;However, you can have an &lt;em&gt;mutable&lt;&#x2F;em&gt; pointer.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Therefore:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;MUTABLE source: Stream = primary_db.users; -- OKAY
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;TRY
&lt;&#x2F;span&gt;&lt;span&gt;  source.peek(); -- Check connection
&lt;&#x2F;span&gt;&lt;span&gt;CATCH
&lt;&#x2F;span&gt;&lt;span&gt;  -- I need to reassign the variable to the backup stream!
&lt;&#x2F;span&gt;&lt;span&gt;  source = backup_db.users;
&lt;&#x2F;span&gt;&lt;span&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;source s&amp;gt; map...
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- ...
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;MUTABLE s: Stream = db.all s&amp;gt; ... ; -- OKAY
&lt;&#x2F;span&gt;&lt;span&gt;MUTABLE s: Stream(10) = db.all s&amp;gt; ... ; -- Compiler error, `... returns a single Stream, not a Vector of Streams`.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;&quot;&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;See &lt;a href=&quot;https:&#x2F;&#x2F;www.openmymind.net&#x2F;Im-Too-Dumb-For-Zigs-New-IO-Interface&#x2F;&quot;&gt;I&#x27;m too dumb to open a file in Zig&lt;&#x2F;a&gt; - for common problems of why being a genius doens&#x27;t scale - even for something as simple as reading a text file...&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>I wanted to write code that scales linearly to 128+ cores, but feels like Ruby. That didn&#x27;t exist, so I made it.</title>
        <published>2026-04-03T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-pre-release/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-pre-release/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-pre-release/">&lt;h2 id=&quot;the-goal&quot;&gt;The Goal&lt;&#x2F;h2&gt;
&lt;p&gt;I wanted the scaling of a 128-core shared-nothing engine, but the ergonomics of Ruby. I wanted to write high-level, readable logic and have a &quot;Magic Button&quot; to make it fast.&lt;&#x2F;p&gt;
&lt;p&gt;In my latest benchmarks, this approach is already &lt;strong&gt;6x faster than Go&lt;&#x2F;strong&gt; and &lt;strong&gt;1.4x faster than Rust&lt;&#x2F;strong&gt; on a 128-core KV-store workload. But the speed isn&#x27;t the story—the &lt;strong&gt;scaling&lt;&#x2F;strong&gt; is.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-problem-the-lock-tax&quot;&gt;The Problem: The &quot;Lock Tax&quot;&lt;&#x2F;h2&gt;
&lt;p&gt;I wanted to write shared-nothing code easily and correctly. Writing this kind of architecture in C or C++ is notoriously difficult. You are constantly fighting race conditions, manual memory management, and the silent performance killer: &lt;strong&gt;Cache-Line Bouncing&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In traditional concurrent languages like Go or Rust, you eventually hit a &quot;Contention Ceiling.&quot; You add more cores, but the overhead of keeping caches in sync (the &quot;Lock Tax&quot;) means you stop seeing speedups. At 64 or 128 cores, these languages often hit negative scaling—adding more hardware actually makes your app slower.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;why-not-actors&quot;&gt;Why not Actors?&lt;&#x2F;h3&gt;
&lt;p&gt;Languages like Erlang or Elixir &quot;solve&quot; this with the Actor Pattern. They isolate state by forbidding shared memory entirely. It’s a beautiful model, and it works perfectly for telecom or niche IO cases where you have millions of slow processes sending small messages.&lt;&#x2F;p&gt;
&lt;p&gt;But for high-performance systems, the Actor model just swaps one bottleneck for another: &lt;strong&gt;The Copying Tax&lt;&#x2F;strong&gt;. If you can&#x27;t share memory, you have to copy it. When you&#x27;re trying to perform 10 million operations per second on a KV store, the cost of copying keys and values between actors becomes far more expensive than the locks you were trying to avoid.&lt;&#x2F;p&gt;
&lt;p&gt;Actors are &quot;Shared-Nothing&quot; conceptually, but they are &quot;Copy-Everything&quot; in practice. I wanted &lt;strong&gt;True Shared-Nothing&lt;&#x2F;strong&gt;: Zero locks, zero contention, and zero-copy performance.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-a-library-wasn-t-enough&quot;&gt;Why a library wasn&#x27;t enough&lt;&#x2F;h2&gt;
&lt;p&gt;I didn&#x27;t want to build a new language. I knew the &quot;Ecosystem Desert&quot; is where most new languages go to die. I tried to achieve my goals by building a library for existing languages, but I hit a wall every time:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Go:&lt;&#x2F;strong&gt; You can&#x27;t escape the Garbage Collector, and the scheduler is too opaque to guarantee the thread-pinning required for true shared-nothing performance.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Rust:&lt;&#x2F;strong&gt; The type system is brilliant but rigid. To change a concurrency model, you have to refactor every function signature in the call chain. I couldn&#x27;t find a way to make optimization a &quot;one-line directive&quot; without fighting the borrow checker at every turn.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Zig:&lt;&#x2F;strong&gt; I love Zig&#x27;s performance, but even with its &lt;code&gt;comptime&lt;&#x2F;code&gt; magic, the code never felt like Ruby. It’s a &quot;Manual Transmission&quot; language; I wanted a &quot;Smart Transmission&quot; that chose the gears for me.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I wanted code to work like &lt;strong&gt;SQL&lt;&#x2F;strong&gt;. In SQL, you write a query that describes &lt;em&gt;what&lt;&#x2F;em&gt; you want, and then you add an &lt;code&gt;INDEX&lt;&#x2F;code&gt; to optimize &lt;em&gt;how&lt;&#x2F;em&gt; it&#x27;s retrieved. You don&#x27;t rewrite the whole query in C just to make it scale. I wanted that &quot;Optimization via Directive&quot; for general-purpose logic.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-breakthrough-the-zig-bridge&quot;&gt;The Breakthrough: The Zig Bridge&lt;&#x2F;h2&gt;
&lt;p&gt;I finally realized that I didn&#x27;t need to build a &quot;Walled Garden.&quot; By transpiling CLEAR to &lt;strong&gt;Zig&lt;&#x2F;strong&gt;, I got native access to the entire C standard library and the LLVM toolchain for free.&lt;&#x2F;p&gt;
&lt;p&gt;It didn&#x27;t matter if people would use my language on Day 1, because CLEAR has access to &lt;strong&gt;everything&lt;&#x2F;strong&gt; that already exists in C and Zig. I didn&#x27;t have to build a new world; I just had to build a better way to talk to the one we already have.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-result-shared-nothing-capabilities&quot;&gt;The Result: Shared-Nothing Capabilities&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR achieves its performance through &lt;strong&gt;Capabilities&lt;&#x2F;strong&gt;. Instead of bake-in a concurrency model into a Type, you apply it to a &lt;strong&gt;Binding&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;cheat&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-cheat &quot;&gt;&lt;code class=&quot;language-cheat&quot; data-lang=&quot;cheat&quot;&gt;&lt;span&gt;-- Write it like Ruby:
&lt;&#x2F;span&gt;&lt;span&gt;MUTABLE map: HashMap&amp;lt;String&amp;gt; = {};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- Optimize it with one line:
&lt;&#x2F;span&gt;&lt;span&gt;MUTABLE map: HashMap&amp;lt;String&amp;gt;@sharded(128) = {};
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;By adding &lt;code&gt;@sharded(128)&lt;&#x2F;code&gt; and &lt;code&gt;@pinned&lt;&#x2F;code&gt;, you tell the CLEAR compiler to generate a shared-nothing, lock-free architecture that scales linearly. The business logic remains identical. The compiler handles the infrastructure.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR is currently in v0.1. It’s not ready for your production database yet, but it’s ready to prove that the &quot;Iron Triangle&quot; of Performance, Scaling, and Ergonomics &lt;em&gt;can&lt;&#x2F;em&gt; be broken.&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR has not yet proved that the triangle &lt;em&gt;is&lt;&#x2F;em&gt; broken—a v0.1 release is just the beginning. But I believe these results are definitive proof that with further development, the triangle &lt;em&gt;will&lt;&#x2F;em&gt; be broken.&lt;&#x2F;p&gt;
&lt;p&gt;I’m not here to ask you to switch your stack. I’m here to show you a solution to the &quot;Many-Core&quot; problem that is only going to get harder as our hardware keeps growing.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Problem solved.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Profiling</title>
        <published>2026-04-02T00:00:00+00:00</published>
        <updated>2026-04-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/profiling/"/>
        <id>https://cuzzo.github.io/clear/docs/profiling/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/profiling/">&lt;h2 id=&quot;quick-start&quot;&gt;Quick Start&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;.&#x2F;clear&lt;&#x2F;span&gt;&lt;span&gt; profile myapp.cht
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;.&#x2F;clear&lt;&#x2F;span&gt;&lt;span&gt; doctor myapp.profile&#x2F;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;clear profile&lt;&#x2F;code&gt; builds with allocation tracking enabled (zero overhead in normal builds), runs the program, and collects:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Heap profile&lt;&#x2F;strong&gt;: allocation counts and bytes per call site&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CPU profile&lt;&#x2F;strong&gt;: &lt;code&gt;perf record&lt;&#x2F;code&gt; sampling (when available)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Syscalls&lt;&#x2F;strong&gt;: &lt;code&gt;strace -c&lt;&#x2F;code&gt; breakdown&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Hardware counters&lt;&#x2F;strong&gt;: &lt;code&gt;perf stat&lt;&#x2F;code&gt; (cycles, cache misses, branch misses)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;code&gt;clear doctor&lt;&#x2F;code&gt; reads the profile data and prints actionable optimization advice with CLEAR source line numbers.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;example-optimizing-benchmark-17-kv-store&quot;&gt;Example: Optimizing Benchmark 17 (KV Store)&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;step-1-profile&quot;&gt;Step 1: Profile&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;.&#x2F;clear&lt;&#x2F;span&gt;&lt;span&gt; profile benchmarks&#x2F;concurrent&#x2F;09_kvstore&#x2F;bench.cht
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;.&#x2F;clear&lt;&#x2F;span&gt;&lt;span&gt; doctor benchmarks&#x2F;concurrent&#x2F;09_kvstore&#x2F;bench.profile&#x2F;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;step-2-read-the-cpu-profile&quot;&gt;Step 2: Read the CPU profile&lt;&#x2F;h3&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;=== CPU Profile ===
&lt;&#x2F;span&gt;&lt;span&gt;  37.49%  hash_map.HashMapUnmanaged.getIndex    -- hashmap probing
&lt;&#x2F;span&gt;&lt;span&gt;  12.21%  pthread_rwlock_unlock                  -- RwLock release
&lt;&#x2F;span&gt;&lt;span&gt;   6.37%  memcpy                                 -- value copying
&lt;&#x2F;span&gt;&lt;span&gt;   5.29%  hash.wyhash.Wyhash.hash               -- key hashing
&lt;&#x2F;span&gt;&lt;span&gt;   4.88%  ShardedStringMap.put                   -- shard selection + lock
&lt;&#x2F;span&gt;&lt;span&gt;   2.84%  pthread_rwlock_rdlock                  -- RwLock acquire
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Observation&lt;&#x2F;strong&gt;: 15% of CPU is in &lt;code&gt;pthread_rwlock_unlock&lt;&#x2F;code&gt; + &lt;code&gt;pthread_rwlock_rdlock&lt;&#x2F;code&gt;. That&#x27;s lock overhead, not useful work.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;step-3-check-hardware-counters&quot;&gt;Step 3: Check hardware counters&lt;&#x2F;h3&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;=== Hardware Counters ===
&lt;&#x2F;span&gt;&lt;span&gt;  5,390,314,521  instructions         #  1.66 insn per cycle
&lt;&#x2F;span&gt;&lt;span&gt;     10,001,037  cache-misses         # 52.87% of all cache refs
&lt;&#x2F;span&gt;&lt;span&gt;     60,878,759  L1-dcache-load-misses  #  4.88% of all L1-dcache accesses
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Observation&lt;&#x2F;strong&gt;: 53% LLC cache miss rate. The hashmap&#x27;s random-access probing misses the cache on every other access. This is inherent to hash tables with large working sets - not fixable by resharding.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;step-4-form-a-hypothesis&quot;&gt;Step 4: Form a hypothesis&lt;&#x2F;h3&gt;
&lt;p&gt;Two bottlenecks:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Lock contention (15% CPU)&lt;&#x2F;strong&gt;: The benchmark uses &lt;code&gt;@writeLocked&lt;&#x2F;code&gt; (RwLock). RwLock has high per-operation overhead even for single-writer access. For write-heavy workloads, &lt;code&gt;@locked&lt;&#x2F;code&gt; (Mutex) should be cheaper.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Cache misses (53% LLC)&lt;&#x2F;strong&gt;: Inherent to random hash probing across 1M keys. Not fixable without changing the data structure.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;step-5-test-the-change&quot;&gt;Step 5: Test the change&lt;&#x2F;h3&gt;
&lt;p&gt;Switch from &lt;code&gt;@shared:sharded(128):writeLocked&lt;&#x2F;code&gt; to &lt;code&gt;@shared:sharded(128):locked&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Config&lt;&#x2F;th&gt;&lt;th&gt;SET&lt;&#x2F;th&gt;&lt;th&gt;GET&lt;&#x2F;th&gt;&lt;th&gt;Zipf&lt;&#x2F;th&gt;&lt;th&gt;Mixed&lt;&#x2F;th&gt;&lt;th&gt;Total&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@writeLocked&lt;&#x2F;code&gt; (before)&lt;&#x2F;td&gt;&lt;td&gt;110ms&lt;&#x2F;td&gt;&lt;td&gt;17ms&lt;&#x2F;td&gt;&lt;td&gt;18ms&lt;&#x2F;td&gt;&lt;td&gt;77ms&lt;&#x2F;td&gt;&lt;td&gt;246ms&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@locked&lt;&#x2F;code&gt; (after)&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;58ms&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;20ms&lt;&#x2F;td&gt;&lt;td&gt;24ms&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;26ms&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;198ms&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;ul&gt;
&lt;li&gt;SET: &lt;strong&gt;47% faster&lt;&#x2F;strong&gt; (Mutex has lower overhead for exclusive access)&lt;&#x2F;li&gt;
&lt;li&gt;Mixed: &lt;strong&gt;66% faster&lt;&#x2F;strong&gt; (RwLock writer starvation was killing mixed workloads)&lt;&#x2F;li&gt;
&lt;li&gt;Total: &lt;strong&gt;20% faster&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;GET&#x2F;Zipf: slightly slower (Mutex blocks concurrent readers that RwLock allows)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;step-6-compare-against-rust-and-go&quot;&gt;Step 6: Compare against Rust and Go&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;&#x2F;th&gt;&lt;th&gt;Rust (DashMap)&lt;&#x2F;th&gt;&lt;th&gt;Go (sync.RWMutex)&lt;&#x2F;th&gt;&lt;th&gt;CLEAR @locked&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;SET&lt;&#x2F;td&gt;&lt;td&gt;75ms&lt;&#x2F;td&gt;&lt;td&gt;1217ms&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;58ms&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;GET&lt;&#x2F;td&gt;&lt;td&gt;14ms&lt;&#x2F;td&gt;&lt;td&gt;529ms&lt;&#x2F;td&gt;&lt;td&gt;20ms&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Zipf&lt;&#x2F;td&gt;&lt;td&gt;13ms&lt;&#x2F;td&gt;&lt;td&gt;17ms&lt;&#x2F;td&gt;&lt;td&gt;24ms&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Mixed&lt;&#x2F;td&gt;&lt;td&gt;19ms&lt;&#x2F;td&gt;&lt;td&gt;26ms&lt;&#x2F;td&gt;&lt;td&gt;26ms&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Total&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;237ms&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;1806ms&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;198ms&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;CLEAR beats Rust (DashMap) by 17% total. SET is 22% faster than DashMap.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;what-the-profiler-told-us&quot;&gt;What the profiler told us&lt;&#x2F;h3&gt;
&lt;p&gt;The profiler didn&#x27;t just confirm &quot;it&#x27;s slow&quot; - it pointed to the specific mechanism:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;CPU profile showed 15% in rwlock functions&lt;&#x2F;li&gt;
&lt;li&gt;Hardware counters confirmed cache misses are inherent (not fixable)&lt;&#x2F;li&gt;
&lt;li&gt;This directed the fix to the lock type, not the shard count&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;We also tested reducing shards from 128 to 32 - this made things &lt;strong&gt;worse&lt;&#x2F;strong&gt; (more contention per shard), confirming that the shard count wasn&#x27;t the problem.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;how-it-works&quot;&gt;How It Works&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;heap-profiling&quot;&gt;Heap Profiling&lt;&#x2F;h3&gt;
&lt;p&gt;Built into the runtime allocator VTable. Every allocation in the runtime passes &lt;code&gt;@returnAddress()&lt;&#x2F;code&gt; (the caller&#x27;s return address). The profiler records this address, allocation count, and bytes per site in a fixed-size hash table (1024 sites, no heap allocations inside the profiler).&lt;&#x2F;p&gt;
&lt;p&gt;Key runtime helpers (&lt;code&gt;charAtCodepoint&lt;&#x2F;code&gt;, &lt;code&gt;intToString&lt;&#x2F;code&gt;, &lt;code&gt;substr&lt;&#x2F;code&gt;, &lt;code&gt;concat&lt;&#x2F;code&gt;, &lt;code&gt;join&lt;&#x2F;code&gt;) also call &lt;code&gt;profileAlloc()&lt;&#x2F;code&gt; with their own &lt;code&gt;@returnAddress()&lt;&#x2F;code&gt;, giving function-level attribution.&lt;&#x2F;p&gt;
&lt;p&gt;Controlled by a comptime flag (&lt;code&gt;CLEAR_PROFILE&lt;&#x2F;code&gt;). When not set, all profiling code is eliminated at compile time - zero overhead in production.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;cpu-profiling&quot;&gt;CPU Profiling&lt;&#x2F;h3&gt;
&lt;p&gt;Uses Linux &lt;code&gt;perf record&lt;&#x2F;code&gt; for sampling-based CPU profiling. Requires &lt;code&gt;perf_event_paranoid &amp;lt;= 2&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span&gt; sysctl kernel.perf_event_paranoid=2  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# temporary, resets on reboot
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;source-mapping&quot;&gt;Source Mapping&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;clear doctor&lt;&#x2F;code&gt; maps addresses back to CLEAR source lines using:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;addr2line&lt;&#x2F;code&gt; to resolve addresses to Zig file:line&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;&#x2F;&#x2F; CLR:N&lt;&#x2F;code&gt; comments in the transpiled Zig to map back to CLEAR line numbers&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Profile builds use &lt;code&gt;-fno-strip&lt;&#x2F;code&gt; to retain debug symbols.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;environment-variables&quot;&gt;Environment Variables&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Variable&lt;&#x2F;th&gt;&lt;th&gt;Set by&lt;&#x2F;th&gt;&lt;th&gt;Purpose&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;CLEAR_ALLOC_PROFILE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;clear profile&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Output path for allocation data&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;CLEAR_THREADS&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;User&lt;&#x2F;td&gt;&lt;td&gt;Number of scheduler threads&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Architecture</title>
        <published>2026-03-31T00:00:00+00:00</published>
        <updated>2026-05-11T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/architecture/"/>
        <id>https://cuzzo.github.io/clear/docs/architecture/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/architecture/">&lt;p&gt;&lt;strong&gt;1. Arena-Based Memory &amp;amp; Isolation&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;CLEAR leverages affine types and Arena-based memory to give you near High-Frequency Trading standards of allocation with zero thought.&lt;&#x2F;li&gt;
&lt;li&gt;Due to optimizing broadly for a fiber-runtime, there are cases when the stack could be better leveraged, but CLEAR chooses not to for large stack objects (to keep fiber stacks small, until most fibers are transformed seamlessly into Finite State Machines by v0.4).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;2. Deterministic Shared-Memory and a Declarative Concurrency Model&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Parallelism is achieved via &lt;code&gt;BG&#x2F;DO&#x2F;CONCURRENT&lt;&#x2F;code&gt;, which creates isolated execution contexts.
&lt;ul&gt;
&lt;li&gt;Rather than telling the code &lt;em&gt;how&lt;&#x2F;em&gt; to achieve fast speeds, you simply tell write the code that expresses your intent - the &lt;em&gt;what&lt;&#x2F;em&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;CLEAR provides one-line capability optimizations. Changing your app from an Arc&#x2F;RwLock strategy suffering from synchronization bottle-necks to a shared-nothing architecture which can compete with Dragonfly DB can be a one-line change.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Spawning a process creates a lightweight, isolated fiber &#x2F; memory arena (or Finite State Machine in the near future).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;3. Implicit &quot;Railway&quot; Error Handling&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;CLEAR treats errors as data, but handles them via control flow.&lt;&#x2F;li&gt;
&lt;li&gt;The &lt;code&gt;SMOOTH&lt;&#x2F;code&gt; operator &lt;code&gt;|&amp;gt;&lt;&#x2F;code&gt; (aka the &lt;code&gt;PIPE&lt;&#x2F;code&gt; or &lt;code&gt;|&amp;gt; &lt;&#x2F;code&gt; in Elixir, etc) acts as a guard.
&lt;ul&gt;
&lt;li&gt;It automatically bubbles errors down the chain, to be handled elsewhere, or allows them to be handled inline elegantly.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;This ensures code reads top-to-bottom &amp;amp; is left-sided (the &quot;Happy Path&quot;) -- making it always clear what&#x27;s desired vs what&#x27;s the fallback.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;The Result:&lt;&#x2F;em&gt; No if err != nil boilerplate. No Pyramid of Doom. No checkOk clutter. No &lt;code&gt;if .nil?&lt;&#x2F;code&gt; everywhere.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;4. A Type system that &lt;em&gt;just works&lt;&#x2F;em&gt;&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;CLEAR is easy to write for beginners. The Type system is implicit, staying out-of-the-way by powerful Type inference.&lt;&#x2F;li&gt;
&lt;li&gt;The compiler takes care of the confusing parts of the type system for you.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;The Result:&lt;&#x2F;em&gt; If you can write code in JavaScript, Lua, Python, or Ruby - you can write blazing fast CLEAR code.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;5. Fortress Architecture&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;All &lt;code&gt;PUBLIC&lt;&#x2F;code&gt; functions must return a single type with a suitable default - or explicitly error&lt;&#x2F;li&gt;
&lt;li&gt;All &lt;code&gt;PUBLIC&lt;&#x2F;code&gt; structs must have a suitable default - or explicitly an error
&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;PUBLIC&lt;&#x2F;code&gt; function obviously cannot take a non-&lt;code&gt;PUBLIC&lt;&#x2F;code&gt; struct as an input.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;The Result:&lt;&#x2F;em&gt; Guarantees that only &lt;em&gt;YOUR&lt;&#x2F;em&gt; code can cause run-time errors (or none if in &lt;code&gt;STRICT&lt;&#x2F;code&gt; mode).
&lt;ul&gt;
&lt;li&gt;You can auto-gen tests for PUBLIC functions for all permutations of POSSIBLE unexpected inputs.
&lt;ul&gt;
&lt;li&gt;This allows you to spot problems easily and arrive at robust, working code quickly.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>CLEAR for Scripters</title>
        <published>2026-03-31T00:00:00+00:00</published>
        <updated>2026-05-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/clear-for-scripters/"/>
        <id>https://cuzzo.github.io/clear/docs/clear-for-scripters/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/clear-for-scripters/">&lt;p&gt;If you already know Logic (JavaScript&#x2F;Python), the only thing stopping you from writing System-Level code is Memory.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;In Ruby&#x2F;Python&#x2F;JavaScript, Memory is &quot;Magic.&quot;&lt;&#x2F;li&gt;
&lt;li&gt;In C, it&#x27;s an incomprehensible arcana.&lt;&#x2F;li&gt;
&lt;li&gt;In CLEAR, Memory is &quot;Physics.&quot;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Here are the 9 Rules of Physics in CLEAR.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;1-physics-of-change-mutable-vs-immutable-default&quot;&gt;1. Physics of change: &lt;code&gt;MUTABLE&lt;&#x2F;code&gt; vs &lt;code&gt;IMMUTABLE&lt;&#x2F;code&gt; (Default)&lt;&#x2F;h3&gt;
&lt;p&gt;In Ruby or Python, you can change the value of any variable by default (they behave as &lt;code&gt;MUTABLE&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Bob&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In CLEAR, binding a name for the first time creates an &lt;strong&gt;immutable&lt;&#x2F;strong&gt; variable. Reassigning it is a compiler error.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Bob&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;             &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR! `name` is immutable.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;x = value&lt;&#x2F;code&gt; = &lt;strong&gt;READ&lt;&#x2F;strong&gt; Only (immutable, no keyword needed).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;MUTABLE x = value&lt;&#x2F;code&gt; = &lt;strong&gt;READ&#x2F;WRITE&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;The &quot;Gotcha&quot;:&lt;&#x2F;strong&gt; If you want to modify a variable, it must be &lt;code&gt;MUTABLE&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span&gt;name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Bob&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;             &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OK
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;2-physics-of-shape-types&quot;&gt;2. Physics of SHAPE: TYPES&lt;&#x2F;h3&gt;
&lt;p&gt;In CLEAR, variables have types to ensure safety and speed.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span&gt;name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Bob&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;                   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: `name` is a String, cannot assign a Float64.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;3-physics-of-size-fixed-vs-dynamic&quot;&gt;3. Physics of Size: FIXED vs. DYNAMIC&lt;&#x2F;h3&gt;
&lt;p&gt;In CLEAR, you choose the physics you need.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;FIXED&lt;&#x2F;strong&gt; Size: Optimized for speed and cache locality.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;DYNAMIC&lt;&#x2F;strong&gt; Size: Grows indefinitely, but requires the Warehouse (HEAP).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;4-the-two-worlds-stack-vs-heap&quot;&gt;4. The Two Worlds: STACK vs. HEAP&lt;&#x2F;h3&gt;
&lt;h4 id=&quot;the-stack-default&quot;&gt;The STACK (Default)&lt;&#x2F;h4&gt;
&lt;p&gt;Think of this as your &lt;strong&gt;Backpack&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Pros: Instant access (L1 Cache). &lt;em&gt;Blazing&lt;&#x2F;em&gt; fast.&lt;&#x2F;li&gt;
&lt;li&gt;Cons: Itty-bitty space. Fixed size.&lt;&#x2F;li&gt;
&lt;li&gt;Behavior: When you finish a task (Function returns), you dump your backpack into the incinerator. Everything inside is gone. &lt;em&gt;POOF&lt;&#x2F;em&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;the-heap&quot;&gt;The HEAP&lt;&#x2F;h4&gt;
&lt;p&gt;Think of this as a &lt;strong&gt;Warehouse&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Pros: (nearly) Unlimited space. Can grow&#x2F;shrink.&lt;&#x2F;li&gt;
&lt;li&gt;Cons: You have to drive there to get stuff (Slower).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;how-to-choose&quot;&gt;How to Choose&lt;&#x2F;h4&gt;
&lt;p&gt;In CLEAR, the compiler and runtime handle the physics of where data lives for you in 99% of cases. You don&#x27;t need to use a sigil to choose between stack and heap.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;x = [1, 2]&lt;&#x2F;code&gt; → CLEAR decides the most efficient location.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;list = [1, 2, 3]&lt;&#x2F;code&gt; → This list is optimized for performance and safety.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If you need to explicitly force an object onto the heap (e.g., for recursive structures or large buffers), you can use the &lt;code&gt;indirect&lt;&#x2F;code&gt; capability (similar to &lt;code&gt;Box&lt;&#x2F;code&gt; in Rust).&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Recursive structures use &amp;#39;indirect&amp;#39; to avoid infinite size on stack
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Node &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;left: &lt;&#x2F;span&gt;&lt;span&gt;?Node &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@indirect&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;left: &lt;&#x2F;span&gt;&lt;span&gt;?Node &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@indirect
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The &quot;Gotcha&quot;: If you try to &lt;code&gt;.push!&lt;&#x2F;code&gt; or &lt;code&gt;.pop!&lt;&#x2F;code&gt; to a fixed-size array, the compiler will yell at you. It’s not being mean; it’s telling you that physics forbids it.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;x = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# ... do something, now I need to add to `x`, what do I do?
&lt;&#x2F;span&gt;&lt;span&gt;x.append!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;);                  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR! `x` is immutable.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;5-physics-of-capability-capabilities-vs-types&quot;&gt;5. Physics of Capability: Capabilities vs Types&lt;&#x2F;h3&gt;
&lt;p&gt;In CLEAR, we separate &lt;strong&gt;Types&lt;&#x2F;strong&gt; from &lt;strong&gt;Capabilities&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Types&lt;&#x2F;strong&gt; describe &lt;em&gt;what&lt;&#x2F;em&gt; the data is (e.g., &lt;code&gt;User&lt;&#x2F;code&gt;, &lt;code&gt;Account&lt;&#x2F;code&gt;).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Capabilities&lt;&#x2F;strong&gt; describe &lt;em&gt;how&lt;&#x2F;em&gt; you access it (e.g., &lt;code&gt;shared&lt;&#x2F;code&gt;, &lt;code&gt;multiowned&lt;&#x2F;code&gt;, &lt;code&gt;alwaysMutable&lt;&#x2F;code&gt;).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;The Rule:&lt;&#x2F;strong&gt; Functions take &lt;strong&gt;Types&lt;&#x2F;strong&gt;, not &lt;strong&gt;Capabilities&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;the-clear-model&quot;&gt;The CLEAR Model&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Ownership:&lt;&#x2F;strong&gt; Rc = &lt;code&gt;multiowned&lt;&#x2F;code&gt;, Arc = &lt;code&gt;shared&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Synchronization:&lt;&#x2F;strong&gt; RwLock = &lt;code&gt;shared:writeLocked&lt;&#x2F;code&gt;, Mutex = &lt;code&gt;shared:locked&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;coming soon&lt;&#x2F;strong&gt; -&amp;gt; Mvcc = &lt;code&gt;shared:versioned&lt;&#x2F;code&gt;, &lt;code&gt;:actor&lt;&#x2F;code&gt; uses Object Actor Pattern combined with compiler aware SHARDING&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Interior Mutability:&lt;&#x2F;strong&gt; Cell, RefCell -&amp;gt; combined = &lt;code&gt;alwaysMutable&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;Automatically acts like Cell for data under 16 bytes&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;alwaysMutable&lt;&#x2F;code&gt; must be unwrapped before individually passing into a function as an argument, like any other capability&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Existence:&lt;&#x2F;strong&gt; Option, Result =&amp;gt; not a capability -&amp;gt; a tense:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;T?&lt;&#x2F;code&gt; = Optional &lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Unwrapped like in Rust and Zig with &lt;code&gt;.?&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Future:&lt;&#x2F;strong&gt;: Something that will arrive later
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;~T&lt;&#x2F;code&gt; = Future &lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;~T[]&lt;&#x2F;code&gt; = Future &lt;code&gt;T&lt;&#x2F;code&gt;s (like a Stream).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;affUser = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;.new();         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# creates `affine User` (default)
&lt;&#x2F;span&gt;&lt;span&gt;a = affUser;                  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY, affine MOVE, affUser is dead
&lt;&#x2F;span&gt;&lt;span&gt;b = affUser;                  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Compiler error, affUser is dead
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;sharedU = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SHARE&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;.new());  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# turns `affine User` into `shared User` (Arc)
&lt;&#x2F;span&gt;&lt;span&gt;c = sharedU;                  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY, sharedU is not dead
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h4 id=&quot;why-it-s-superior-zero-blast-radius-refactoring&quot;&gt;Why it&#x27;s superior: Zero Blast Radius Refactoring&lt;&#x2F;h4&gt;
&lt;p&gt;In Rust, capabilities like &lt;code&gt;Arc&lt;&#x2F;code&gt;, &lt;code&gt;Rc&lt;&#x2F;code&gt;, and &lt;code&gt;Mutex&lt;&#x2F;code&gt; infect function signatures. Changing from &lt;code&gt;Rc&amp;lt;User&amp;gt;&lt;&#x2F;code&gt; to &lt;code&gt;Arc&amp;lt;User&amp;gt;&lt;&#x2F;code&gt; forces a massive refactor because every function signature and call site must change.&lt;&#x2F;p&gt;
&lt;p&gt;In CLEAR, if you need thread-safety, you change &lt;strong&gt;one line&lt;&#x2F;strong&gt; at the definition site:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Change multiowned (Rc) to shared (Arc)
&lt;&#x2F;span&gt;&lt;span&gt;sharedU = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SHARE&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;.new());
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Your functions (which just take &lt;code&gt;User&lt;&#x2F;code&gt;) never knew about the capability, so they don&#x27;t need to change.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;synchronization-strategies&quot;&gt;Synchronization Strategies&lt;&#x2F;h4&gt;
&lt;p&gt;For multi-threaded &lt;code&gt;shared&lt;&#x2F;code&gt; objects, you choose the strategy:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;shared:read&lt;&#x2F;code&gt;: (MVCC) Optimized for massive read scaling.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;shared:writeLocked&lt;&#x2F;code&gt;: (&lt;code&gt;RwLock&amp;lt;Arc&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt;) Multiple readers OR one writer.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;shared:locked&lt;&#x2F;code&gt;: (&lt;code&gt;Mutex&amp;lt;Arc&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt;) One thread at a time.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;interior-mutability&quot;&gt;Interior Mutability&lt;&#x2F;h4&gt;
&lt;p&gt;For complex data, use &lt;code&gt;alwaysMutable&lt;&#x2F;code&gt; (&lt;code&gt;RefCell&lt;&#x2F;code&gt;). CLEAR handles the lock for you:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 99% Case: Compiler handles temporary lock
&lt;&#x2F;span&gt;&lt;span&gt;user.login_count += &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 1% Case: Scoped mutation
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; user.config {
&lt;&#x2F;span&gt;&lt;span&gt;  _.theme = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Light&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  _.retries = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;6-physics-of-sight-scopes&quot;&gt;6. Physics of Sight (SCOPES)&lt;&#x2F;h3&gt;
&lt;p&gt;Functions can ONLY see what is explicitly passed into them:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;x = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; add() -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; x + &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;;                 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: I don&amp;#39;t know what &amp;#39;x&amp;#39; is.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Use &lt;code&gt;USE&lt;&#x2F;code&gt; for upvalues:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;x = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; add(n) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;USE &lt;&#x2F;span&gt;&lt;span&gt;(x) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; n + x;                 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OK
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;7-physics-of-time-the-arena-lifetimes&quot;&gt;7. Physics of Time: The ARENA (Lifetimes)&lt;&#x2F;h3&gt;
&lt;p&gt;Variable lifetimes follow a simple birth&#x2F;death cycle: they live as long as the Function they were born in.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;the-arena-rule&quot;&gt;The ARENA Rule:&lt;&#x2F;h4&gt;
&lt;p&gt;When a function starts, it opens a clean ARENA (A bank of memory). Any variable you create lives in this ARENA. When the function ends, the entire ARENA is wiped. &lt;em&gt;POOF&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;9-cheating-death-the-takes-keyword&quot;&gt;9. Cheating Death: The &lt;code&gt;TAKES&lt;&#x2F;code&gt; Keyword&lt;&#x2F;h3&gt;
&lt;p&gt;In 99% of cases, when you pass a variable to a function, you are just letting that function &lt;strong&gt;Borrow&lt;&#x2F;strong&gt; it. If a function needs to store that object in a long-lived structure (like a Tree or Global List), it must explicitly &lt;strong&gt;TAKE&lt;&#x2F;strong&gt; responsibility for it.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# This function promises to adopt the &amp;#39;child&amp;#39;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; addChild!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;parent: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Node&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TAKES &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;child: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Node&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  parent.list.push!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;GIVE&lt;&#x2F;span&gt;&lt;span&gt; child);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;node = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Node&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;val: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;addChild!(root, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;GIVE&lt;&#x2F;span&gt;&lt;span&gt; node);   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# I surrender ownership.
&lt;&#x2F;span&gt;&lt;span&gt;node.print();                 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: Variable &amp;#39;node&amp;#39; is dead.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;10-simplified-lifetimes-with-restrict&quot;&gt;10. Simplified Lifetimes: &lt;code&gt;WITH RESTRICT&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust&#x27;s borrow checker is hard because its side effects are non-local and implicit. In CLEAR, borrows that &quot;poison&quot; (restrict) a mutable variable are explicitly scoped using &lt;code&gt;WITH RESTRICT&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUT&lt;&#x2F;span&gt;&lt;span&gt; node = buildTree();
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH RESTRICT&lt;&#x2F;span&gt;&lt;span&gt; node.child {
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Inside this block, node.child is immutable (restricted).
&lt;&#x2F;span&gt;&lt;span&gt;  gc = node.grandChild();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  node.child.name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;OK&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: node.child is RESTRICTed.
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Outside the block, node.child is mutable again.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Path-Based Scoping:&lt;&#x2F;strong&gt; CLEAR allows you to restrict only the specific part of a data structure you are using (e.g., &lt;code&gt;node.child&lt;&#x2F;code&gt;), leaving the rest of the object mutable. This minimizes &quot;poison&quot; and makes complex architectures easier to reason about.&lt;&#x2F;p&gt;
&lt;p&gt;This ensures that &quot;poisoning&quot; is always visible and local.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>OPINIONS</title>
        <published>2026-03-31T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-opinions/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-opinions/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-opinions/">&lt;ol&gt;
&lt;li&gt;Boiler Plate is bad.&lt;&#x2F;li&gt;
&lt;li&gt;Understandable code is king.
&lt;ul&gt;
&lt;li&gt;The easier it is to &lt;em&gt;UNDERSTAND&lt;&#x2F;em&gt; code, the more likely it is to arrive at a correct state.&lt;&#x2F;li&gt;
&lt;li&gt;Understanding what a function is &lt;em&gt;supposed&lt;&#x2F;em&gt; to do should not be bogged down by it&#x27;s error handling logic.
&lt;ul&gt;
&lt;li&gt;Like test code, error handling code should be separate as much as possible.&lt;&#x2F;li&gt;
&lt;li&gt;Read it as an addendum IFF you care.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Implicit behavior &#x2F; magic &lt;em&gt;can&lt;&#x2F;em&gt; make things &lt;em&gt;harder&lt;&#x2F;em&gt; to understand.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;You should be able to test anything, and it should be EASY.
&lt;ul&gt;
&lt;li&gt;There should be ZERO test code in production code.
&lt;ul&gt;
&lt;li&gt;Java @visibleForTesting is nice, but it shouldn&#x27;t be necessary at all.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;The easier it is to write tests, the more likely you are to actually arrive at working code.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Handling Errors should &quot;just work&quot;.
&lt;ul&gt;
&lt;li&gt;You should not always have to &lt;code&gt;checkOk&lt;&#x2F;code&gt;.
&lt;ul&gt;
&lt;li&gt;We can &lt;em&gt;assume&lt;&#x2F;em&gt; okay, and look to the bottom to see what happens when not okay, if we ever care.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;The easier it is to handle errors, the more likely you are to handle them correctly!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;If your code compiles in &lt;code&gt;STRICT&lt;&#x2F;code&gt; mode, it will not produce a Run-time Error unless the system explicitly encounters a resource boundary, or the program executes an operation whose inputs are logically impossible to resolve correctly.
&lt;ul&gt;
&lt;li&gt;TODO: Investigate Type Coercion Failure claims.
&lt;ul&gt;
&lt;li&gt;Currently not implemented, but on the roadmap.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;TODO: Investigate claims of all errors being handled &lt;em&gt;somewhere&lt;&#x2F;em&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Compiler errors should tell you &lt;em&gt;exactly&lt;&#x2F;em&gt; what&#x27;s wrong, how to fix it, and be easy to understand.&lt;&#x2F;li&gt;
&lt;li&gt;Types should be your friend, helping you write working code &lt;em&gt;faster&lt;&#x2F;em&gt;, not an enemy that is constantly slowing you down.&lt;&#x2F;li&gt;
&lt;li&gt;90% of your time should be spent writing the code you need, and 10% debugging, handling errors, fighting compilers - not the other way around.&lt;&#x2F;li&gt;
&lt;li&gt;Writing efficient code should be the default, and the default should be easy.
&lt;ul&gt;
&lt;li&gt;Writing ineffiecent code should be &lt;em&gt;obviously&lt;&#x2F;em&gt; wrong.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Anything that &lt;em&gt;can&lt;&#x2F;em&gt; be 1-line &lt;em&gt;should&lt;&#x2F;em&gt; be!
&lt;ul&gt;
&lt;li&gt;Readability and understandability beat cleverness -- unless direly critical to performance.&lt;&#x2F;li&gt;
&lt;li&gt;The constructs and syntax of a language should lend itself to one-liners, as they are often easier to &lt;em&gt;UNDERSTAND&lt;&#x2F;em&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Code should be as declaractive as possible.
&lt;ul&gt;
&lt;li&gt;Every function should look like a clean chain of exactly what it &lt;em&gt;should&lt;&#x2F;em&gt; be doing.
&lt;ul&gt;
&lt;li&gt;It should not look like a nested mess of &lt;em&gt;how&lt;&#x2F;em&gt; it&#x27;s handling errors and undesirable states.
&lt;ul&gt;
&lt;li&gt;Though it &lt;em&gt;MUST&lt;&#x2F;em&gt; have the capability to do that.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;You should not need to worry about memory management OR a garbage collector.
&lt;ul&gt;
&lt;li&gt;Unless you&#x27;re a rocket scientist, the right compiler can figure it out better than you can.&lt;&#x2F;li&gt;
&lt;li&gt;A good SQL engine beats all but the absolute most elite programmers.&lt;&#x2F;li&gt;
&lt;li&gt;A good compiler can also take an easy language and beat all but the most elite programmers (see LuaJIT).&lt;&#x2F;li&gt;
&lt;li&gt;CLEAR &lt;em&gt;does&lt;&#x2F;em&gt; ask you think about &lt;em&gt;WHERE&lt;&#x2F;em&gt; an object lives.
&lt;ul&gt;
&lt;li&gt;Cache locality is literally 100x faster. If you wrote something cache-locality optimized in Ruby, it would crush a pointer cache miss in C.&lt;&#x2F;li&gt;
&lt;li&gt;Therefore, CLEAR is designed around making it as easy as possible to ensure you DON&#x27;T cache miss unless you absolutely must.
&lt;ul&gt;
&lt;li&gt;This means you do need to think about if you want something on the STACK (default, fast) or the HEAP (slow, but sometimes required).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;You should not need to worry about a Global-Interpreter-Lock (GIL).
&lt;ul&gt;
&lt;li&gt;Code &lt;em&gt;should&lt;&#x2F;em&gt; be able to run in parallel or concurrently &lt;em&gt;EFFICIENTLY&lt;&#x2F;em&gt; by default.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Code should be as left-sided as possible.
&lt;ul&gt;
&lt;li&gt;How many hours have &lt;em&gt;YOU&lt;&#x2F;em&gt; spent tracking down paren-syntax errors, figuring out which condition you&#x27;re in, etc???&lt;&#x2F;li&gt;
&lt;li&gt;Time spent figuring out &lt;em&gt;WHERE&lt;&#x2F;em&gt; you even are logically, is time wasted, that could be spent getting things done.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Someone who doesn&#x27;t know &lt;em&gt;CLEAR&lt;&#x2F;em&gt; should be able to look at &lt;em&gt;CLEAR&lt;&#x2F;em&gt; code and intuit what it does.&lt;&#x2F;li&gt;
&lt;li&gt;Publicly-Exported APIs &lt;em&gt;SHOULD&lt;&#x2F;em&gt; have style-enforcements.
&lt;ul&gt;
&lt;li&gt;At a minimum, if you&#x27;re making a library, anyone should be able to understand the API.&lt;&#x2F;li&gt;
&lt;li&gt;All &lt;code&gt;PUBLIC&lt;&#x2F;code&gt; functions &lt;em&gt;MUST&lt;&#x2F;em&gt; either &lt;em&gt;explicitly&lt;&#x2F;em&gt; &lt;code&gt;RAISE&lt;&#x2F;code&gt; an error OR handle all errors.
&lt;ul&gt;
&lt;li&gt;All &lt;code&gt;PUBLIC&lt;&#x2F;code&gt; structs &lt;em&gt;MUST&lt;&#x2F;em&gt; either have a suitable default or &lt;code&gt;!!&lt;&#x2F;code&gt; suffix.
&lt;ul&gt;
&lt;li&gt;All &lt;code&gt;PUBLIC&lt;&#x2F;code&gt; Union Types &lt;em&gt;MUST&lt;&#x2F;em&gt; be projectable for ease of use.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Internal-code can be &lt;em&gt;Chill&lt;&#x2F;em&gt;-Correct.
&lt;ul&gt;
&lt;li&gt;No interpretting errors because you have an unnused variable.&lt;&#x2F;li&gt;
&lt;li&gt;No forbidding your code to run for a test because you didn&#x27;t follow a covention, etc.&lt;&#x2F;li&gt;
&lt;li&gt;Your code can fail because of &lt;code&gt;your&lt;&#x2F;code&gt; problems, but not becuase of your dependencies problems.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;STRICT&lt;&#x2F;code&gt; mode compilation eliminates &lt;em&gt;Chill&lt;&#x2F;em&gt;-Correct and can guarantee you won&#x27;t encounter virtually all preventable run-time errors.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>WHO IS CLEAR *NOT* FOR</title>
        <published>2026-03-31T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-who-not/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-who-not/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-who-not/">&lt;p&gt;CLEAR is opinionated. The specific optimizations that make it fast and safe for 99% of Business Logic make it extremely hostile to 1% of Architectural patterns.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;You are building a Pointer-Heavy Engine (like a Graph Database).&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;ul&gt;
&lt;li&gt;CLEAR prevents Memory Leaks by forbidding reference cycles in &lt;code&gt;shared&lt;&#x2F;code&gt; objects (Shared A -&amp;gt; B, B -&amp;gt; A).&lt;&#x2F;li&gt;
&lt;li&gt;If your architecture relies on a &quot;Soup of Mutable Objects&quot; where everything references everything else, CLEAR will fight you.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;The Alternative:&lt;&#x2F;em&gt; Architect your data using IDs and centralized lookups (like a relational database), or use Rust&#x2F;C++ for manual pointer management.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;You need to model Inherently Unsafe &#x2F; Cyclic Relationships&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;ul&gt;
&lt;li&gt;If your architecture relies on Rust-style &quot;Weak Pointers&quot; to manage reference cycles (A -&amp;gt; B -&amp;gt; A)
&lt;ul&gt;
&lt;li&gt;OR if you need recursive fine-grained locking, and you are strictly managing memory and deadlock risks manually.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;CLEAR guarantees safety by forbidding these patterns entirely! They&#x27;re rare!&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;The Alternative:&lt;&#x2F;em&gt; If you absolutely need a doubly-linked list or a cyclic graph with individual node locking, that is &quot;Engine Code,&quot; not &quot;Business Logic.&quot; Write that specific component in Zig (where you can manage the unsafe pointers yourself) and import it into CLEAR as a safe handle.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Modules &amp; Build System</title>
        <published>2026-03-31T00:00:00+00:00</published>
        <updated>2026-05-06T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/modules/"/>
        <id>https://cuzzo.github.io/clear/docs/modules/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/modules/">&lt;p&gt;CLEAR uses a simple, explicit module system based on the &lt;code&gt;REQUIRE&lt;&#x2F;code&gt; keyword. It separates code into &lt;strong&gt;Files&lt;&#x2F;strong&gt;, &lt;strong&gt;Packages&lt;&#x2F;strong&gt;, and &lt;strong&gt;Native Modules&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;require-importing-code&quot;&gt;REQUIRE — Importing Code&lt;&#x2F;h2&gt;
&lt;p&gt;Importing a CLEAR module makes its &lt;code&gt;PUB&lt;&#x2F;code&gt; and package-private symbols available under a namespace.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;local-file-imports&quot;&gt;Local File Imports&lt;&#x2F;h3&gt;
&lt;p&gt;Use a relative path string to import files in your own project:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REQUIRE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;math_utils.cht&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    res = math_utils.add(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;package-imports&quot;&gt;Package Imports&lt;&#x2F;h3&gt;
&lt;p&gt;Use the &lt;code&gt;pkg:&lt;&#x2F;code&gt; prefix to import registered libraries:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REQUIRE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;pkg:geometry&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    p = geometry.Point{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2 &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;aliasing-as&quot;&gt;Aliasing (AS)&lt;&#x2F;h3&gt;
&lt;p&gt;You can rename any import to avoid collisions:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REQUIRE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;math_utils.cht&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; m;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REQUIRE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;pkg:geometry&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; geo;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    sq = m.square(geo.distance(p1, p2));
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;visibility&quot;&gt;Visibility&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR enforces three levels of visibility. Access control is checked at compile-time by the semantic annotator.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Keyword&lt;&#x2F;th&gt;&lt;th&gt;Level&lt;&#x2F;th&gt;&lt;th&gt;Visibility&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;PRIVATE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;File Private&lt;&#x2F;td&gt;&lt;td&gt;Only accessible within the &lt;code&gt;.cht&lt;&#x2F;code&gt; file where it is defined.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;em&gt;(None)&lt;&#x2F;em&gt;&lt;&#x2F;td&gt;&lt;td&gt;Package Private&lt;&#x2F;td&gt;&lt;td&gt;Accessible to any file in the &lt;strong&gt;same directory&lt;&#x2F;strong&gt;.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;PUB&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Public&lt;&#x2F;td&gt;&lt;td&gt;Accessible to any file that &lt;code&gt;REQUIRE&lt;&#x2F;code&gt;s this module or package.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;example&quot;&gt;Example&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# internal_helper.cht
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;PRIVATE FN&lt;&#x2F;span&gt;&lt;span&gt; secret_calc() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Int64 &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; ... &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; package_helper() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Int64 &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; secret_calc();  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OK: same file
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;PUB FN&lt;&#x2F;span&gt;&lt;span&gt; public_api() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Int64 &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; package_helper(); &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OK: same package
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# main.cht
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REQUIRE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;internal_helper.cht&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    internal_helper.public_api();     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OK: PUB
&lt;&#x2F;span&gt;&lt;span&gt;    internal_helper.package_helper();  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OK: same directory
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# internal_helper.secret_calc();  -- ERROR: PRIVATE
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;future-strict-mode&quot;&gt;Future: STRICT Mode&lt;&#x2F;h3&gt;
&lt;p&gt;In future versions (v0.2+), &lt;code&gt;PUB&lt;&#x2F;code&gt; declarations at a package boundary will require &lt;strong&gt;explicit effect declarations&lt;&#x2F;strong&gt; (e.g., &lt;code&gt;EFFECTS :alloc&lt;&#x2F;code&gt;) when compiled in &lt;code&gt;STRICT&lt;&#x2F;code&gt; mode. This ensures that library side-effects are always documented and verified.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;build-system&quot;&gt;Build System&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR features a built-in dependency manager that handles recursive &lt;code&gt;REQUIRE&lt;&#x2F;code&gt; calls, prevents circular dependencies, and manages the transpilation graph.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;package-registration&quot;&gt;Package Registration&lt;&#x2F;h3&gt;
&lt;p&gt;Packages are mapped to file paths at compile-time using the &lt;code&gt;--pkg&lt;&#x2F;code&gt; flag:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ruby&lt;&#x2F;span&gt;&lt;span&gt; src&#x2F;transpiler.rb&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --pkg&lt;&#x2F;span&gt;&lt;span&gt; geometry=.&#x2F;libs&#x2F;geometry&#x2F;lib.cht main.cht &amp;gt; main.zig
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;module-transpilation&quot;&gt;Module Transpilation&lt;&#x2F;h3&gt;
&lt;p&gt;To compile a library as a standalone Zig module (without the CLEAR runtime footer), use the &lt;code&gt;--module&lt;&#x2F;code&gt; flag. This is useful when building CLEAR code to be consumed by native Zig applications.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ruby&lt;&#x2F;span&gt;&lt;span&gt; src&#x2F;transpiler.rb&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt; --module&lt;&#x2F;span&gt;&lt;span&gt; my_lib.cht &amp;gt; my_lib.zig
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;how-it-works&quot;&gt;How it Works&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Local Imports&lt;&#x2F;strong&gt;: The transpiler inlines the generated Zig code of the local file into a &lt;code&gt;const struct&lt;&#x2F;code&gt; namespace in the caller&#x27;s Zig file.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Package Imports&lt;&#x2F;strong&gt;: The transpiler emits a Zig &lt;code&gt;@import(&quot;namespace&quot;)&lt;&#x2F;code&gt;. The actual wiring of these modules is handled by the Zig build system using the &lt;code&gt;--dep&lt;&#x2F;code&gt; and &lt;code&gt;-M&lt;&#x2F;code&gt; flags.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Deduplication&lt;&#x2F;strong&gt;: Each file is parsed and annotated exactly once, even if required by multiple files.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;project-structure-recommended&quot;&gt;Project Structure (Recommended)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;text&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-text &quot;&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;&lt;span&gt;my_project&#x2F;
&lt;&#x2F;span&gt;&lt;span&gt;├── main.cht            # Entry point
&lt;&#x2F;span&gt;&lt;span&gt;├── logic.cht           # Local module
&lt;&#x2F;span&gt;&lt;span&gt;└── lib&#x2F;
&lt;&#x2F;span&gt;&lt;span&gt;    └── math&#x2F;
&lt;&#x2F;span&gt;&lt;span&gt;        ├── lib.cht     # Package entry point (exports PUB symbols)
&lt;&#x2F;span&gt;&lt;span&gt;        └── private.cht  # Internal logic (default visibility)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>CLEAR Language Walkthrough</title>
        <published>2026-03-31T00:00:00+00:00</published>
        <updated>2026-05-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/walkthrough/"/>
        <id>https://cuzzo.github.io/clear/docs/walkthrough/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/walkthrough/">&lt;p&gt;This guide showcases CLEAR: a memory-safe language that combines the ergonomics of scripting with the safety of affine types and the performance of hand-optimized C.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;1-immutability-mutability&quot;&gt;1. Immutability &amp;amp; Mutability&lt;&#x2F;h2&gt;
&lt;p&gt;Bindings are immutable by default. Reassignment requires the &lt;code&gt;MUTABLE&lt;&#x2F;code&gt; keyword.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;x = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;;                        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Immutable binding (default)
&lt;&#x2F;span&gt;&lt;span&gt;name = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;               &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Immutable string
&lt;&#x2F;span&gt;&lt;span&gt;pi = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3.14159&lt;&#x2F;span&gt;&lt;span&gt;;                 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Immutable float
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;x = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;6&lt;&#x2F;span&gt;&lt;span&gt;;                        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: x is immutable
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; counter = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;          &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Explicit mutability
&lt;&#x2F;span&gt;&lt;span&gt;counter = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;                  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: can reassign mutable binding
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;2-primitive-types&quot;&gt;2. Primitive Types&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR provides a comprehensive set of primitives for precise control over memory.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Type&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Description&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Example&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;Int8&lt;&#x2F;code&gt; .. &lt;code&gt;Int64&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Signed integers (8, 16, 32, 64-bit)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;42_i64&lt;&#x2F;code&gt;, &lt;code&gt;-1_i8&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;UInt8&lt;&#x2F;code&gt; .. &lt;code&gt;UInt64&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Unsigned integers (8, 16, 32, 64-bit)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;42_u64&lt;&#x2F;code&gt;, &lt;code&gt;-1_u8&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;Float32&lt;&#x2F;code&gt;, &lt;code&gt;Float64&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;IEEE-754 floating point&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;3.14159_f64&lt;&#x2F;code&gt;, &lt;code&gt;1.0_f32&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;Bool&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Boolean logic&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;TRUE&lt;&#x2F;code&gt;, &lt;code&gt;FALSE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;Byte&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Raw 8-bit data&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;0x41_b&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;String&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;UTF-8 encoded text (affine)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;&quot;hello&quot;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;Void&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Absence of a value&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;RETURN;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;3-types-vs-capabilities&quot;&gt;3. Types vs Capabilities&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR distinguishes between what data &lt;em&gt;is&lt;&#x2F;em&gt; (Type) and how it is &lt;em&gt;accessed&lt;&#x2F;em&gt; (Capability). In Rust, capabilities like &lt;code&gt;Arc&lt;&#x2F;code&gt;, &lt;code&gt;Rc&lt;&#x2F;code&gt;, and &lt;code&gt;Mutex&lt;&#x2F;code&gt; are part of the type, leading to &quot;function coloring&quot; and high refactoring costs. In CLEAR, functions take &lt;strong&gt;Types&lt;&#x2F;strong&gt;, not &lt;strong&gt;Capabilities&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;capability-annotations&quot;&gt;Capability Annotations&lt;&#x2F;h3&gt;
&lt;p&gt;Capabilities are applied at the &lt;strong&gt;declaration site&lt;&#x2F;strong&gt; with &lt;code&gt;@&lt;&#x2F;code&gt; suffixes:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Capability&lt;&#x2F;th&gt;&lt;th&gt;Rust Equivalent&lt;&#x2F;th&gt;&lt;th&gt;CLEAR Syntax&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Single-threaded shared ownership&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;value @multiowned&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Multi-threaded shared ownership&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Arc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;value @shared&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Mutex (exclusive lock)&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Arc&amp;lt;Mutex&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;value @shared:locked&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;RwLock (read-write lock)&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Arc&amp;lt;RwLock&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;value @shared:writeLocked&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Heap pointer&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;value @indirect&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Thread-local pointer&lt;&#x2F;td&gt;&lt;td&gt;&lt;em&gt;(no direct equivalent)&lt;&#x2F;em&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;value @local&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;zero-blast-radius-refactoring&quot;&gt;Zero Blast Radius Refactoring&lt;&#x2F;h3&gt;
&lt;p&gt;In Rust, changing &lt;code&gt;Rc&amp;lt;User&amp;gt;&lt;&#x2F;code&gt; to &lt;code&gt;Arc&amp;lt;User&amp;gt;&lt;&#x2F;code&gt; means rewriting every function signature in the call chain. In CLEAR, functions take the plain type:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT User &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span&gt;String }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; process(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;u: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  print(u.name);
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# At the call site, capabilities are unwrapped:
&lt;&#x2F;span&gt;&lt;span&gt;  shared_u = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@shared&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; shared_u &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; val { process(val); }
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you change &lt;code&gt;@shared&lt;&#x2F;code&gt; to &lt;code&gt;@multiowned&lt;&#x2F;code&gt;, the &lt;code&gt;process&lt;&#x2F;code&gt; function remains untouched. The refactor is a one-line change at the declaration.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;with-blocks-for-capability-unwrapping&quot;&gt;WITH Blocks for Capability Unwrapping&lt;&#x2F;h3&gt;
&lt;p&gt;For multi-statement access, use &lt;code&gt;WITH&lt;&#x2F;code&gt; blocks:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;counter: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64@shared&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:locked &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH EXCLUSIVE&lt;&#x2F;span&gt;&lt;span&gt; counter &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; c {
&lt;&#x2F;span&gt;&lt;span&gt;    c += &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    print(c.toString());
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;4-affine-ownership-give-takes&quot;&gt;4. Affine Ownership: GIVE &amp;amp; TAKES&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR uses &lt;strong&gt;affine types&lt;&#x2F;strong&gt; by default. Every value has exactly one owner. When you assign a value, ownership is &lt;strong&gt;moved&lt;&#x2F;strong&gt;, not copied.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; process(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TAKES &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;s: &lt;&#x2F;span&gt;&lt;span&gt;String) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    print(s);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# s is destroyed here (end of scope)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    msg = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Hello&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    process(msg);                   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Implicit transfer (by FN signature)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;GIVE&lt;&#x2F;span&gt;&lt;span&gt; msg);                &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: USE AFTER MOVE: You can&amp;#39;t GIVE `msg`.  `process(msg)` TOOK it away.
&lt;&#x2F;span&gt;&lt;span&gt;    print(msg);                     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: USE AFTER MOVE: You can&amp;#39;t use `msg`.  `process(msg)` TOOK it away.
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For more details, see &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;docs&#x2F;walkthrough&#x2F;docs&#x2F;sharing-capabilities.md&quot;&gt;docs&#x2F;sharing-capabilities.md&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;parameter-ownership&quot;&gt;Parameter Ownership&lt;&#x2F;h3&gt;
&lt;p&gt;Function parameters are &lt;strong&gt;implicit borrows&lt;&#x2F;strong&gt; by default. Only &lt;code&gt;TAKES&lt;&#x2F;code&gt; transfers ownership.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Param Style&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Ownership&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Can Move Into Container?&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Can Mutate?&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;v: Value&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Borrow&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;No&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;No&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;MUTABLE v: Value&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Borrow&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;No&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;TAKES v: Value&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Owned&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;No&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;TAKES MUTABLE v: Value&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Owned&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNION Value &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Nil&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Num: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Lambda &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;body: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value @indirect &lt;&#x2F;span&gt;&lt;span&gt;} }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Borrow: can read, cannot store or move
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN &lt;&#x2F;span&gt;&lt;span&gt;inspect(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;v: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS &lt;&#x2F;span&gt;&lt;span&gt;String -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MATCH&lt;&#x2F;span&gt;&lt;span&gt; v &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;START
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;.Num &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; n -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; n.toString();,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DEFAULT &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;other&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Owned: can store into collections
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; store!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TAKES &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;v: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;map: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    map[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;item&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;] = v;                &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: v is owned via TAKES
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; bad!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;v: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;map: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    map[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;item&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;] = v;                &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: Cannot move borrowed value &amp;#39;v&amp;#39;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Zero implicit copies.&lt;&#x2F;strong&gt; Copy types (primitives, strings, enums) can be freely used after assignment. Non-Copy types (unions with &lt;code&gt;@indirect&lt;&#x2F;code&gt; or &lt;code&gt;[]T&lt;&#x2F;code&gt; variants, structs with heap data) follow move semantics. There are never implicit deep copies.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;5-sharded-shared-nothing-architecture&quot;&gt;5. Sharded Shared-Nothing Architecture&lt;&#x2F;h2&gt;
&lt;p&gt;The &lt;code&gt;@sharded&lt;&#x2F;code&gt; capability partitions data across threads, enabling massive parallelism without lock contention by automatically pinning threads to specific data shards.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# A sharded map distributes keys across independent thread-local heaps
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;registry: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;) = {};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# CLEAR automatically pins this fiber to the correct shard
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    registry[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;key&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;42&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Sharding is also available for Pools and Lists
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;users: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;) = [];
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;logs: &lt;&#x2F;span&gt;&lt;span&gt;String[]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@list&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;) = [];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Note: Sharding provides peak throughput but carries a risk of
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# data skew if keys&#x2F;items are not uniformly distributed.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;div class=&quot;gh-alert gh-alert-note&quot;&gt;
&lt;p class=&quot;gh-alert-title&quot;&gt;&lt;svg class=&quot;gh-alert-icon&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z&quot;&#x2F;&gt;&lt;&#x2F;svg&gt; Note&lt;&#x2F;p&gt;
&lt;p&gt;Shared-nothing architectures present problems if your workloads can be heavily skewed.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;6-function-signatures&quot;&gt;6. Function Signatures&lt;&#x2F;h2&gt;
&lt;p&gt;Functions support explicit types, failable returns (&lt;code&gt;!T&lt;&#x2F;code&gt;), and optional types (&lt;code&gt;?T&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Point &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; sum(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;p: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Point&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Float64 &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN &lt;&#x2F;span&gt;&lt;span&gt;p.x + p.y;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    p = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Point&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4.0 &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;    d = sum(p);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Failable and optional returns:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; findUser(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS &lt;&#x2F;span&gt;&lt;span&gt;!?User -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt; id &amp;lt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RAISE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Invalid ID&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; result;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;recursion&quot;&gt;Recursion&lt;&#x2F;h3&gt;
&lt;p&gt;Recursive functions must be explicitly annotated with &lt;code&gt;@reentrant&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; fib(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;n: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Int64 @reentrant &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt; n &amp;lt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; n;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; fib(n - &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;) + fib(n - &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;7-basic-control-flow&quot;&gt;7. Basic Control Flow&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR provides standard control flow constructs with support for one-line shorthands.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 1. IF &#x2F; ELSE_IF &#x2F; ELSE
&lt;&#x2F;span&gt;&lt;span&gt;x = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;75&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt; x &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN
&lt;&#x2F;span&gt;&lt;span&gt;    print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Large&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ELSE_IF&lt;&#x2F;span&gt;&lt;span&gt; x &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;50 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN
&lt;&#x2F;span&gt;&lt;span&gt;    print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Medium&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ELSE
&lt;&#x2F;span&gt;&lt;span&gt;    print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Small&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 2. WHILE loops
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; i = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHILE&lt;&#x2F;span&gt;&lt;span&gt; i &amp;lt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DO
&lt;&#x2F;span&gt;&lt;span&gt;    print(i.toString());
&lt;&#x2F;span&gt;&lt;span&gt;    i += &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 3. FOR loops (Range iteration)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FOR&lt;&#x2F;span&gt;&lt;span&gt; j &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IN &lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span&gt;..= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt; print(j.toString());     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Inclusive range
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FOR&lt;&#x2F;span&gt;&lt;span&gt; j &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IN &lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span&gt;..&amp;lt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt; print(j.toString());     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Exclusive range
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;8-enums-unions-and-pattern-matching&quot;&gt;8. Enums, Unions, and Pattern Matching&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;enums&quot;&gt;Enums&lt;&#x2F;h3&gt;
&lt;p&gt;Simple enumerations for discrete states:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ENUM Direction &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;North&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;South&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;East&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;West &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; describe(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;d: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Direction&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS &lt;&#x2F;span&gt;&lt;span&gt;String -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MATCH&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;START
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Direction&lt;&#x2F;span&gt;&lt;span&gt;.North -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;up&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Direction&lt;&#x2F;span&gt;&lt;span&gt;.South -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;down&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Direction&lt;&#x2F;span&gt;&lt;span&gt;.East  -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;right&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Direction&lt;&#x2F;span&gt;&lt;span&gt;.West  -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;left&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;tagged-unions-sum-types&quot;&gt;Tagged Unions (Sum Types)&lt;&#x2F;h3&gt;
&lt;p&gt;Unions carry a payload per variant. Unit variants (no payload) are also supported:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNION Result &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Ok: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Err: &lt;&#x2F;span&gt;&lt;span&gt;String, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Empty &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Payload variant
&lt;&#x2F;span&gt;&lt;span&gt;    r = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Ok: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;42.0 &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Unit variant (no payload)
&lt;&#x2F;span&gt;&lt;span&gt;    e = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;.Empty;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MATCH&lt;&#x2F;span&gt;&lt;span&gt; r &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;START
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;.Ok    -&amp;gt; print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;success&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;.Err   -&amp;gt; print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;error&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;.Empty -&amp;gt; print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;nothing&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;match-as-and-ownership&quot;&gt;MATCH AS and Ownership&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;MATCH ... AS&lt;&#x2F;code&gt; payload extraction follows the same ownership rules as parameters. The binding is a &lt;strong&gt;borrow&lt;&#x2F;strong&gt; of the source by default, or a &lt;strong&gt;move&lt;&#x2F;strong&gt; if the source is owned.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Source Ownership&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;MATCH AS Produces&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Can Store in Struct?&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;Borrowed (parameter, &lt;code&gt;map.get&lt;&#x2F;code&gt;)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Borrow&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;No&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;Owned (local, TAKES param)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Move (consumes source)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNION Value &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Nil&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Num: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;List: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;[] }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Borrowed source: MATCH AS produces a borrow
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; sum(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;v: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Float64 &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MATCH&lt;&#x2F;span&gt;&lt;span&gt; v &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;START
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;.List &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; items -&amp;gt;       &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# items is &amp;amp;[]Value (borrow)
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; items.length();   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: reading a borrow
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DEFAULT &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Owned source: MATCH AS moves the payload
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; take!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TAKES &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;v: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Value&lt;&#x2F;span&gt;&lt;span&gt;[] -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MATCH&lt;&#x2F;span&gt;&lt;span&gt; v &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;START
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;.List &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; items -&amp;gt;       &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# items is []Value (owned, v consumed)
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; items;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: returning owned data
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DEFAULT &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN List&lt;&#x2F;span&gt;&lt;span&gt;[];
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Storing a borrowed &lt;code&gt;MATCH AS&lt;&#x2F;code&gt; binding into a struct or union variant is a compile error:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; bad(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;items: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span&gt;[]) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Value &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# items is a borrowed parameter
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN Value&lt;&#x2F;span&gt;&lt;span&gt;.Lambda{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;params:&lt;&#x2F;span&gt;&lt;span&gt; items };  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: Cannot store borrowed &amp;#39;items&amp;#39;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;generics&quot;&gt;Generics&lt;&#x2F;h3&gt;
&lt;p&gt;Structs and unions support type parameters:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Pair&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; { &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;first: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;second: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;T &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;p = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Pair&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;first: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;second: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2 &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;9-higher-order-functions-error-handling&quot;&gt;9. Higher-Order Functions &amp;amp; Error Handling&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR supports powerful functional pipelines via the Smooth operator &lt;code&gt;|&amp;gt;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 1. Pipelines: Filter, Aggregate, Transform
&lt;&#x2F;span&gt;&lt;span&gt;alive = entities |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.health &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;total = scores |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.value;
&lt;&#x2F;span&gt;&lt;span&gt;names = users |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; _.name;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 2. Side effects &amp;amp; Function Piping
&lt;&#x2F;span&gt;&lt;span&gt;entities |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EACH &lt;&#x2F;span&gt;&lt;span&gt;{ _.x += _.vx; };
&lt;&#x2F;span&gt;&lt;span&gt;result = data |&amp;gt; process |&amp;gt; validate |&amp;gt; format;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 3. Error Handling: Inline OR &#x2F; OR RAISE
&lt;&#x2F;span&gt;&lt;span&gt;val = parseInt(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;abc&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;                         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Fallback value
&lt;&#x2F;span&gt;&lt;span&gt;content = readFile(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;config.json&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR RAISE&lt;&#x2F;span&gt;&lt;span&gt;;         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Explicit propagation
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 4. Function-level CATCH
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    result = loadConfig(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;config.json&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR RAISE&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Config: ${result}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CATCH&lt;&#x2F;span&gt;&lt;span&gt; e
&lt;&#x2F;span&gt;&lt;span&gt;    print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Failed to load: ${e}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;See &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;docs&#x2F;walkthrough&#x2F;docs&#x2F;pipelines.md#operators&quot;&gt;docs&#x2F;pipelines.md#operators&lt;&#x2F;a&gt; for a full list of higher-order function operators.&lt;&#x2F;p&gt;
&lt;p&gt;Pipelines are automatically fused for efficiency.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;10-time-as-tense-t&quot;&gt;10. Time as Tense (~T)&lt;&#x2F;h2&gt;
&lt;p&gt;Tense represents a value that will exist in the future. CLEAR eliminates the complexity of &lt;code&gt;Future&#x2F;Promise&#x2F;Observable&lt;&#x2F;code&gt; with a single unified tense.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;~User&lt;&#x2F;code&gt; is read as &lt;strong&gt;&quot;Future User&quot;&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;~User[]&lt;&#x2F;code&gt; is read as &lt;strong&gt;&quot;Future Users&quot;&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;A &lt;strong&gt;STREAM&lt;&#x2F;strong&gt; of users is simply one way to produce &quot;Future Users&quot;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 1. Promise (~T): A single future value
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;p: &lt;&#x2F;span&gt;&lt;span&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;String &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ sleep(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;); &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Data&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;; };
&lt;&#x2F;span&gt;&lt;span&gt;val = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT &lt;&#x2F;span&gt;&lt;span&gt;p;                                       &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Blocks until ready
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 2. Open Stream (~?T[]): Asynchronous generator
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# NEXT on ~?T[] returns ?T, with NIL signaling exhaustion.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;gen: &lt;&#x2F;span&gt;&lt;span&gt;~?Int64[] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG STREAM &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;val = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; gen;                                     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Returns ?Int64 (NIL when exhausted)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 3. Infinite Stream (~T[INF]): Lazy rendezvous generator
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;counter: &lt;&#x2F;span&gt;&lt;span&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;INF&lt;&#x2F;span&gt;&lt;span&gt;] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG STREAM &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; i = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHILE TRUE DO &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD&lt;&#x2F;span&gt;&lt;span&gt; i; i += &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;; }
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;v1 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; counter;                                  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OKAY: Returns Int64 (never NIL)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;stream-capabilities-shared-vs-split&quot;&gt;Stream Capabilities: &lt;code&gt;@shared&lt;&#x2F;code&gt; vs &lt;code&gt;@split&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Streams can also carry sharing capabilities:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@shared&lt;&#x2F;code&gt; means the stream handle may be shared across threads, but it is not ordered replay. Multiple threads calling &lt;code&gt;NEXT&lt;&#x2F;code&gt; are sharing access to one producer.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;@split&lt;&#x2F;code&gt; means ordered fanout &#x2F; pub-sub semantics. Each cloned handle sees the same items in the same order, and memoized items are released once every live split owner has consumed them.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;source: &lt;&#x2F;span&gt;&lt;span&gt;~?Int64[]@split = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG STREAM &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;a: &lt;&#x2F;span&gt;&lt;span&gt;~?Int64[]@split = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLONE&lt;&#x2F;span&gt;&lt;span&gt; source;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;b: &lt;&#x2F;span&gt;&lt;span&gt;~?Int64[]@split = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLONE&lt;&#x2F;span&gt;&lt;span&gt; source;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT NEXT&lt;&#x2F;span&gt;&lt;span&gt; a == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;first subscriber sees first value&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT NEXT&lt;&#x2F;span&gt;&lt;span&gt; b == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;second subscriber sees the same first value&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT NEXT&lt;&#x2F;span&gt;&lt;span&gt; a == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;order is preserved&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT NEXT&lt;&#x2F;span&gt;&lt;span&gt; b == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;order is preserved for all subscribers&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;CLONE&lt;&#x2F;code&gt; is mandatory for &lt;code&gt;@split&lt;&#x2F;code&gt; streams. Plain assignment moves the handle.&lt;&#x2F;p&gt;
&lt;p&gt;This is the model CLEAR intends for pub&#x2F;sub style workloads. For a concrete benchmark in this area, see &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;docs&#x2F;walkthrough&#x2F;benchmarks&#x2F;16_pubsub&#x2F;bench.cht&quot;&gt;benchmarks&#x2F;16_pubsub&#x2F;bench.cht&lt;&#x2F;a&gt;. That benchmark still uses the older sharing path today, but it is the right benchmark to watch as &lt;code&gt;@split&lt;&#x2F;code&gt; becomes the native pub&#x2F;sub primitive.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;11-collections-array-list-and-pool&quot;&gt;11. Collections: Array, List, and Pool&lt;&#x2F;h2&gt;
&lt;p&gt;All collections are &lt;strong&gt;automatically monomorphized&lt;&#x2F;strong&gt; -- the compiler generates zero-overhead, type-specific native code for every unique &lt;code&gt;T&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Sigil&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Collection&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Purpose&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;T[N]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;Array&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Fixed-size, stack-allocated (if small)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;T[]@list&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;List&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Dynamic-size, heap-backed&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;T[N]@pool&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;Pool&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Fixed-capacity, generational handles&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;T[]@set&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;Set&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Dynamic-size, heap-backed, distinct items&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;T[]@ring&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;Ring&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Circular Ring Buffer (mainly for Streams - v0.2)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT User &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span&gt;String }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 1. Fixed Array
&lt;&#x2F;span&gt;&lt;span&gt;vals = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 2. Dynamic List
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;items: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;[]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@list &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span&gt;items.append(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;42&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 3. Generational Pool
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Pools provide peak cache locality. Switching from List to @pool:soa
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# (Structure of Arrays) is a one-line refactor for massive speed.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;users: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;id = users.insert(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;});           &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Returns stable handle
&lt;&#x2F;span&gt;&lt;span&gt;user = users.get(id) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR RAISE&lt;&#x2F;span&gt;&lt;span&gt;;                      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Returns ?T (checks stale handles)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;element-level-capabilities&quot;&gt;Element-Level Capabilities&lt;&#x2F;h3&gt;
&lt;p&gt;Capabilities normally apply to the &lt;strong&gt;collection&lt;&#x2F;strong&gt; (&lt;code&gt;T[]@shared&lt;&#x2F;code&gt; = one shared list). For rare cases where each &lt;strong&gt;element&lt;&#x2F;strong&gt; needs its own capability, place the capability before the array suffix:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Collection-level (common): one Arc wrapping the whole list
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;shared_list: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;[]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@list&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:shared &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Element-level (rare): each element is individually Arc&amp;#39;d
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;arc_users: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User@shared&lt;&#x2F;span&gt;&lt;span&gt;[]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@list &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Element-level with pool: each slot holds an Arc&amp;#39;d user
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;arc_pool: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User@shared&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Element-level capabilities are primarily useful in struct fields where individual elements need independent lifetime management (e.g., a graph where each node is shared across multiple edges).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;12-strings-and-buffers&quot;&gt;12. Strings and Buffers&lt;&#x2F;h2&gt;
&lt;p&gt;Strings in CLEAR are Copy (like Rust&#x27;s &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt; — a pointer + length). Assignment copies the slice header.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;x = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;hello&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;y = x;                         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# x is moved (strings are owned, non-Copy)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# z = x;                       # would be use-after-move error
&lt;&#x2F;span&gt;&lt;span&gt;z = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; y;                    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OK: explicit deep-copy
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# String concatenation
&lt;&#x2F;span&gt;&lt;span&gt;full = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;foo&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;+ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;bar&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;          &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# &amp;quot;foobar&amp;quot; (single allocation, no intermediate)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Like arrays, Strings have capabilities:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;String@raw&lt;&#x2F;code&gt; - raw byte buffer; no UTF-8 encoding assumption, O(1) byte indexing, zero-copy slicing. Use for binary data, network buffers, parsers operating on bytes.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;String@symbol&lt;&#x2F;code&gt; - compile-time interned identifier. Literals use Ruby-style &lt;code&gt;:ok&lt;&#x2F;code&gt; syntax. The compiler embeds the string in read-only static memory and deduplicates identical literals, so equality is O(1) pointer comparison and the value needs no cleanup (program-lifetime). Use for status tags, option names, event names, and map keys where the set of values is known at compile time. Note: interned HashMaps carry their own per-map symbol table for runtime string keys - this avoids a globally locked intern table, which would create a contention hotspot incompatible with CLEAR&#x27;s scalability goals.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;String@ring&lt;&#x2F;code&gt; (v0.2) - circular buffer for streaming.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;13-graphs-cycles-and-indirect&quot;&gt;13. Graphs, Cycles, and @indirect&lt;&#x2F;h2&gt;
&lt;p&gt;For recursive or cyclic data structures, use &lt;code&gt;@indirect&lt;&#x2F;code&gt; (heap-allocated pointer, like Rust&#x27;s &lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;). Combined with &lt;code&gt;@reentrant&lt;&#x2F;code&gt; for recursive traversal:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Recursive tree node using @indirect for child pointers
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Node &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;left: &lt;&#x2F;span&gt;&lt;span&gt;?Node@indirect,     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Optional heap-allocated child
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;right: &lt;&#x2F;span&gt;&lt;span&gt;?Node@indirect
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Recursive traversal must be @reentrant
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; sumTree(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;n: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Node&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Int64 @reentrant &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; total = n.value;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt; n.left -&amp;gt; total += sumTree(n?.left &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt; n.right -&amp;gt; total += sumTree(n?.right &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; total;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;@indirect&lt;&#x2F;code&gt; gives the node a stable heap address, enabling graph structures. &lt;code&gt;@multiowned&lt;&#x2F;code&gt; (Rc) enables shared ownership for DAGs. For cyclic graphs, use &lt;code&gt;@link&lt;&#x2F;code&gt; -- CLEAR&#x27;s weak reference.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;?.&lt;&#x2F;code&gt; is the safe navigate operator to peek into optional types.  It combines with &lt;code&gt;OR&lt;&#x2F;code&gt; to handle missing data like an error.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;weak-references-with-link&quot;&gt;Weak References with @link&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;@link&lt;&#x2F;code&gt; creates a weak reference that does not keep the target alive. It works with both &lt;code&gt;@multiowned&lt;&#x2F;code&gt; (WeakRc) and &lt;code&gt;@shared&lt;&#x2F;code&gt; (WeakArc).&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;LINK expr&lt;&#x2F;code&gt; -- downgrade a strong reference to a weak reference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;RESOLVE expr&lt;&#x2F;code&gt; -- upgrade a weak reference back to an optional strong reference (&lt;code&gt;?T&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Parent-child with back-pointer cycle
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Parent &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span&gt;String,
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;child: &lt;&#x2F;span&gt;&lt;span&gt;?Child@multiowned@indirect
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Child &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span&gt;String,
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;parent: &lt;&#x2F;span&gt;&lt;span&gt;?Parent@link          &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# weak back-pointer, breaks the cycle
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    p = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Parent&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;child: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NIL &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@multiowned&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# LINK downgrades the strong Rc to a WeakRc
&lt;&#x2F;span&gt;&lt;span&gt;    weak_p = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;LINK &lt;&#x2F;span&gt;&lt;span&gt;p;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# RESOLVE returns ?Parent@multiowned; bind first, then use ?. to safely access fields
&lt;&#x2F;span&gt;&lt;span&gt;    resolved = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RESOLVE&lt;&#x2F;span&gt;&lt;span&gt; weak_p;
&lt;&#x2F;span&gt;&lt;span&gt;    name = resolved?.name &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;dropped&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT &lt;&#x2F;span&gt;&lt;span&gt;name == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;resolved&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Key rules:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;LINK&lt;&#x2F;code&gt; only works on &lt;code&gt;@multiowned&lt;&#x2F;code&gt; or &lt;code&gt;@shared&lt;&#x2F;code&gt; values (compile-time error otherwise)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;RESOLVE&lt;&#x2F;code&gt; only works on &lt;code&gt;@link&lt;&#x2F;code&gt; values (compile-time error otherwise)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;RESOLVE&lt;&#x2F;code&gt; returns &lt;code&gt;?T&lt;&#x2F;code&gt; -- bind the result first, then use &lt;code&gt;resolved?.field OR fallback&lt;&#x2F;code&gt; to handle the dropped case&lt;&#x2F;li&gt;
&lt;li&gt;Cleanup is automatic: weak references are released when they go out of scope&lt;&#x2F;li&gt;
&lt;li&gt;No runtime cost when the strong reference is still alive; RESOLVE is a simple count check&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;14-concurrency-bg-do&quot;&gt;14. Concurrency: BG &amp;amp; DO&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR makes background tasks and fork-join parallelism trivial.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# BG: Background execution
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;p: &lt;&#x2F;span&gt;&lt;span&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64 &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; slowComputation(); };
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# DO: Fork-Join parallel execution
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DO &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    step1(),
&lt;&#x2F;span&gt;&lt;span&gt;    step2()
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# CONCURRENT: Parallel pipelines
&lt;&#x2F;span&gt;&lt;span&gt;results = items |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;workers: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; transform(_);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;bg-stack-modifiers&quot;&gt;BG Stack Modifiers&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Modifier&lt;&#x2F;th&gt;&lt;th&gt;Stack Size&lt;&#x2F;th&gt;&lt;th&gt;Use&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@micro&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;4 KB&lt;&#x2F;td&gt;&lt;td&gt;Lightweight tasks&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@standard&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;16 KB&lt;&#x2F;td&gt;&lt;td&gt;Default&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@large&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;64 KB&lt;&#x2F;td&gt;&lt;td&gt;File I&#x2F;O, deep recursion&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@xl&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;256 KB&lt;&#x2F;td&gt;&lt;td&gt;Very deep call stacks&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@pinned&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;(any)&lt;&#x2F;td&gt;&lt;td&gt;Pin to local scheduler&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@arena&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;(any)&lt;&#x2F;td&gt;&lt;td&gt;Thread-local arena; implies @pinned&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;15-modules-imports&quot;&gt;15. Modules &amp;amp; Imports&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR uses a simple namespace-based module system via &lt;code&gt;REQUIRE&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REQUIRE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;math_utils.cht&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; m;                      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Local file alias
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REQUIRE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;pkg:geometry&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;                             &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Package import
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; main() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    p = geometry.Point{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2 &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;    print(m.square(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;).toString());
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;See &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;docs&#x2F;walkthrough&#x2F;docs&#x2F;modules.md&quot;&gt;docs&#x2F;modules.md&lt;&#x2F;a&gt; for visibility (&lt;code&gt;PUB&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;PRIVATE&lt;&#x2F;code&gt;) and build details.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;16-ffi-native-integration&quot;&gt;16. FFI: Native Integration&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR integrates directly with Zig and C libraries via &lt;code&gt;EXTERN&lt;&#x2F;code&gt; declarations. All EXTERN FN calls automatically trampoline to the OS stack (g0) for fiber safety.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;importing-functions-and-types&quot;&gt;Importing Functions and Types&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Import a struct type from a Zig module
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN STRUCT Vec2 &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FROM &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;math_native&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Import a free function
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN FN&lt;&#x2F;span&gt;&lt;span&gt; computeDistance(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;v: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Vec2&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Float64 FROM &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;math_native&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Import with allocator injection (EFFECTS)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN FN&lt;&#x2F;span&gt;&lt;span&gt; parseJson(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;data: &lt;&#x2F;span&gt;&lt;span&gt;String) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS &lt;&#x2F;span&gt;&lt;span&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;JsonDoc
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EFFECTS &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:alloc:heap &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FROM &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;json_native&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;local-struct-definitions-no-from&quot;&gt;Local Struct Definitions (no FROM)&lt;&#x2F;h3&gt;
&lt;p&gt;For passing default options or defining Zig-compatible layouts:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Local struct (no external module)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN STRUCT ParseOptions &lt;&#x2F;span&gt;&lt;span&gt;{};
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN STRUCT JsonRecord &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;data: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;[] };
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Comptime type parameters for generic FFI
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN FN&lt;&#x2F;span&gt;&lt;span&gt; parseFromSliceLeaky&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;comptime: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;content: &lt;&#x2F;span&gt;&lt;span&gt;String, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;options: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ParseOptions&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS &lt;&#x2F;span&gt;&lt;span&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;T EFFECTS &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:alloc:heap &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FROM &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;std.json&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;method-calls-on-extern-structs&quot;&gt;Method Calls on EXTERN Structs&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN STRUCT Dir &lt;&#x2F;span&gt;&lt;span&gt;{} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FROM &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;std.fs&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN FN&lt;&#x2F;span&gt;&lt;span&gt; cwd() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Dir FROM &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;std.fs&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN FN Dir&lt;&#x2F;span&gt;&lt;span&gt;.makePath(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;self: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Dir&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;path: &lt;&#x2F;span&gt;&lt;span&gt;String) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void FROM &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;std.fs&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Chained method call (both trampolined to g0)
&lt;&#x2F;span&gt;&lt;span&gt;cwd().makePath(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;extern-struct-close-raii&quot;&gt;EXTERN STRUCT CLOSE (RAII)&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EXTERN STRUCT Buffer &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;data: &lt;&#x2F;span&gt;&lt;span&gt;String }
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLOSE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;deinit&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FROM &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;native_resource&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Buffer.deinit() is auto-called when buf goes out of scope
&lt;&#x2F;span&gt;&lt;span&gt;buf = createBuffer(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;hello&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# defer buf.deinit() emitted automatically
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;See &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;docs&#x2F;walkthrough&#x2F;benchmarks&#x2F;24_json_api&#x2F;server.cht&quot;&gt;json_api&lt;&#x2F;a&gt; for an example.&lt;&#x2F;li&gt;
&lt;li&gt;See &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;docs&#x2F;walkthrough&#x2F;docs&#x2F;agents&#x2F;ffi.md&quot;&gt;docs&#x2F;agents&#x2F;ffi.md&lt;&#x2F;a&gt; for the complete FFI guide.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;17-memory-model&quot;&gt;17. Memory Model&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;arena-allocation&quot;&gt;Arena Allocation&lt;&#x2F;h3&gt;
&lt;p&gt;Every function has its own memory arena. Variables live as long as the function they were born in.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Stack&lt;&#x2F;strong&gt; (~0ns): Primitives and small structs (up to 128 slots)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Frame Arena&lt;&#x2F;strong&gt; (~2ns): Large structs, temporary buffers, string concat&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Heap&lt;&#x2F;strong&gt; (~60ns): Dynamic collections, cross-fiber data, Rc&#x2F;Arc&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;escaping-the-arena&quot;&gt;Escaping the Arena&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;RETURN&lt;&#x2F;code&gt;: Values stay in the caller&#x27;s frame arena (no heap dupe for strings).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;GIVE&lt;&#x2F;code&gt;: Ownership is transferred to the callee.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;@shared&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;@multiowned&lt;&#x2F;code&gt;: Reference-counted objects that live as long as they are referenced.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;loop-arena-rewind&quot;&gt;Loop Arena Rewind&lt;&#x2F;h3&gt;
&lt;p&gt;Inside loops, the frame arena is rewound each iteration to prevent unbounded growth. Mutable variables that accumulate across iterations (like string concatenation) are automatically detected and excluded from the rewind.&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR additionally inserts cooperative yielding into loops to prevent head-of-line blocking, etc.&lt;&#x2F;p&gt;
&lt;p&gt;This destroys SIMD optimizations. CLEAR can detect when a SIMD optimization is possible and warn you to use &lt;code&gt;TIGHT&lt;&#x2F;code&gt; loops:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TIGHT FOR&lt;&#x2F;span&gt;&lt;span&gt; i &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IN &lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;..&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt; ...
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;CLEAR will also warn you when you&#x27;re using a &lt;code&gt;TIGHT&lt;&#x2F;code&gt; loop and you should not.&lt;&#x2F;p&gt;
&lt;div class=&quot;gh-alert gh-alert-note&quot;&gt;
&lt;p class=&quot;gh-alert-title&quot;&gt;&lt;svg class=&quot;gh-alert-icon&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z&quot;&#x2F;&gt;&lt;&#x2F;svg&gt; Note&lt;&#x2F;p&gt;
&lt;p&gt;Misusing &lt;code&gt;TIGHT&lt;&#x2F;code&gt; loops can destroy your p99 latency.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;18-the-reality-of-concurrency&quot;&gt;18. The Reality of Concurrency&lt;&#x2F;h2&gt;
&lt;p&gt;In an ideal world, every workload would distribute perfectly across available cores and memory. In reality, concurrency is difficult because of the &quot;messy middle&quot;:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Skew:&lt;&#x2F;strong&gt; Data is rarely uniform. Sharded collections can develop &quot;hot shards&quot; that bottleneck the system.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Outliers:&lt;&#x2F;strong&gt; The 0.1% of workers that take 100x longer than typical (due to cache misses or deep recursion) destroy p99 response times.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Non-Cooperation:&lt;&#x2F;strong&gt; Problems like head-of-line blocking and thundering herds can stall an entire thread pool.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Variadic Depth:&lt;&#x2F;strong&gt; Real-world recursion and loops often exceed the fixed stack sizes of traditional fibers.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;CLEAR handles these issues through its &lt;strong&gt;Control Plane&lt;&#x2F;strong&gt; -- an active runtime observer that uses live telemetry to manage execution.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fiber Overflow:&lt;&#x2F;strong&gt; The runtime detects imminent stack overflows and auto-upsizes future tasks to &lt;code&gt;@large&lt;&#x2F;code&gt; or &lt;code&gt;@xl&lt;&#x2F;code&gt; stacks.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Workload Mismatch (v0.2):&lt;&#x2F;strong&gt; Telemetry-driven alerting when the runtime detects contented or skewed workloads. &lt;code&gt;.&#x2F;clear profile&lt;&#x2F;code&gt; can automatically suggest fixes.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Shared-Nothing Safety:&lt;&#x2F;strong&gt; By enforcing sharding and affine moves at the language level, the Control Plane can optimize memory layout without fear of data races.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Workload Migration (v0.4+):&lt;&#x2F;strong&gt; Telemetry-driven migration allows the runtime to detect contention and skew in real-time and react to it, &lt;em&gt;IF&lt;&#x2F;em&gt; you have the protection enabled (added memory).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;See &lt;a href=&quot;https:&#x2F;&#x2F;cuzzo.github.io&#x2F;clear&#x2F;docs&#x2F;walkthrough&#x2F;docs&#x2F;control-plane.md&quot;&gt;docs&#x2F;control-plane.md&lt;&#x2F;a&gt; for more on how CLEAR manages the reality of high-performance systems.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;19-function-lifetimes&quot;&gt;19. Function Lifetimes&lt;&#x2F;h2&gt;
&lt;p&gt;Functions cannot return borrowed data freely, but can with a lifetime.  This is simplified from Rust.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Node &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;left: &lt;&#x2F;span&gt;&lt;span&gt;?Node, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;right: &lt;&#x2F;span&gt;&lt;span&gt;?Node }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; grandChild(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;n: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Node&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS&lt;&#x2F;span&gt;&lt;span&gt; n.left:?Node -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; n.left?.right;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Lifetimes are scoped with &lt;code&gt;&amp;lt;param&amp;gt;.&amp;lt;path&amp;gt;:Type&lt;&#x2F;code&gt;. In the example above, &lt;code&gt;n.left&lt;&#x2F;code&gt; is the path and &lt;code&gt;?Node&lt;&#x2F;code&gt; is the return type.&lt;&#x2F;p&gt;
&lt;p&gt;This is a less restrictive lifetime than &lt;code&gt;r:Bar&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Standard &lt;code&gt;IMMUTABLE&lt;&#x2F;code&gt; returned borrows &lt;em&gt;just work&lt;&#x2F;em&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;bar = root.identity();
&lt;&#x2F;span&gt;&lt;span&gt;print(bar.index);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;MUTABLE&lt;&#x2F;code&gt; returned borrows require a scope - because the object you&#x27;re borrowing from is restricted while you hold the borrow to prevent use-after-free:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH RESTRICT&lt;&#x2F;span&gt;&lt;span&gt; node &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; n {
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; gc = n.grandChild();
&lt;&#x2F;span&gt;&lt;span&gt;  gc.value = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  node.left = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Nil&lt;&#x2F;span&gt;&lt;span&gt;; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPIILER ERROR: `node` is RESTRICTED.  It&amp;#39;s immutable in this scope.
&lt;&#x2F;span&gt;&lt;span&gt;  n.left = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Nil&lt;&#x2F;span&gt;&lt;span&gt;;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPIILER ERROR: `n` is RESTRICTED.  It&amp;#39;s immutable in this scope.
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;20-struct-lifetimes&quot;&gt;20. STRUCT lifetimes&lt;&#x2F;h2&gt;
&lt;p&gt;It&#x27;s sometimes useful to define a STRUCT with a borrowed field (iterators are a prime example):&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT SliceIter &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;source: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BORROWED Int64&lt;&#x2F;span&gt;&lt;span&gt;[], &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Allows `source` to be a BORROW, must be initialized in a scope.
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;pos: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;len: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; hasNext(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;iter: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SliceIter&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Bool &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; iter.pos &amp;lt; iter.len;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; iterExample() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH BORROWED&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; ref { &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# create a borrowed version
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; iter = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SliceIter&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;source:&lt;&#x2F;span&gt;&lt;span&gt; ref, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;pos: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;len:&lt;&#x2F;span&gt;&lt;span&gt; n };
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHILE&lt;&#x2F;span&gt;&lt;span&gt; hasNext(iter) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DO
&lt;&#x2F;span&gt;&lt;span&gt;      total += currentVal(iter);
&lt;&#x2F;span&gt;&lt;span&gt;      iter = advance(iter);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; iter;       &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# COMPILER ERROR: You can&amp;#39;t return `iter`.  It&amp;#39;s BORROWED.  You don&amp;#39;t own it.
&lt;&#x2F;span&gt;&lt;span&gt;  }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;quick-reference-capabilities&quot;&gt;Quick Reference: Capabilities&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Annotation&lt;&#x2F;th&gt;&lt;th&gt;Purpose&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@multiowned&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Single-threaded shared ownership (Rc)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@shared&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Multi-threaded shared ownership (Arc)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@shared:locked&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Arc + Mutex&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@shared:writeLocked&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Arc + RwLock&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@locked&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Mutex (single-scheduler)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@writeLocked&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;RwLock (single-scheduler)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@local&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Thread-local heap pointer&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@indirect&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Explicit heap allocation (Box)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@link&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;To create cyclic graphs (WeakRef&#x2F;Ref)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@sharded(N)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Shared-nothing partitioned across N shards&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;quick-reference-sigils&quot;&gt;Quick Reference: Sigils&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Sigil&lt;&#x2F;th&gt;&lt;th&gt;Meaning&lt;&#x2F;th&gt;&lt;th&gt;Example&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Capability &#x2F; pipeline binding&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;value @shared&lt;&#x2F;code&gt;, &lt;code&gt;|&amp;gt; process AS @p&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;!&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Mutation suffix&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;FN increment!(...)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;|&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Smooth operator (pipeline)&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;items |&amp;gt; WHERE _ &amp;gt; 5&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;_&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Pipeline element placeholder&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; SELECT _.name&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;!T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Error union type&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;RETURNS !Float64&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;?T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Optional type&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;RETURNS ?User&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Promise &#x2F; stream type&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;p: ~Int64 = BG { 42; }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;integer-overflow-operators&quot;&gt;Integer Overflow Operators&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR uses fixed-width integers (Int64, Int32, etc.) that can overflow. Three tiers of arithmetic operators control what happens on overflow:&lt;&#x2F;p&gt;
&lt;h3 id=&quot;default&quot;&gt;Default: &lt;code&gt;+&lt;&#x2F;code&gt;, &lt;code&gt;-&lt;&#x2F;code&gt;, &lt;code&gt;*&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Panics on overflow in &lt;strong&gt;debug&lt;&#x2F;strong&gt; builds, wraps silently in &lt;strong&gt;release&lt;&#x2F;strong&gt; builds. This matches Rust&#x27;s semantics - catches accidental overflow during development, zero overhead in production.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;a: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64 &lt;&#x2F;span&gt;&lt;span&gt;= 9223372036854775807_i64;
&lt;&#x2F;span&gt;&lt;span&gt;b = a + 1_i64;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# debug: PANIC!  release: wraps to -9223372036854775808
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;wrapping&quot;&gt;Wrapping: &lt;code&gt;%+&lt;&#x2F;code&gt;, &lt;code&gt;%-&lt;&#x2F;code&gt;, &lt;code&gt;%*&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Always wraps on overflow in &lt;strong&gt;all&lt;&#x2F;strong&gt; build modes. Use for hash functions, random number generators, checksums, and any code that intentionally overflows.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# LCG random number generator (intentional overflow)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;state: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64 &lt;&#x2F;span&gt;&lt;span&gt;= seed;
&lt;&#x2F;span&gt;&lt;span&gt;state = state &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;%*&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt; 6364136223846793005_i64 %+ 1442695040888963407_i64;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;# Max + 1 wraps to min
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;max: Int64 = 9223372036854775807_i64;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;min = max %+ 1_i64;  # always -9223372036854775808, never panics
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;checked&quot;&gt;Checked: &lt;code&gt;!+&lt;&#x2F;code&gt;, &lt;code&gt;!-&lt;&#x2F;code&gt;, &lt;code&gt;!*&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Always panics on overflow in &lt;strong&gt;all&lt;&#x2F;strong&gt; build modes, including release. Use for financial calculations, safety-critical code, and anywhere overflow indicates a logic error.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Financial calculation: overflow means a bug, even in production
&lt;&#x2F;span&gt;&lt;span&gt;balance = balance !+ deposit;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# panics if result exceeds Int64 range
&lt;&#x2F;span&gt;&lt;span&gt;total = quantity !* price;     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# panics on overflow, even in release
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;Debug build&lt;&#x2F;th&gt;&lt;th&gt;Release build&lt;&#x2F;th&gt;&lt;th&gt;Use case&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;+&lt;&#x2F;code&gt;, &lt;code&gt;-&lt;&#x2F;code&gt;, &lt;code&gt;*&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;panic&lt;&#x2F;td&gt;&lt;td&gt;wrap&lt;&#x2F;td&gt;&lt;td&gt;General arithmetic&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;%+&lt;&#x2F;code&gt;, &lt;code&gt;%-&lt;&#x2F;code&gt;, &lt;code&gt;%*&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;wrap&lt;&#x2F;td&gt;&lt;td&gt;wrap&lt;&#x2F;td&gt;&lt;td&gt;Hash, RNG, checksum&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;!+&lt;&#x2F;code&gt;, &lt;code&gt;!-&lt;&#x2F;code&gt;, &lt;code&gt;!*&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;panic&lt;&#x2F;td&gt;&lt;td&gt;panic&lt;&#x2F;td&gt;&lt;td&gt;Financial, safety&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Float arithmetic (&lt;code&gt;Float64&lt;&#x2F;code&gt;) is unaffected - IEEE 754 handles overflow via infinity&#x2F;NaN.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Concurrency</title>
        <published>2026-03-26T00:00:00+00:00</published>
        <updated>2026-05-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/concurrency/"/>
        <id>https://cuzzo.github.io/clear/docs/concurrency/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/concurrency/">&lt;p&gt;CLEAR uses cooperative fibers for concurrency.&lt;&#x2F;p&gt;
&lt;p&gt;Fibers are lightweight threads managed by the CLEAR runtime — each has its own stack (4-256KB) and runs until it yields. No OS threads are created per fiber; the scheduler multiplexes fibers onto a thread pool.&lt;&#x2F;p&gt;
&lt;div class=&quot;gh-alert gh-alert-note&quot;&gt;
&lt;p class=&quot;gh-alert-title&quot;&gt;&lt;svg class=&quot;gh-alert-icon&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z&quot;&#x2F;&gt;&lt;&#x2F;svg&gt; Note&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR will support limited Finite State Machines in v0.2, and by v0.4 - full support for Finite State Machines is planned.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;bg-background-fibers&quot;&gt;BG — Background Fibers&lt;&#x2F;h2&gt;
&lt;p&gt;Spawn a fiber that runs concurrently and returns a Promise:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;p = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ expensive_computation(data); };
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# ... do other work ...
&lt;&#x2F;span&gt;&lt;span&gt;result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT &lt;&#x2F;span&gt;&lt;span&gt;p;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# block until the fiber finishes
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The last expression in the body becomes the promise&#x27;s value. &lt;code&gt;NEXT&lt;&#x2F;code&gt; consumes the promise and returns the value.&lt;&#x2F;p&gt;
&lt;div class=&quot;gh-alert gh-alert-note&quot;&gt;
&lt;p class=&quot;gh-alert-title&quot;&gt;&lt;svg class=&quot;gh-alert-icon&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z&quot;&#x2F;&gt;&lt;&#x2F;svg&gt; Note&lt;&#x2F;p&gt;
&lt;p&gt;By v0.4 Finite State Machines will be the default, and you will opt-in to stack-based fibers for re-entrant tasks or tasks that use FFI.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h3 id=&quot;modifiers&quot;&gt;Modifiers&lt;&#x2F;h3&gt;
&lt;p&gt;Modifiers go inside the braces, before a &lt;code&gt;-&amp;gt;&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@large&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:pinned &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; heavy_work(); }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Modifier&lt;&#x2F;th&gt;&lt;th&gt;Effect&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@micro&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;4 KB fiber stack&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@standard&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;16 KB fiber stack (default)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@large&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;64 KB fiber stack&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@xl&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;256 KB fiber stack&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@service&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;OS thread&lt;&#x2F;strong&gt; (not a fiber). Full OS stack. For heavy non-cooperative compute.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@pinned&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Pin to local scheduler (no work stealing)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@parallel&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Distribute to least-loaded scheduler&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@arena&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Thread-local arena allocation; only works with @pinned tasks&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Combine with &lt;code&gt;:&lt;&#x2F;code&gt; — &lt;code&gt;@large:@arena&lt;&#x2F;code&gt; gives a large stack with arena allocation.&lt;&#x2F;p&gt;
&lt;p&gt;By v0.2 &lt;code&gt;@stateMachine&lt;&#x2F;code&gt; and &lt;code&gt;@stack&lt;&#x2F;code&gt; will be options.  The compiler will warn you when you should use a state machine, and block you from using it when it&#x27;s not an option.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;service-os-thread-spawning&quot;&gt;@service — OS Thread Spawning&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;@service&lt;&#x2F;code&gt; spawns a &lt;strong&gt;dedicated OS thread&lt;&#x2F;strong&gt; instead of a green fiber. Use it for heavy-compute tasks that won&#x27;t cooperatively yield - the OS handles preemption.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;p = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@service &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    trainModel(dataset);  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# runs on its own OS thread
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# fiber continues concurrently
&lt;&#x2F;span&gt;&lt;span&gt;result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT &lt;&#x2F;span&gt;&lt;span&gt;p;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# blocks fiber until OS thread finishes
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The OS thread gets its own Runtime with a 64 KB frame arena. No scheduler is involved - the thread runs independently until completion, then signals the Promise.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;When to use @service vs fibers:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Fibers (&lt;code&gt;@standard&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;@large&lt;&#x2F;code&gt;): I&#x2F;O-bound, short compute bursts, cooperative yielding&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;@service&lt;&#x2F;code&gt;: CPU-bound, long-running, no yields, true OS-level parallelism&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;captures&quot;&gt;Captures&lt;&#x2F;h3&gt;
&lt;p&gt;BG blocks capture outer variables &lt;strong&gt;by value&lt;&#x2F;strong&gt; (moved, not borrowed):&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;x = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;42.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;p = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ x + &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;; };  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# x is moved into the fiber
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# x is no longer usable here (affine ownership)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;then-chains&quot;&gt;THEN Chains&lt;&#x2F;h3&gt;
&lt;p&gt;Chain sequential steps inside a single fiber:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    fetch(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;https:&#x2F;&#x2F;api.example.com&#x2F;data&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; response
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN&lt;&#x2F;span&gt;&lt;span&gt; parse(response) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; parsed
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN&lt;&#x2F;span&gt;&lt;span&gt; transform(parsed);
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Each &lt;code&gt;AS name&lt;&#x2F;code&gt; binds the result for subsequent steps. The last step&#x27;s value becomes the promise result.&lt;&#x2F;p&gt;
&lt;p&gt;This is equivalent to:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    response = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; fetch(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;https:&#x2F;&#x2F;api.example.com&#x2F;data&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;    parsed = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; parse(response);
&lt;&#x2F;span&gt;&lt;span&gt;    transform(parsed);
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;THEN&lt;&#x2F;code&gt; is mostly useful for short-chained tasks, especially in a complex pipeline:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    fetch(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;https:&#x2F;&#x2F;api.example.com&#x2F;data1&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; r &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN&lt;&#x2F;span&gt;&lt;span&gt; parse(r),
&lt;&#x2F;span&gt;&lt;span&gt;    fetch(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;https:&#x2F;&#x2F;api.example.com&#x2F;data2&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; r &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN&lt;&#x2F;span&gt;&lt;span&gt; parse(r)
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# result = ~T[] -&amp;gt; this is only valid when all T are the same.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Error handling:&lt;&#x2F;strong&gt; use &lt;code&gt;OR&lt;&#x2F;code&gt; before the &lt;code&gt;AS&lt;&#x2F;code&gt; binding. If a step returns &lt;code&gt;!T&lt;&#x2F;code&gt;, handle it inline:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# ILLUSTRATIVE
&lt;&#x2F;span&gt;&lt;span&gt;result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    fetch(url) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR RAISE           &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# propagate error to caller
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; response &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN&lt;&#x2F;span&gt;&lt;span&gt; parse(response) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR&lt;&#x2F;span&gt;&lt;span&gt; default_value
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; parsed &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN&lt;&#x2F;span&gt;&lt;span&gt; transform(parsed);
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;OR RAISE&lt;&#x2F;code&gt; - propagate the error (caller sees it via &lt;code&gt;NEXT&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;OR value&lt;&#x2F;code&gt; - replace error with a fallback, chain continues&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;do-fork-join&quot;&gt;DO — Fork-Join&lt;&#x2F;h2&gt;
&lt;p&gt;Execute multiple branches concurrently, wait for all to complete:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# ILLUSTRATIVE
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DO &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    update_database(record),
&lt;&#x2F;span&gt;&lt;span&gt;    send_notification(user),
&lt;&#x2F;span&gt;&lt;span&gt;    log_event(event)
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# All three are done here.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Branches are separated by commas. Each runs in its own fiber. The DO block waits for all branches before continuing. Returns &lt;code&gt;Void&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;branch-modifiers&quot;&gt;Branch Modifiers&lt;&#x2F;h3&gt;
&lt;p&gt;Each branch can have its own modifiers:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# ILLUSTRATIVE
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DO &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@large &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; heavy_computation(),
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pinned &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; cache_local_work()
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;next-promise-resolution&quot;&gt;NEXT — Promise Resolution&lt;&#x2F;h2&gt;
&lt;p&gt;Block until a promise resolves:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;p: &lt;&#x2F;span&gt;&lt;span&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64 &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;42.0&lt;&#x2F;span&gt;&lt;span&gt;; };
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;result: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64 &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT &lt;&#x2F;span&gt;&lt;span&gt;p;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Promise Type&lt;&#x2F;th&gt;&lt;th&gt;NEXT returns&lt;&#x2F;th&gt;&lt;th&gt;Behavior&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Consumes the promise (one-shot)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~T @shared&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Returns cached result (safe for multiple NEXT)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~T[?]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;?T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Returns next value or nil (open stream)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~T[INF]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Returns next value, never nil (infinite stream)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;bg-stream-generators&quot;&gt;BG STREAM — Generators&lt;&#x2F;h2&gt;
&lt;p&gt;Spawn a fiber that yields values over time:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Open stream (finite)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;s: &lt;&#x2F;span&gt;&lt;span&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;[?] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG STREAM &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;9.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;v1 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; s;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 1.0
&lt;&#x2F;span&gt;&lt;span&gt;v2 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; s;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 4.0
&lt;&#x2F;span&gt;&lt;span&gt;v3 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; s;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 9.0
&lt;&#x2F;span&gt;&lt;span&gt;v4 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; s;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# NIL (exhausted)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Infinite stream
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;counter: &lt;&#x2F;span&gt;&lt;span&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;INF&lt;&#x2F;span&gt;&lt;span&gt;] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG STREAM &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; i = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHILE TRUE DO
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD&lt;&#x2F;span&gt;&lt;span&gt; i;
&lt;&#x2F;span&gt;&lt;span&gt;        i = i + &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;v1 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; counter;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 0.0
&lt;&#x2F;span&gt;&lt;span&gt;v2 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; counter;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 1.0 (blocks until generator yields)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;concurrent-parallel-pipelines&quot;&gt;CONCURRENT — Parallel Pipelines&lt;&#x2F;h2&gt;
&lt;p&gt;Apply pipeline operators in parallel with a persistent worker pool:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# ILLUSTRATIVE
&lt;&#x2F;span&gt;&lt;span&gt;results = items |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;workers: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; transform(_);
&lt;&#x2F;span&gt;&lt;span&gt;filtered = items |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;workers: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; predicate(_);
&lt;&#x2F;span&gt;&lt;span&gt;items |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;workers: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EACH &lt;&#x2F;span&gt;&lt;span&gt;{ _.value = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;; };
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;options&quot;&gt;Options&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Option&lt;&#x2F;th&gt;&lt;th&gt;Type&lt;&#x2F;th&gt;&lt;th&gt;Default&lt;&#x2F;th&gt;&lt;th&gt;Effect&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;workers&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Number&lt;&#x2F;td&gt;&lt;td&gt;8&lt;&#x2F;td&gt;&lt;td&gt;Number of persistent worker fibers&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;batch&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Number&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;Items each worker pulls per fetch from the shared index (larger = less index contention)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;capacity&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Number&lt;&#x2F;td&gt;&lt;td&gt;auto (worker count rounded up to a power of 2, clamped 4-64)&lt;&#x2F;td&gt;&lt;td&gt;Bounded channel ring-buffer size; only valid with a streaming &#x2F; &lt;code&gt;SHARD&lt;&#x2F;code&gt; &#x2F; range source&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;parallel&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Bool&lt;&#x2F;td&gt;&lt;td&gt;FALSE&lt;&#x2F;td&gt;&lt;td&gt;TRUE = distribute workers across schedulers (multi-core)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;size&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Identifier&lt;&#x2F;td&gt;&lt;td&gt;STANDARD&lt;&#x2F;td&gt;&lt;td&gt;Stack size: MICRO, STANDARD, LARGE, XL&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;supported-operators&quot;&gt;Supported Operators&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;CONCURRENT SELECT&lt;&#x2F;strong&gt; — parallel map. Returns transformed array (order preserved).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CONCURRENT WHERE&lt;&#x2F;strong&gt; — parallel filter. Returns matching elements (order preserved).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CONCURRENT EACH&lt;&#x2F;strong&gt; — parallel side effects. Returns Void.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;error-handling&quot;&gt;Error Handling&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Skip failed items
&lt;&#x2F;span&gt;&lt;span&gt;results = items
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;workers: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; risky_fn(_) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR PRUNE&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Propagate first error
&lt;&#x2F;span&gt;&lt;span&gt;results = items
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;workers: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; risky_fn(_) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR RAISE&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;how-it-works&quot;&gt;How It Works&lt;&#x2F;h3&gt;
&lt;p&gt;CONCURRENT spawns N persistent worker fibers that pull items from a shared atomic index. Zero per-item allocation — workers reuse their stack and context across all items. This is fundamentally different from spawning one fiber per item (which is what BG does).&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;results = items
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT BG &lt;&#x2F;span&gt;&lt;span&gt;{ risky_fn(_) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR RAISE &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# this is valid, but it would spawn N tasks, all at once.  It is NOT recommended.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;text&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-text &quot;&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;&lt;span&gt;Default (workers on local scheduler):
&lt;&#x2F;span&gt;&lt;span&gt;  CONCURRENT(workers: 8) SELECT transform(_)
&lt;&#x2F;span&gt;&lt;span&gt;  → 8 fibers on one thread, cooperative scheduling
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;Multi-core (workers distributed):
&lt;&#x2F;span&gt;&lt;span&gt;  CONCURRENT(workers: 8, parallel: TRUE) SELECT transform(_)
&lt;&#x2F;span&gt;&lt;span&gt;  → 8 fibers spread across all schedulers
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;performance&quot;&gt;Performance&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Pattern&lt;&#x2F;th&gt;&lt;th&gt;Per-item cost&lt;&#x2F;th&gt;&lt;th&gt;Use when&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;CONCURRENT(workers: N)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;~0 (atomic fetchAdd only)&lt;&#x2F;td&gt;&lt;td&gt;Bulk processing, batch transforms&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Individual &lt;code&gt;BG { }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;~60μs (GPA alloc)&lt;&#x2F;td&gt;&lt;td&gt;Dynamic spawning, I&#x2F;O-bound tasks&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;ul&gt;
&lt;li&gt;CONCURRENT is 30x faster than individual BG spawns for batch workloads.&lt;&#x2F;li&gt;
&lt;li&gt;For I&#x2F;O-bound tasks (network requests, file reads), the 60μs BG spawn cost is negligible compared to I&#x2F;O latency.&lt;&#x2F;li&gt;
&lt;li&gt;The big benefit is that &lt;code&gt;workers: N&lt;&#x2F;code&gt; handles backpressure to avoid spawning more tasks than you can handle.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;multi-threading&quot;&gt;Multi-Threading&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR defaults to single-threaded scheduling. Set &lt;code&gt;CLEAR_THREADS&lt;&#x2F;code&gt; to enable multi-core:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLEAR_THREADS&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;.&#x2F;my_program   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# auto-detect CPU count
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLEAR_THREADS&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;4 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;.&#x2F;my_program   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 4 scheduler threads
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLEAR_THREADS&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;.&#x2F;my_program   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# single-threaded (default)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Each scheduler thread runs its own event loop with work stealing. Idle schedulers steal tasks from busy ones. &lt;code&gt;@pinned&lt;&#x2F;code&gt; tasks are exempt from stealing.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;safety-rules&quot;&gt;Safety Rules&lt;&#x2F;h2&gt;
&lt;p&gt;The compiler enforces these at compile time:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Rule&lt;&#x2F;th&gt;&lt;th&gt;Reason&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@parallel&lt;&#x2F;code&gt; + &lt;code&gt;@local&lt;&#x2F;code&gt; = error&lt;&#x2F;td&gt;&lt;td&gt;@local has no synchronization&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@parallel&lt;&#x2F;code&gt; + &lt;code&gt;@multiowned&lt;&#x2F;code&gt; = error&lt;&#x2F;td&gt;&lt;td&gt;Rc is non-atomic; use @shared (Arc)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@arena&lt;&#x2F;code&gt; + &lt;code&gt;@parallel&lt;&#x2F;code&gt; = error&lt;&#x2F;td&gt;&lt;td&gt;Arena memory is thread-local&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Non-@pinned BG capturing from @pinned scope = error&lt;&#x2F;td&gt;&lt;td&gt;Thread-local memory would escape&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;YIELD&lt;&#x2F;code&gt; outside BG STREAM = error&lt;&#x2F;td&gt;&lt;td&gt;YIELD only valid in generators&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;NEXT&lt;&#x2F;code&gt; on non-promise = error&lt;&#x2F;td&gt;&lt;td&gt;Can only await promises and streams&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;when-to-use-what&quot;&gt;When to Use What&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Goal&lt;&#x2F;th&gt;&lt;th&gt;Construct&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Process a batch of items&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; CONCURRENT(workers: N) SELECT&#x2F;WHERE&#x2F;EACH&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Fire off a background task&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;BG { work(); }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Run independent tasks concurrently&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;DO { task1(), task2(), task3() }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Generate values lazily&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;BG STREAM { YIELD ...; }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Chain async steps&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;BG { step1() AS r THEN step2(r) }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Handle requests (server)&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;BG { @pinned:@arena -&amp;gt; handle(conn); }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;known-limitations-v0-1&quot;&gt;Known Limitations (v0.1)&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;strong&gt;Dynamic spawn overhead&lt;&#x2F;strong&gt;: spawning many individual &lt;code&gt;BG&lt;&#x2F;code&gt; tasks is competitive with Go at moderate thread counts (roughly parity at 8 threads on the 100K-spawn benchmark) but slower at high core counts — about 1.6x Go at small scale, up to ~3.5x at 32 threads. The remaining gap is idle schedulers spinning on the work-stealing deque instead of parking, not per-spawn allocation. Workaround: use &lt;code&gt;CONCURRENT(workers: N)&lt;&#x2F;code&gt; for bulk workloads. Scheduler parking (the fix) is tracked for post-v0.1.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;No general bounded channel&lt;&#x2F;strong&gt;: CLEAR has Promises (one-shot) and Streams (unbounded). &lt;code&gt;CONCURRENT&lt;&#x2F;code&gt; streaming uses an internal bounded ring-buffer channel for backpressure (tunable via the &lt;code&gt;capacity:&lt;&#x2F;code&gt; option), but there is no general user-facing bounded producer&#x2F;consumer channel primitive yet.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Pipelines and Higher-Order Functions</title>
        <published>2026-03-26T00:00:00+00:00</published>
        <updated>2026-05-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/pipelines/"/>
        <id>https://cuzzo.github.io/clear/docs/pipelines/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/pipelines/">&lt;p&gt;CLEAR&#x27;s pipeline system lets you transform, filter, aggregate, and iterate collections using the smooth operator (&lt;code&gt;|&amp;gt;&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;Every pipeline operator works on arrays, &lt;code&gt;@list&lt;&#x2F;code&gt;, &lt;code&gt;@pool&lt;&#x2F;code&gt;, sharded collections, &lt;code&gt;@pool:soa&lt;&#x2F;code&gt;, streams &lt;code&gt;~T[]&lt;&#x2F;code&gt;, etc - the same syntax regardless of the underlying storage.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;_&lt;&#x2F;code&gt; is the placeholder value for the value being iterated over.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;scores
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _ &amp;lt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;50 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;users 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; _.name 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DISTINCT&lt;&#x2F;span&gt;&lt;span&gt; _;
&lt;&#x2F;span&gt;&lt;span&gt;  
&lt;&#x2F;span&gt;&lt;span&gt;entities 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EACH &lt;&#x2F;span&gt;&lt;span&gt;{ _.health = _.health - &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;; };
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This document describes both the collection pipeline model and the stream&#x2F;future pipeline surface. The full operator set is supported for finite streams (&lt;code&gt;~T[]&lt;&#x2F;code&gt;, &lt;code&gt;~T[N]&lt;&#x2F;code&gt;); infinite streams (&lt;code&gt;~T[INF]&lt;&#x2F;code&gt;) require &lt;code&gt;LIMIT&lt;&#x2F;code&gt; to bound them and then support all non-materialization operators.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-smooth-operator&quot;&gt;The Smooth Operator (&lt;code&gt;|&amp;gt;&lt;&#x2F;code&gt;)&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;|&amp;gt;&lt;&#x2F;code&gt; pipes a value into a function or operator. It&#x27;s CLEAR&#x27;s equivalent of &lt;code&gt;|&amp;gt;&lt;&#x2F;code&gt; (Elixir) or &lt;code&gt;.&lt;&#x2F;code&gt; method chaining (Ruby), but it also works with collection operators.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Pipe to a function: x |&amp;gt; f  →  f(x)
&lt;&#x2F;span&gt;&lt;span&gt;result = data 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; process 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; validate
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; format;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Pipe to an operator: list |&amp;gt; WHERE predicate
&lt;&#x2F;span&gt;&lt;span&gt;alive = entities 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.health &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Pipelines chain left to right. Each stage passes its result to the next.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;named-pipeline-bindings-as-v&quot;&gt;Named Pipeline Bindings (&lt;code&gt;AS $v&lt;&#x2F;code&gt;)&lt;&#x2F;h2&gt;
&lt;p&gt;The &lt;code&gt;AS $v&lt;&#x2F;code&gt; syntax binds the current pipeline element to a named reference that persists across subsequent stages.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;bill = users &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS $u
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNNEST $u&lt;&#x2F;span&gt;&lt;span&gt;.orders
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.price * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;$u&lt;&#x2F;span&gt;&lt;span&gt;.discount;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;why-bindings-exist&quot;&gt;Why bindings exist&lt;&#x2F;h3&gt;
&lt;p&gt;Without a binding, &lt;code&gt;_&lt;&#x2F;code&gt; always refers to the &lt;em&gt;current&lt;&#x2F;em&gt; element - the item being iterated at the innermost level. After &lt;code&gt;UNNEST&lt;&#x2F;code&gt;, &lt;code&gt;_&lt;&#x2F;code&gt; becomes each inner element (an Order), and the outer element (the User) is no longer reachable.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Without AS $u: $u is not available inside the fold.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# `_` after UNNEST is the Order, not the User.
&lt;&#x2F;span&gt;&lt;span&gt;bill = users
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNNEST&lt;&#x2F;span&gt;&lt;span&gt; _.orders
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.price;         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# can access order.price, but NOT user.discount
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;AS $u&lt;&#x2F;code&gt; captures the outer element before the &lt;code&gt;UNNEST&lt;&#x2F;code&gt; replaces &lt;code&gt;_&lt;&#x2F;code&gt;, keeping it accessible:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;bill = users &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS $u
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNNEST $u&lt;&#x2F;span&gt;&lt;span&gt;.orders     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# $u = the User; _ = each Order
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.price * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;$u&lt;&#x2F;span&gt;&lt;span&gt;.discount;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# cross-reference: order.price * user.discount
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The compiler fuses this into a single nested loop with no intermediate allocations.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;scope-of-a-binding&quot;&gt;Scope of a binding&lt;&#x2F;h3&gt;
&lt;p&gt;A binding created with &lt;code&gt;AS $v&lt;&#x2F;code&gt; is visible from the point of declaration to the end of the pipeline expression. It cannot be used after the pipeline terminates:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;bill = users &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS $u
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNNEST $u&lt;&#x2F;span&gt;&lt;span&gt;.orders   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# $u is in scope
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.qty &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# $u still in scope
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.price * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;$u&lt;&#x2F;span&gt;&lt;span&gt;.discount;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# $u still in scope
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# $u is not accessible here (out of scope after the pipeline ends)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Multiple pipelines in the same function can each use their own &lt;code&gt;$u&lt;&#x2F;code&gt; - bindings are scoped to the pipeline expression, not the function.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;naming-the-inner-element-as-o&quot;&gt;Naming the inner element (AS $o)&lt;&#x2F;h3&gt;
&lt;p&gt;When you UNNEST and need a name for the inner element (instead of &lt;code&gt;_&lt;&#x2F;code&gt;), use a second binding after the UNNEST expression:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;bill = users &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS $u
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNNEST $u&lt;&#x2F;span&gt;&lt;span&gt;.orders &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS $o    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# $u = User, $o = Order
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM $o&lt;&#x2F;span&gt;&lt;span&gt;.price * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;$u&lt;&#x2F;span&gt;&lt;span&gt;.discount;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;AS $o&lt;&#x2F;code&gt; after the UNNEST expression binds the inner element. Both &lt;code&gt;$u&lt;&#x2F;code&gt; and &lt;code&gt;$o&lt;&#x2F;code&gt; are available in the fold.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;supported-combinations&quot;&gt;Supported combinations&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;UNNEST binding chains&lt;&#x2F;strong&gt; - fold operators that work after &lt;code&gt;AS $u |&amp;gt; UNNEST&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Fold&lt;&#x2F;th&gt;&lt;th&gt;Example&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;SUM&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; SUM _.price * $u.discount&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;COUNT&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; COUNT TRUE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;AVERAGE&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; AVERAGE _.price&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;MIN&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; MIN _.price&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;MAX&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; MAX _.price&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;ANY&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; ANY _.price &amp;gt; 50.0&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;ALL&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; ALL $u.discount &amp;gt; 0.0&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;FIND&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;|&amp;gt; FIND _.price &amp;gt; 10.0&lt;&#x2F;code&gt; (returns &lt;code&gt;?ElemType&lt;&#x2F;code&gt;)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Intermediate &lt;code&gt;WHERE&lt;&#x2F;code&gt; stages filter the inner elements before the fold:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;total = users &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS $u
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNNEST $u&lt;&#x2F;span&gt;&lt;span&gt;.orders
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.qty &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# filter inner elements
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.price * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;$u&lt;&#x2F;span&gt;&lt;span&gt;.discount;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;SELECT&lt;&#x2F;code&gt; is not supported in UNNEST binding chains (the inner projection would lose the &lt;code&gt;$u&lt;&#x2F;code&gt; context). Use field access in the fold expression instead.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;CONCURRENT binding&lt;&#x2F;strong&gt; - &lt;code&gt;$u&lt;&#x2F;code&gt; is also accessible inside &lt;code&gt;CONCURRENT&lt;&#x2F;code&gt; stages that operate directly on the bound list (without an intermediate UNNEST):&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;Example&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;CONCURRENT SELECT&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;AS $u |&amp;gt; CONCURRENT SELECT $u.val * 2.0&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;CONCURRENT SUM&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;AS $u |&amp;gt; CONCURRENT SUM $u.score&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;CONCURRENT COUNT&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;AS $u |&amp;gt; CONCURRENT COUNT $u.active&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;CONCURRENT MIN&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;AS $u |&amp;gt; CONCURRENT MIN $u.score&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;CONCURRENT MAX&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;AS $u |&amp;gt; CONCURRENT MAX $u.score&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;CONCURRENT AVERAGE&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;AS $u |&amp;gt; CONCURRENT AVERAGE $u.score&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;CONCURRENT WHERE&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;AS $u |&amp;gt; CONCURRENT WHERE $u.score &amp;gt; 50.0&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;In all concurrent cases, &lt;code&gt;$u&lt;&#x2F;code&gt; resolves to the item being processed by the current worker.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-variable&quot;&gt;The &lt;code&gt;_&lt;&#x2F;code&gt; Variable&lt;&#x2F;h2&gt;
&lt;p&gt;Inside pipeline expressions, &lt;code&gt;_&lt;&#x2F;code&gt; refers to the current element. For struct elements, access fields with &lt;code&gt;_.fieldname&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# _ is the element itself (for scalar collections)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;nums: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;[] = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;7.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;9.0&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;big = nums 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _ &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;5.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; length(big) == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;WHERE filters by element value&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# _.field for struct collections
&lt;&#x2F;span&gt;&lt;span&gt;users = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;}, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;bob&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;}];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;names = users
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; _.name;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;scores = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Score&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10.0&lt;&#x2F;span&gt;&lt;span&gt;}, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Score&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20.0&lt;&#x2F;span&gt;&lt;span&gt;}];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;total = scores 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.value;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; total == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;30.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;SUM aggregates field values&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In EACH blocks, &lt;code&gt;_&lt;&#x2F;code&gt; is mutable — you can assign to fields:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;pool 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EACH &lt;&#x2F;span&gt;&lt;span&gt;{ _.health = _.health - damage; };
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;operators&quot;&gt;Operators&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;transform&quot;&gt;Transform&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;Syntax&lt;&#x2F;th&gt;&lt;th&gt;Returns&lt;&#x2F;th&gt;&lt;th&gt;Description&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;SELECT&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; SELECT expr&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;ExprType[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Project each element through an expression&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;WHERE&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; WHERE pred&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;ElemType[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Keep elements matching a boolean predicate&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;ORDER_BY&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; ORDER_BY key&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;ElemType[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Sort by key expression&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;LIMIT&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; LIMIT n&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;ElemType[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;First N elements&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;SKIP&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; SKIP n&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;ElemType[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Drop first N elements, return rest&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;DISTINCT&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; DISTINCT key&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;ElemType[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Unique by key (first occurrence wins)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;UNNEST&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; UNNEST expr&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;InnerType[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Flatten nested arrays (flatmap)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;INDEX&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; INDEX key&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;HashMap&amp;lt;ElemType[]&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Group into a hashmap by key&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;SELECT accepts any expression, including struct literals. This lets you project into a different struct type in one step:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Raw     &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;score: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Summary &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;key: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;normalized: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;raws: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Raw&lt;&#x2F;span&gt;&lt;span&gt;[] = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Raw&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;score: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100.0 &lt;&#x2F;span&gt;&lt;span&gt;}, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Raw&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;score: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;200.0 &lt;&#x2F;span&gt;&lt;span&gt;}];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;summaries = raws |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT Summary&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;key:&lt;&#x2F;span&gt;&lt;span&gt; _.id, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;normalized:&lt;&#x2F;span&gt;&lt;span&gt; _.score &#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100.0 &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; summaries[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;].key == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;id preserved&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; summaries[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;].normalized == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;score normalized&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The result type is inferred from the expression - &lt;code&gt;Summary[]&lt;&#x2F;code&gt; above, not &lt;code&gt;Raw[]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Pipeline fusion with SELECT T{}:&lt;&#x2F;strong&gt; SELECT composes with WHERE and aggregates in a single fused loop - no intermediate list allocation:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# WHERE before SELECT: filter on the raw element (efficient)
&lt;&#x2F;span&gt;&lt;span&gt;high = raws
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.score &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;75.0
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT Summary&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;key:&lt;&#x2F;span&gt;&lt;span&gt; _.id, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;normalized:&lt;&#x2F;span&gt;&lt;span&gt; _.score &#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100.0 &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# SELECT before aggregate: project then sum&#x2F;min&#x2F;max a field
&lt;&#x2F;span&gt;&lt;span&gt;total = raws
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT Summary&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;key:&lt;&#x2F;span&gt;&lt;span&gt; _.id, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;normalized:&lt;&#x2F;span&gt;&lt;span&gt; _.score &#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100.0 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.normalized;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# SELECT before WHERE: build struct first, then filter on a struct field (less efficient)
&lt;&#x2F;span&gt;&lt;span&gt;norm_high = raws
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT Summary&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;key:&lt;&#x2F;span&gt;&lt;span&gt; _.id, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;normalized:&lt;&#x2F;span&gt;&lt;span&gt; _.score &#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100.0 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.normalized &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0.75&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;When SELECT precedes a fold or WHERE, the compiler binds the projected value to a temp variable per iteration. This avoids the Zig restriction on struct literals in arithmetic&#x2F;boolean expression positions, so the generated code is always valid without changing semantics.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;aggregate&quot;&gt;Aggregate&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;Syntax&lt;&#x2F;th&gt;&lt;th&gt;Returns&lt;&#x2F;th&gt;&lt;th&gt;Empty list&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;SUM&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; SUM expr&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Int64 &#x2F; UInt64 &#x2F; Float32 &#x2F; Float64&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;AVERAGE&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; AVERAGE expr&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Float64&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;MIN&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; MIN expr&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;matches expr type&lt;&#x2F;td&gt;&lt;td&gt;panics&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;MAX&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; MAX expr&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;matches expr type&lt;&#x2F;td&gt;&lt;td&gt;panics&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;REDUCE&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; REDUCE(init) expr&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;type of init&lt;&#x2F;td&gt;&lt;td&gt;init&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;The return type is driven by the expression type. SUM widens small integers to &lt;code&gt;Int64&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;UInt64&lt;&#x2F;code&gt;; floats stay at their original width (&lt;code&gt;Float32&lt;&#x2F;code&gt; stays &lt;code&gt;Float32&lt;&#x2F;code&gt;). AVERAGE always returns &lt;code&gt;Float64&lt;&#x2F;code&gt;. MIN and MAX preserve the exact expression type. REDUCE is the general fold - &lt;code&gt;acc&lt;&#x2F;code&gt; is the mutable accumulator, &lt;code&gt;_&lt;&#x2F;code&gt; is the current element:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;nums: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;[] = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4.0&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;product = nums 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REDUCE&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;) acc * _;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; product == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;24.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;REDUCE multiplies 2*3*4&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;query&quot;&gt;Query&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;Syntax&lt;&#x2F;th&gt;&lt;th&gt;Returns&lt;&#x2F;th&gt;&lt;th&gt;Description&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;COUNT&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; COUNT pred&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Int64&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Number of matches&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;ANY&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; ANY pred&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Bool&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;True if any match (short-circuits)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;ALL&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; ALL pred&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Bool&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;True if all match (short-circuits)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;FIND&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; FIND pred&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;?ElemType&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;First match or null&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;side-effects&quot;&gt;Side Effects&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;Syntax&lt;&#x2F;th&gt;&lt;th&gt;Returns&lt;&#x2F;th&gt;&lt;th&gt;Description&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;EACH&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; EACH { body }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Void&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Iterate with mutable &lt;code&gt;_&lt;&#x2F;code&gt;; side-effect only&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;TAP&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list |&amp;gt; TAP { body }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;ElemType[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Observe each element (read-only &lt;code&gt;_&lt;&#x2F;code&gt;), pass collection through&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;EACH is the only operator where &lt;code&gt;_&lt;&#x2F;code&gt; is mutable. Use it for in-place updates:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;entities 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EACH &lt;&#x2F;span&gt;&lt;span&gt;{ _.x = _.x + _.vx; _.y = _.y + _.vy; };
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;tap-debugging-observation&quot;&gt;TAP (Debugging &#x2F; Observation)&lt;&#x2F;h3&gt;
&lt;p&gt;TAP runs a body for each element but passes the collection through unchanged. Unlike EACH, &lt;code&gt;_&lt;&#x2F;code&gt; is read-only and TAP returns the original collection:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;result = scores
&lt;&#x2F;span&gt;&lt;span&gt;    |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.points &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100
&lt;&#x2F;span&gt;&lt;span&gt;    |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TAP &lt;&#x2F;span&gt;&lt;span&gt;{ print(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;score: ${_.points.toString()}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;); }
&lt;&#x2F;span&gt;&lt;span&gt;    |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.points;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;window-sliding-window&quot;&gt;WINDOW (Sliding Window)&lt;&#x2F;h3&gt;
&lt;p&gt;WINDOW produces a sliding window of size N over the collection. &lt;code&gt;_&lt;&#x2F;code&gt; inside the body is the sub-slice (a &lt;code&gt;Float64[]&lt;&#x2F;code&gt; or &lt;code&gt;ElemType[]&lt;&#x2F;code&gt; of length N). The result is an array of the body expression evaluated per window.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;data: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;[] = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;5.0&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Each window is a 3-element slice; body projects to window length
&lt;&#x2F;span&gt;&lt;span&gt;lengths = data |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WINDOW&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;) _.length();
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; lengths.length() == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;5 elements, window 3 -&amp;gt; 3 windows&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Access individual elements in the window
&lt;&#x2F;span&gt;&lt;span&gt;firsts = data |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WINDOW&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;) _[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; firsts[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;] == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;first element of first window&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Number of result windows = &lt;code&gt;max(0, len - size + 1)&lt;&#x2F;code&gt;. A window larger than the list produces an empty result.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;window-batch-tumbling-window&quot;&gt;WINDOW (Batch &#x2F; Tumbling Window)&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;WINDOW(size: N)&lt;&#x2F;code&gt;, &lt;code&gt;WINDOW(time: &#x27;Xms&#x27;)&lt;&#x2F;code&gt;, or &lt;code&gt;WINDOW(size: N, time: &#x27;Xms&#x27;)&lt;&#x2F;code&gt; produces non-overlapping batches. &lt;code&gt;_&lt;&#x2F;code&gt; inside the body is a &lt;code&gt;T[]&lt;&#x2F;code&gt; batch. The result is a heap-allocated list of the body expression evaluated per batch.&lt;&#x2F;p&gt;
&lt;p&gt;Flush conditions (checked after every item):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;size: N&lt;&#x2F;code&gt; - flush when the batch accumulates N items&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;time: &#x27;Xms&#x27;&lt;&#x2F;code&gt; - flush when elapsed time since the first item in the batch &amp;gt;= timeout; time units: &lt;code&gt;ms&lt;&#x2F;code&gt;, &lt;code&gt;s&lt;&#x2F;code&gt;, &lt;code&gt;min&lt;&#x2F;code&gt;, &lt;code&gt;h&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Both specified - flush on whichever fires first (first-of-either)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;A partial batch at the end is always included. Works on all source types: arrays, &lt;code&gt;~T[]&lt;&#x2F;code&gt;, &lt;code&gt;~T[N]&lt;&#x2F;code&gt;, and &lt;code&gt;~T[INF]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; sumBatch(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;batch: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;[]) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Int64 &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;s: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64 &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    batch |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EACH &lt;&#x2F;span&gt;&lt;span&gt;{ s = s + _; };
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; s;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Array source, size-only: [1..7] -&amp;gt; [1,2,3], [4,5,6], [7]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;arr: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;[] = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;6&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;7&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;sums = arr |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WINDOW&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;size: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;) sumBatch(_);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; sums.length() == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;;   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 3 batches
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; sums[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;] == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;7&lt;&#x2F;span&gt;&lt;span&gt;;         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# partial final batch
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Open stream, size + time (first-of-either)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;gen: &lt;&#x2F;span&gt;&lt;span&gt;~?Int64[] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG STREAM &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;i: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64 &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHILE&lt;&#x2F;span&gt;&lt;span&gt; i &amp;lt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DO YIELD&lt;&#x2F;span&gt;&lt;span&gt; i; i = i + &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;sums2 = gen |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WINDOW&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;size: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;time: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;500ms&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) sumBatch(_);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; sums2.length() == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# [1-4], [5-8], [9-10]
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Time-only: entire array arrives fast, all items in one final batch
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;arr2: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;[] = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;200&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;300&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;lens = arr2 |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WINDOW&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;time: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;1s&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) _.length();
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; lens[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;] == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# one batch of 3
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;&#x2F;strong&gt; The sliding-window form &lt;code&gt;WINDOW(N)&lt;&#x2F;code&gt; (positional integer, no named params) is the existing collection-only operator above. The named-param form &lt;code&gt;WINDOW(size:, time:)&lt;&#x2F;code&gt; is the new batching operator and works on both collections and streams.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;join-left-outer-join&quot;&gt;JOIN (Left Outer Join)&lt;&#x2F;h3&gt;
&lt;p&gt;JOIN performs a left outer join between two collections using a two-parameter lambda predicate. Every element of the left collection appears in the result exactly once; the right field is &lt;code&gt;NIL&lt;&#x2F;code&gt; when no right element matches.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT User &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span&gt;String }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Order &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;userId: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;amount: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;results = users |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;JOIN&lt;&#x2F;span&gt;&lt;span&gt;(orders) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;%(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;u, o&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;) &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; u.id == o.userId;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# results: JoinResult_User_Order[]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# results[i].left  -- the User
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# results[i].right -- ?Order (NIL if no match)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The result element type is an anonymous struct &lt;code&gt;{ left: L, right: ?R }&lt;&#x2F;code&gt;. The lambda must take exactly two parameters (left element, right element) and return Bool.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;stream-and-future-compatibility&quot;&gt;Stream and Future Compatibility&lt;&#x2F;h2&gt;
&lt;p&gt;Pipelines over futures&#x2F;streams are currently supported in a narrower subset than pipelines over collections.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;stream-kinds&quot;&gt;Stream kinds&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Type&lt;&#x2F;th&gt;&lt;th&gt;Meaning&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;NEXT&lt;&#x2F;code&gt; result&lt;&#x2F;th&gt;&lt;th&gt;Pipeline support&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Single future value&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Not a pipeline source&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~?T[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Open stream&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;?T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Not a pipeline source yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~T[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Finite dynamic stream&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;?T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Full non-concurrent operator set (see table)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~T[N]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Finite bounded stream&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;?T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Full non-concurrent operator set plus &lt;code&gt;CONCURRENT EACH&#x2F;SELECT&#x2F;WHERE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;~T[INF]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Infinite stream&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Fusible stages + all terminals via &lt;code&gt;LIMIT&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;operator-support-matrix&quot;&gt;Operator support matrix&lt;&#x2F;h3&gt;
&lt;p&gt;The columns are the three pipeline-capable stream types. &quot;Stage&quot; operators filter or transform in a fused while loop without materializing; &quot;terminal&quot; operators consume the stream and produce a scalar or collection result.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;stages-fusible-zero-intermediate-allocations&quot;&gt;Stages (fusible, zero intermediate allocations)&lt;&#x2F;h4&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[N]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[INF]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;WHERE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes (LIMIT must appear in chain)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;SELECT&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes (LIMIT must appear in chain)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;SKIP&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes (LIMIT must appear in chain)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TAKE_WHILE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes (LIMIT must appear in chain)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;LIMIT&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes - converts stream to &lt;code&gt;T[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;TAP&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;&lt;code&gt;LIMIT&lt;&#x2F;code&gt; can appear anywhere in the chain relative to other fusible stages. The compiler fuses the entire chain into a single while loop - &lt;code&gt;counter |&amp;gt; WHERE _ &amp;gt; 0 |&amp;gt; LIMIT 5 |&amp;gt; EACH&lt;&#x2F;code&gt; and &lt;code&gt;counter |&amp;gt; LIMIT 5 |&amp;gt; WHERE _ &amp;gt; 0 |&amp;gt; EACH&lt;&#x2F;code&gt; both work; they differ only in whether LIMIT counts pre- or post-filter items.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;fold-terminals-produce-a-scalar-or-optional-value&quot;&gt;Fold terminals (produce a scalar or optional value)&lt;&#x2F;h4&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[N]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[INF]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;EACH&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;SUM&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;COUNT&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;AVERAGE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;MIN&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;MAX&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;ANY&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;ALL&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;FIND&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;REDUCE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;&quot;via LIMIT&quot; means LIMIT must appear earlier in the same pipeline chain. LIMIT converts &lt;code&gt;~T[INF]&lt;&#x2F;code&gt; to &lt;code&gt;T[]&lt;&#x2F;code&gt; (a regular list); the fold terminal then operates on that list. Example: &lt;code&gt;counter |&amp;gt; WHERE _ &amp;gt; 0 |&amp;gt; LIMIT 5 |&amp;gt; SUM _&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;materialization-terminals-produce-a-new-collection&quot;&gt;Materialization terminals (produce a new collection)&lt;&#x2F;h4&gt;
&lt;p&gt;These operators consume the stream and produce a new heap-allocated collection.
&lt;code&gt;DISTINCT&lt;&#x2F;code&gt; and &lt;code&gt;INDEX&lt;&#x2F;code&gt; are fully supported for all stream types; others require
materializing first with &lt;code&gt;.toList()&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[N]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[INF]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;DISTINCT&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes - returns &lt;code&gt;T[]@set&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes - returns &lt;code&gt;T[]@set&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT - returns &lt;code&gt;T[]@set&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;INDEX&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;via LIMIT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;ORDER_BY&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;UNNEST&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;WINDOW(N)&lt;&#x2F;code&gt; (sliding)&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;WINDOW(size:, time:)&lt;&#x2F;code&gt; (batch)&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;JOIN&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;&quot;via LIMIT&quot; means &lt;code&gt;LIMIT&lt;&#x2F;code&gt; must appear earlier in the chain (same rule as fold terminals).
&lt;code&gt;DISTINCT&lt;&#x2F;code&gt; returns &lt;code&gt;T[]@set&lt;&#x2F;code&gt; (a Set), supporting &lt;code&gt;.count()&lt;&#x2F;code&gt; and &lt;code&gt;.contains?()&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you need &lt;code&gt;ORDER_BY&lt;&#x2F;code&gt;, &lt;code&gt;UNNEST&lt;&#x2F;code&gt;, sliding &lt;code&gt;WINDOW(N)&lt;&#x2F;code&gt;, or &lt;code&gt;JOIN&lt;&#x2F;code&gt; on a stream, materialize first.
The batching &lt;code&gt;WINDOW(size:, time:)&lt;&#x2F;code&gt; operator works directly on streams without materialization.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;s: &lt;&#x2F;span&gt;&lt;span&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;[] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;..&amp;lt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;vals = s.toList();
&lt;&#x2F;span&gt;&lt;span&gt;total = vals 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _ &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h4 id=&quot;concurrent-operators&quot;&gt;Concurrent operators&lt;&#x2F;h4&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operator&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[N]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;~T[INF]&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;CONCURRENT EACH&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;CONCURRENT SELECT&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;CONCURRENT WHERE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;td&gt;yes&lt;&#x2F;td&gt;&lt;td&gt;not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;&lt;code&gt;~T[N]&lt;&#x2F;code&gt; concurrent pipelines are native: they consume promise slots directly without materializing through &lt;code&gt;.toList()&lt;&#x2F;code&gt;, and lower through MIR-visible builtin helpers. Example:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;nums: &lt;&#x2F;span&gt;&lt;span&gt;~&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;] = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;; }, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2.0&lt;&#x2F;span&gt;&lt;span&gt;; }, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3.0&lt;&#x2F;span&gt;&lt;span&gt;; }, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4.0&lt;&#x2F;span&gt;&lt;span&gt;; }];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;doubled = nums 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;workers: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; _ * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Direct range expressions still use the non-concurrent path unless first bound as &lt;code&gt;~T[N]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;open-streams&quot;&gt;Open streams&lt;&#x2F;h3&gt;
&lt;p&gt;Open streams (&lt;code&gt;~?T[]&lt;&#x2F;code&gt;) are still &lt;code&gt;NEXT&lt;&#x2F;code&gt;-driven only:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;gen: &lt;&#x2F;span&gt;&lt;span&gt;~?Int64[] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG STREAM &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;YIELD &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;v1 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; gen;
&lt;&#x2F;span&gt;&lt;span&gt;v2 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; gen;
&lt;&#x2F;span&gt;&lt;span&gt;v3 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NEXT&lt;&#x2F;span&gt;&lt;span&gt; gen;     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# NIL
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;skip-and-limit-pagination&quot;&gt;SKIP and LIMIT (Pagination)&lt;&#x2F;h3&gt;
&lt;p&gt;SKIP and LIMIT are complementary: SKIP drops the first N elements, LIMIT takes the first N.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Pagination: page 3, 10 items per page
&lt;&#x2F;span&gt;&lt;span&gt;page = items 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SKIP &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;LIMIT &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Skip header row, process the rest
&lt;&#x2F;span&gt;&lt;span&gt;data = rows 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SKIP &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; parseRow;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;chaining&quot;&gt;Chaining&lt;&#x2F;h2&gt;
&lt;p&gt;Operators compose naturally:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Filter, sort, take top 3
&lt;&#x2F;span&gt;&lt;span&gt;leaderboard = scores
&lt;&#x2F;span&gt;&lt;span&gt;    |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.points &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100
&lt;&#x2F;span&gt;&lt;span&gt;    |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ORDER_BY&lt;&#x2F;span&gt;&lt;span&gt; _.points
&lt;&#x2F;span&gt;&lt;span&gt;    |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;LIMIT &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Count active users with high scores
&lt;&#x2F;span&gt;&lt;span&gt;n = users
&lt;&#x2F;span&gt;&lt;span&gt;    |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.active == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TRUE
&lt;&#x2F;span&gt;&lt;span&gt;    |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;COUNT&lt;&#x2F;span&gt;&lt;span&gt; _.score &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;collection-compatibility&quot;&gt;Collection Compatibility&lt;&#x2F;h2&gt;
&lt;p&gt;Every operator works on every collection type:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Array
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;nums: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;[] = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;total = nums 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# List
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; data = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;List&lt;&#x2F;span&gt;&lt;span&gt;[];
&lt;&#x2F;span&gt;&lt;span&gt;avg = data 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AVERAGE&lt;&#x2F;span&gt;&lt;span&gt; _.value;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Pool
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;pool: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Entity&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span&gt;alive = pool 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _.health &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Pool with SOA (field-slice iteration — cache-optimal)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;soa_pool: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Entity&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:soa &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span&gt;total_hp = soa_pool 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.health;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# iterates only the health array
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# List with SOA
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;soa_list: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Entity&lt;&#x2F;span&gt;&lt;span&gt;[]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@list&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:soa &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span&gt;avg = soa_list 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AVERAGE&lt;&#x2F;span&gt;&lt;span&gt; _.health;   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# contiguous f64 slice
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Sharded (parallel EACH via DO blocks)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;sharded: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Entity&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;) = [];
&lt;&#x2F;span&gt;&lt;span&gt;sharded 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;EACH &lt;&#x2F;span&gt;&lt;span&gt;{ _.processed = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TRUE&lt;&#x2F;span&gt;&lt;span&gt;; };
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;loop-fusion&quot;&gt;Loop Fusion&lt;&#x2F;h2&gt;
&lt;p&gt;The compiler automatically fuses chains of WHERE and SELECT stages ending in a fold (SUM, REDUCE, AVERAGE, MIN, MAX, COUNT, ANY, ALL, FIND) into a single loop with zero intermediate allocations.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Written as 3 stages:
&lt;&#x2F;span&gt;&lt;span&gt;result = data 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHERE&lt;&#x2F;span&gt;&lt;span&gt; _ &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;500.0 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; _ * _ 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Compiled as a single loop (no intermediate arrays):
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# for (data) |it| { if (it &amp;gt; 500) { sum += it * it; } }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This eliminates the allocation and iteration overhead of intermediate lists. Stages that require materialization (ORDER_BY, DISTINCT, INDEX) break the fusion chain - operations before them are fused separately.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;soa-optimization&quot;&gt;SOA Optimization&lt;&#x2F;h2&gt;
&lt;p&gt;When a &lt;code&gt;@pool:soa&lt;&#x2F;code&gt; is used in a pipeline, the compiler rewrites field accesses to iterate directly over contiguous field arrays instead of striding over whole structs. This happens automatically for all operators — no syntax change needed.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Entity &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;vx: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;vy: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;health: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;pool: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Entity&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:soa &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# SUM _.health iterates only the health array (contiguous f64[]).
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Without :soa, it would load all 5 fields per element.
&lt;&#x2F;span&gt;&lt;span&gt;total = pool 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SUM&lt;&#x2F;span&gt;&lt;span&gt; _.health;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For WHERE and FIND, the predicate uses field-slice access (fast), and the struct is reassembled only for matching elements.&lt;&#x2F;p&gt;
&lt;p&gt;The compiler warns when SOA would help:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;NOTE: Pipeline accesses 1 of 5 fields (health). Consider @soa
&lt;&#x2F;span&gt;&lt;span&gt;      for better cache performance on &amp;#39;Entity&amp;#39;.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;concurrency&quot;&gt;Concurrency&lt;&#x2F;h2&gt;
&lt;p&gt;The &lt;code&gt;CONCURRENT&lt;&#x2F;code&gt; modifier currently parallelizes collection pipelines for &lt;code&gt;SELECT&lt;&#x2F;code&gt;, &lt;code&gt;WHERE&lt;&#x2F;code&gt;, and &lt;code&gt;EACH&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;data: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Score&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;) = [];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Parallel WHERE: one fiber per shard
&lt;&#x2F;span&gt;&lt;span&gt;results = data 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT WHERE&lt;&#x2F;span&gt;&lt;span&gt; dbFetch(_.id).val &amp;gt; threshold;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Process in parallel
&lt;&#x2F;span&gt;&lt;span&gt;results = data 
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;parallel: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TRUE&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; dbFetch(_.id).name;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Options:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;workers: N&lt;&#x2F;code&gt; (fiber worker size)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;pin: TRUE&lt;&#x2F;code&gt; (pin to cores)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;size: MICRO|STANDARD|LARGE|XL&lt;&#x2F;code&gt; (stack size).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;parallel&lt;&#x2F;code&gt;: TRUE` (run on multiple cores)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;concurrent-compatibility&quot;&gt;&lt;code&gt;CONCURRENT&lt;&#x2F;code&gt; compatibility&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Source kind&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;CONCURRENT SELECT&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;CONCURRENT WHERE&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;CONCURRENT EACH&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Arrays &#x2F; &lt;code&gt;@list&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;@pool&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;@pool:soa&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@sharded(...)&lt;&#x2F;code&gt; collections&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Finite streams &lt;code&gt;~T[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Not yet&lt;&#x2F;td&gt;&lt;td&gt;Not yet&lt;&#x2F;td&gt;&lt;td&gt;Not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Bounded streams &lt;code&gt;~T[N]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Open streams &lt;code&gt;~?T[]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Not yet&lt;&#x2F;td&gt;&lt;td&gt;Not yet&lt;&#x2F;td&gt;&lt;td&gt;Not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Infinite streams &lt;code&gt;~T[INF]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Not yet&lt;&#x2F;td&gt;&lt;td&gt;Not yet&lt;&#x2F;td&gt;&lt;td&gt;Not yet&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;So today:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;CONCURRENT&lt;&#x2F;code&gt; is for collection sources.&lt;&#x2F;li&gt;
&lt;li&gt;finite streams can participate in non-concurrent fused pipelines for the supported operators above.&lt;&#x2F;li&gt;
&lt;li&gt;stream &lt;code&gt;CONCURRENT&lt;&#x2F;code&gt; will come later once the MIR-safe native lowering is in place.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>CLEAR Collections: Array, List, Pool</title>
        <published>2026-03-25T00:00:00+00:00</published>
        <updated>2026-05-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/collections/"/>
        <id>https://cuzzo.github.io/clear/docs/collections/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/collections/">&lt;p&gt;CLEAR has three collection types, each designed for a different access pattern. The choice is a capability annotation — the element type and functions that operate on it stay the same regardless of which collection you use.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;quick-reference&quot;&gt;Quick Reference&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Collection&lt;&#x2F;th&gt;&lt;th&gt;Zig Type&lt;&#x2F;th&gt;&lt;th&gt;Access&lt;&#x2F;th&gt;&lt;th&gt;Growth&lt;&#x2F;th&gt;&lt;th&gt;Safety&lt;&#x2F;th&gt;&lt;th&gt;Use when&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;T[N]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;[N]T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Index O(1)&lt;&#x2F;td&gt;&lt;td&gt;Fixed&lt;&#x2F;td&gt;&lt;td&gt;Bounds-checked&lt;&#x2F;td&gt;&lt;td&gt;Size known at compile time&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;T[]@list&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;ArrayListUnmanaged(T)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Index O(1), append O(1)*&lt;&#x2F;td&gt;&lt;td&gt;Dynamic&lt;&#x2F;td&gt;&lt;td&gt;Bounds-checked&lt;&#x2F;td&gt;&lt;td&gt;Size unknown, sequential access&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;T[N]@pool&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Pool(T)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Handle O(1)&lt;&#x2F;td&gt;&lt;td&gt;Fixed&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;Generational handles&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;Frequent insert&#x2F;remove, stable references&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;* Amortized O(1) — occasional reallocation when capacity is exceeded.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;arrays-t-n&quot;&gt;Arrays — &lt;code&gt;T[N]&lt;&#x2F;code&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Fixed-size, stack-allocated. The size is part of the type.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;scores: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;] = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;40&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;50&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;x = scores[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;];          &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 30
&lt;&#x2F;span&gt;&lt;span&gt;scores[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;99&lt;&#x2F;span&gt;&lt;span&gt;;         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# mutation via index
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; x == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;index access&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ASSERT&lt;&#x2F;span&gt;&lt;span&gt; scores[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;] == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;99&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;mutation via index&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;When to use&lt;&#x2F;strong&gt;: Size is known at compile time. No insertions or removals. The fastest option — no heap allocation, no bounds-growth overhead.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Limitations&lt;&#x2F;strong&gt;: Cannot append, remove, or resize. Index out of bounds is a runtime panic.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;lists-list&quot;&gt;Lists — &lt;code&gt;@list&lt;&#x2F;code&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Dynamic-size, heap-allocated. Backed by &lt;code&gt;std.ArrayListUnmanaged(T)&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; users = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;List&lt;&#x2F;span&gt;&lt;span&gt;[];
&lt;&#x2F;span&gt;&lt;span&gt;users.append(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;users.append(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Bob&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;n = users.length();       &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 2
&lt;&#x2F;span&gt;&lt;span&gt;name = users[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;];           &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# &amp;quot;Alice&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;When to use&lt;&#x2F;strong&gt;: Size is unknown or grows over time. Elements accessed by index. The general-purpose dynamic array — equivalent to &lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; in Rust or &lt;code&gt;[]T&lt;&#x2F;code&gt; in Go.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Limitations&lt;&#x2F;strong&gt;: Removing from the middle is O(N) (shift elements). Handles&#x2F;pointers to elements are invalidated on reallocation. Not suitable for frequent insert&#x2F;remove of interior elements.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Variant — sharded list&lt;&#x2F;strong&gt;: &lt;code&gt;T[]@list:sharded(N)&lt;&#x2F;code&gt; splits the list into N shards for parallel pipeline operations (&lt;code&gt;|&amp;gt; EACH&lt;&#x2F;code&gt;, &lt;code&gt;|&amp;gt; SUM&lt;&#x2F;code&gt;). Each shard is an independent list. Round-robin distribution on append.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Lazy inference&lt;&#x2F;strong&gt;: &lt;code&gt;List[]&lt;&#x2F;code&gt; creates an untyped list. The element type is inferred from the first &lt;code&gt;append&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; items = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;List&lt;&#x2F;span&gt;&lt;span&gt;[];
&lt;&#x2F;span&gt;&lt;span&gt;items.append(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;42.0&lt;&#x2F;span&gt;&lt;span&gt;);  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# type inferred as Float64[]@list
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;pools-pool&quot;&gt;Pools — &lt;code&gt;@pool&lt;&#x2F;code&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Handle-based, pre-allocated with fixed capacity. Backed by &lt;code&gt;Pool(T)&lt;&#x2F;code&gt; with &lt;strong&gt;generational handles&lt;&#x2F;strong&gt; for ABA safety. The capacity is specified at declaration time and all slots are allocated up front — no dynamic resizing, no reallocation. Insert and remove are O(1) via an internal free stack.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Enemy &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;hp: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span&gt;String }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;enemies: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Enemy&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id1: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Id&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Enemy&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; = enemies.insert(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Enemy&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;hp: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Goblin&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;});
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id2: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Id&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Enemy&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; = enemies.insert(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Enemy&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;hp: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;200&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Dragon&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;});
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Access via handle — returns ?T (optional). Must use OR to unwrap:
&lt;&#x2F;span&gt;&lt;span&gt;goblin = enemies.get(id1) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR Enemy&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;hp: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;none&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Or via [] syntax (equivalent to .get):
&lt;&#x2F;span&gt;&lt;span&gt;dragon = enemies[id2] &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR Enemy&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;hp: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;none&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Remove: slot is freed, generation increments
&lt;&#x2F;span&gt;&lt;span&gt;enemies.remove(id1);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Stale handle returns null — OR provides a safe fallback:
&lt;&#x2F;span&gt;&lt;span&gt;gone = enemies.get(id1) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR Enemy&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;hp: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;removed&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Important: every pool access returns &lt;code&gt;?T&lt;&#x2F;code&gt; (optional).&lt;&#x2F;strong&gt; Like &lt;code&gt;@writeLocked&lt;&#x2F;code&gt;, using a pool is not a one-line optimization — it changes how you access data. Every &lt;code&gt;pool.get(id)&lt;&#x2F;code&gt; or &lt;code&gt;pool[id]&lt;&#x2F;code&gt; requires &lt;code&gt;OR default&lt;&#x2F;code&gt; to handle the case where the handle is stale or the slot was removed. This is by design: the pool guarantees you never read invalid data, but you must handle the &quot;not found&quot; case explicitly.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;how-generational-handles-work&quot;&gt;How Generational Handles Work&lt;&#x2F;h3&gt;
&lt;p&gt;Each pool slot stores a generation counter alongside the data:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Slot: &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;generation:&lt;&#x2F;span&gt;&lt;span&gt; u32, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;alive:&lt;&#x2F;span&gt;&lt;span&gt; bool, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;T &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Handle &lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Id&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;): u64 = [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;generation:&lt;&#x2F;span&gt;&lt;span&gt; upper &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;32&lt;&#x2F;span&gt;&lt;span&gt; bits][&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;index:&lt;&#x2F;span&gt;&lt;span&gt; lower &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;32&lt;&#x2F;span&gt;&lt;span&gt; bits]
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;When you &lt;code&gt;insert&lt;&#x2F;code&gt;, the handle encodes the current generation and slot index. When you &lt;code&gt;remove&lt;&#x2F;code&gt;, the slot&#x27;s generation increments. When you &lt;code&gt;get&lt;&#x2F;code&gt; with a stale handle, the generation in the handle doesn&#x27;t match the slot&#x27;s generation — the pool returns null instead of the wrong data.&lt;&#x2F;p&gt;
&lt;p&gt;This prevents the classic &lt;strong&gt;use-after-free&lt;&#x2F;strong&gt; &#x2F; &lt;strong&gt;type confusion&lt;&#x2F;strong&gt; bug:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;1. Insert User at slot 0, generation 0 → handle = 0x00000000_00000000
&lt;&#x2F;span&gt;&lt;span&gt;2. Remove User → slot 0 generation becomes 1
&lt;&#x2F;span&gt;&lt;span&gt;3. Insert Projectile at slot 0, generation 1 → handle = 0x00000001_00000000
&lt;&#x2F;span&gt;&lt;span&gt;4. Try to read old User handle (gen 0) → GENERATION MISMATCH → null
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;No garbage collector. No reference counting. Just a 4-byte integer comparison per access.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;when-to-use-pools&quot;&gt;When to use pools&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Game entities&lt;&#x2F;strong&gt; (ECS): enemies, projectiles, particles — frequently spawned and destroyed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Connection pools&lt;&#x2F;strong&gt;: TCP clients, database handles — allocated and returned&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Object caches&lt;&#x2F;strong&gt;: LRU-style caches where entries are evicted and reused&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Any workload with frequent insert&#x2F;remove&lt;&#x2F;strong&gt; where index-based access would leave holes&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;pools-vs-lists&quot;&gt;Pools vs Lists&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Operation&lt;&#x2F;th&gt;&lt;th&gt;List &lt;code&gt;T[]@list&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;Pool &lt;code&gt;T[N]@pool&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Append&#x2F;Insert&lt;&#x2F;td&gt;&lt;td&gt;O(1) amortized&lt;&#x2F;td&gt;&lt;td&gt;O(1) via free stack&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Access&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list[i]&lt;&#x2F;code&gt; → &lt;code&gt;T&lt;&#x2F;code&gt; (direct)&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;pool[id]&lt;&#x2F;code&gt; → &lt;code&gt;?T&lt;&#x2F;code&gt; (requires &lt;code&gt;OR&lt;&#x2F;code&gt;)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Remove from middle&lt;&#x2F;td&gt;&lt;td&gt;O(N) shift&lt;&#x2F;td&gt;&lt;td&gt;O(1) mark-dead&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Stable references&lt;&#x2F;td&gt;&lt;td&gt;No (realloc invalidates)&lt;&#x2F;td&gt;&lt;td&gt;Yes (handles survive realloc)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Capacity&lt;&#x2F;td&gt;&lt;td&gt;Dynamic (grows on demand)&lt;&#x2F;td&gt;&lt;td&gt;Fixed (pre-allocated at declaration)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Memory after remove&lt;&#x2F;td&gt;&lt;td&gt;Compacted&lt;&#x2F;td&gt;&lt;td&gt;Holes (reused on next insert via free stack)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Safety after remove&lt;&#x2F;td&gt;&lt;td&gt;Index may now point to different element&lt;&#x2F;td&gt;&lt;td&gt;Handle returns null (generational)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Ergonomic cost&lt;&#x2F;td&gt;&lt;td&gt;Direct access — no unwrapping&lt;&#x2F;td&gt;&lt;td&gt;Every access needs &lt;code&gt;OR&lt;&#x2F;code&gt; fallback&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;decision-tree&quot;&gt;Decision Tree&lt;&#x2F;h2&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;Is the size fixed at compile time?
&lt;&#x2F;span&gt;&lt;span&gt;├── Yes → T[N] (array)
&lt;&#x2F;span&gt;&lt;span&gt;└── No
&lt;&#x2F;span&gt;&lt;span&gt;    ├── Access pattern?
&lt;&#x2F;span&gt;&lt;span&gt;    │   ├── Sequential &#x2F; index-based → T[]@list (list)
&lt;&#x2F;span&gt;&lt;span&gt;    │   └── Handle-based &#x2F; frequent insert+remove → T[N]@pool (pool)
&lt;&#x2F;span&gt;&lt;span&gt;    └── Need stable references across insert&#x2F;remove?
&lt;&#x2F;span&gt;&lt;span&gt;        ├── Yes → T[N]@pool (generational handles survive mutations)
&lt;&#x2F;span&gt;&lt;span&gt;        └── No → T[]@list (simpler, more cache-friendly for iteration)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: pools require a compile-time capacity &lt;code&gt;N&lt;&#x2F;code&gt;. All slots are pre-allocated up front, giving O(1) insert&#x2F;remove via an internal free stack with no runtime reallocation. Choose a capacity that covers your expected maximum — the pool will panic if you exceed it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;hash-maps-hashmap-v-and-hashmap-k-v&quot;&gt;Hash Maps — &lt;code&gt;HashMap&amp;lt;V&amp;gt;&lt;&#x2F;code&gt; and &lt;code&gt;HashMap&amp;lt;K, V&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Key-value maps. String-keyed by default, numeric-keyed with explicit &lt;code&gt;HashMap&amp;lt;K, V&amp;gt;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;scores: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; = {};     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# String → Int64
&lt;&#x2F;span&gt;&lt;span&gt;scores[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;] = 100_i64;
&lt;&#x2F;span&gt;&lt;span&gt;scores[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;bob&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;] = 200_i64;
&lt;&#x2F;span&gt;&lt;span&gt;val = scores[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;];                    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 100
&lt;&#x2F;span&gt;&lt;span&gt;scores.delete(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;bob&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;scores.contains?(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);                 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# TRUE
&lt;&#x2F;span&gt;&lt;span&gt;scores.count();                           &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# 1
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;When to use&lt;&#x2F;strong&gt;: Lookup by key. The general-purpose associative container.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;soa-layout-cache-optimal-iteration&quot;&gt;SOA Layout — Cache-Optimal Iteration&lt;&#x2F;h2&gt;
&lt;p&gt;By default, collections store elements as &lt;strong&gt;Array of Structures&lt;&#x2F;strong&gt; (AOS): each element is a contiguous block of all its fields. When a pipeline accesses only a subset of fields, the CPU loads entire cache lines but uses only a fraction — wasting memory bandwidth.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;code&gt;:soa&lt;&#x2F;code&gt; capability switches to &lt;strong&gt;Structure of Arrays&lt;&#x2F;strong&gt; layout: each field gets its own contiguous array. A pipeline that touches one field iterates a dense, cache-friendly slice.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Entity &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;vx: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;vy: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;health: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;mana: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span&gt;String, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;level: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64 &lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# AOS (default): each entity is 8 fields × 8 bytes = 64 bytes per cache line.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# SUM _.health loads all 8 fields but uses only 1 — 87.5% wasted bandwidth.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;pool: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Entity&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# SOA: health values are stored in a contiguous f64 array.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# SUM _.health touches only that array — zero waste.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;pool: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Entity&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:soa &lt;&#x2F;span&gt;&lt;span&gt;= [];
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The compiler detects when SOA would help and suggests it:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;NOTE: Pipeline accesses 1 of 8 fields (health). Consider @soa
&lt;&#x2F;span&gt;&lt;span&gt;      for better cache performance on &amp;#39;Entity&amp;#39;.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;When &lt;code&gt;:soa&lt;&#x2F;code&gt; helps most:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Pipelines that touch &amp;lt; 50% of fields (SUM, MIN, MAX, AVERAGE on one field)&lt;&#x2F;li&gt;
&lt;li&gt;Large structs (8+ fields)&lt;&#x2F;li&gt;
&lt;li&gt;High-volume iteration (thousands of elements)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;When &lt;code&gt;:soa&lt;&#x2F;code&gt; doesn&#x27;t help:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Small structs (&amp;lt; 4 fields) — cache lines already fit the whole struct&lt;&#x2F;li&gt;
&lt;li&gt;EACH that reads&#x2F;writes most fields — no bandwidth savings&lt;&#x2F;li&gt;
&lt;li&gt;Random-access by handle (&lt;code&gt;pool.get(id)&lt;&#x2F;code&gt;) — must reassemble the struct&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;How it works under the hood:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;All pipeline operators (SUM, MIN, MAX, AVERAGE, COUNT, ANY, ALL, WHERE, FIND, SELECT) automatically use field-slice iteration on &lt;code&gt;:soa&lt;&#x2F;code&gt; pools. The compiler rewrites &lt;code&gt;_.health&lt;&#x2F;code&gt; to &lt;code&gt;data.items(.health)[i]&lt;&#x2F;code&gt; — a direct index into the contiguous field array. No materialization, no struct reassembly for the common case.&lt;&#x2F;p&gt;
&lt;p&gt;For operators that produce struct output (WHERE, FIND), structs are reassembled only for matching elements — the predicate still uses field-slice access, so most iterations touch only the predicate field.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;:soa&lt;&#x2F;code&gt; works on both &lt;code&gt;@pool&lt;&#x2F;code&gt; and &lt;code&gt;@list&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;pool: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Entity&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:soa &lt;&#x2F;span&gt;&lt;span&gt;= [];   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# SOA pool (generational handles)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;items: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Entity&lt;&#x2F;span&gt;&lt;span&gt;[]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@list&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:soa &lt;&#x2F;span&gt;&lt;span&gt;= [];  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# SOA list (dense, indexed)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Same API as their non-SOA counterparts. The difference is invisible except in pipeline performance.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;FFI restriction:&lt;&#x2F;strong&gt; &lt;code&gt;@soa&lt;&#x2F;code&gt; collections cannot be passed to &lt;code&gt;EXTERN FN&lt;&#x2F;code&gt; — SOA memory layout is incompatible with the C ABI. Materialize to a regular collection first if you need FFI.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;sharding-true-shared-nothing-parallel-collections&quot;&gt;Sharding — True Shared-Nothing Parallel Collections&lt;&#x2F;h2&gt;
&lt;p&gt;Lists, pools, and hash maps all support sharding for parallel access:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;data: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;[]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@list&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;) = [];
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;entities: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Enemy&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10000&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@pool&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;) = [];
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;counts: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;) = {};
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Sharding splits the collection into N independent partitions. Each shard is a complete, independent data structure — no shared state, no locks, no atomic operations between shards.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;How it works:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lists&lt;&#x2F;strong&gt;: Round-robin distribution on &lt;code&gt;append&lt;&#x2F;code&gt;. &lt;code&gt;length()&lt;&#x2F;code&gt; sums across shards.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pools&lt;&#x2F;strong&gt;: Round-robin distribution on &lt;code&gt;insert&lt;&#x2F;code&gt;. Handle encodes shard index in upper bits.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Hash maps&lt;&#x2F;strong&gt;: Key-based routing via &lt;code&gt;hash(key) % N&lt;&#x2F;code&gt;. Same key always maps to same shard.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;Pipeline operations&lt;&#x2F;strong&gt; (&lt;code&gt;|&amp;gt; EACH&lt;&#x2F;code&gt;, &lt;code&gt;|&amp;gt; SUM&lt;&#x2F;code&gt;, &lt;code&gt;|&amp;gt; WHERE&lt;&#x2F;code&gt;, etc.) process each shard in parallel via DO blocks — one fiber per shard, no contention between them.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;the-dragonflydb-model-each-thread-owns-its-partition&quot;&gt;The DragonflyDB Model — Each Thread Owns Its Partition&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;@sharded(N)&lt;&#x2F;code&gt; uses the same architecture as DragonflyDB: each scheduler thread owns a subset of shards, and fibers pinned to that scheduler access those shards with zero locks, zero atomics, and zero synchronization.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Shard ownership&lt;&#x2F;strong&gt;: Shard &lt;code&gt;i&lt;&#x2F;code&gt; is owned by scheduler &lt;code&gt;i % S&lt;&#x2F;code&gt; (where S = number of schedulers). With 8 shards and 2 schedulers, each scheduler owns 4 shards.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Hot path&lt;&#x2F;strong&gt; (shard owned by the current scheduler): Direct access. No locks, no atomics. Cooperative scheduling ensures only one fiber runs at a time per scheduler, so there&#x27;s no data race.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Cold path&lt;&#x2F;strong&gt; (shard owned by another scheduler): The operation is transparently routed to the owning scheduler via SPSC ring buffers. The calling fiber yields until the owning scheduler executes the operation inline and signals completion via an atomic done flag. Correct, but slower — design your workload so each fiber processes ONLY its own partition.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;shard-pipeline-true-shared-nothing-workloads&quot;&gt;&lt;code&gt;SHARD&lt;&#x2F;code&gt; Pipeline — True Shared-Nothing Workloads&lt;&#x2F;h3&gt;
&lt;p&gt;The &lt;code&gt;SHARD&lt;&#x2F;code&gt; pipeline operator partitions work so each fiber owns its shard exclusively:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;map: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;String&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;) = {};
&lt;&#x2F;span&gt;&lt;span&gt;n = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1000000&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# SHARD routes each key to the scheduler that owns its shard.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# CONCURRENT EACH runs one fiber per shard — zero locks, zero routing.
&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;..&amp;lt;n)
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SHARD&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;key:${toString(_)}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, map)
&lt;&#x2F;span&gt;&lt;span&gt;  |&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CONCURRENT EACH &lt;&#x2F;span&gt;&lt;span&gt;{ map[_] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;value&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;; };
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;How it works&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;SHARD hashes each key, appends it to the owning shard&#x27;s queue&lt;&#x2F;li&gt;
&lt;li&gt;One fiber per shard is pinned to the owning scheduler&lt;&#x2F;li&gt;
&lt;li&gt;Each fiber processes only its own queue — no cross-shard access, no locks&lt;&#x2F;li&gt;
&lt;li&gt;The result is true DragonflyDB-style shared-nothing: N partitions, N fibers, zero synchronization&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;&lt;strong&gt;When to use &lt;code&gt;@sharded(N)&lt;&#x2F;code&gt; vs &lt;code&gt;@sharded(N):locked&lt;&#x2F;code&gt;&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@sharded(N)&lt;&#x2F;code&gt; + &lt;code&gt;CONCURRENT EACH&lt;&#x2F;code&gt;: each fiber owns its partition. Maximum throughput.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;@sharded(N):locked&lt;&#x2F;code&gt;: any fiber can access any key. RwLock per shard. Use when the workload can&#x27;t be partitioned (e.g., random key distribution across all fibers).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;one-line-optimization&quot;&gt;One-Line Optimization&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;@sharded(N)&lt;&#x2F;code&gt; is a one-line declaration change. Functions don&#x27;t need to know — a function that takes &lt;code&gt;HashMap&amp;lt;String&amp;gt;&lt;&#x2F;code&gt; seamlessly accepts &lt;code&gt;HashMap&amp;lt;String&amp;gt;@sharded(8)&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# One-line change: add @sharded(8) to the declaration
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;map: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;String&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;) = {};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Functions: no @sharded needed in parameter types
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; doWork!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;map: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;String&amp;gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;key: &lt;&#x2F;span&gt;&lt;span&gt;String) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS &lt;&#x2F;span&gt;&lt;span&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    map[key] = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;value&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# BG blocks: auto-pinned when they capture a @sharded map
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ doWork!(map, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;hello&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;); }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# [Note] BG block auto-pinned — captures shared&#x2F;locked resource.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The compiler handles everything:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Unified API&lt;&#x2F;strong&gt;: All HashMap variants (plain, &lt;code&gt;@sharded&lt;&#x2F;code&gt;, &lt;code&gt;@sharded:locked&lt;&#x2F;code&gt;) have the same &lt;code&gt;.put()&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;.get()&lt;&#x2F;code&gt; interface. Functions use Zig &lt;code&gt;anytype&lt;&#x2F;code&gt; generics to accept any variant.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Auto-pinning&lt;&#x2F;strong&gt;: BG blocks that capture a &lt;code&gt;@sharded&lt;&#x2F;code&gt; map are automatically pinned to a scheduler. No &lt;code&gt;@pinned&lt;&#x2F;code&gt; annotation needed.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Fiber distribution&lt;&#x2F;strong&gt;: Pinned BG fibers are distributed round-robin across schedulers via &lt;code&gt;spawnPinned()&lt;&#x2F;code&gt;, so each scheduler gets work.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;sharding-variants&quot;&gt;Sharding Variants&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Variant&lt;&#x2F;th&gt;&lt;th&gt;Model&lt;&#x2F;th&gt;&lt;th&gt;Locking&lt;&#x2F;th&gt;&lt;th&gt;Use when&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@sharded(N)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Shared-nothing&lt;&#x2F;td&gt;&lt;td&gt;None (fiber-pinned)&lt;&#x2F;td&gt;&lt;td&gt;Partitioned workloads (CONCURRENT EACH)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@sharded(N):locked&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;RwLock per shard&lt;&#x2F;td&gt;&lt;td&gt;Per-shard RwLock&lt;&#x2F;td&gt;&lt;td&gt;Cross-shard access from any fiber&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@sharded(N):writeLocked&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;RwLock per shard&lt;&#x2F;td&gt;&lt;td&gt;Per-shard RwLock&lt;&#x2F;td&gt;&lt;td&gt;Same as :locked (alias)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;when-you-need-shared-mutable-maps&quot;&gt;When You Need Shared Mutable Maps&lt;&#x2F;h3&gt;
&lt;p&gt;For rare cases where multiple schedulers must read&#x2F;write the same keys concurrently (e.g., a global session registry), use &lt;code&gt;@shared:writeLocked&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;sessions: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Session&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@shared&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:writeLocked &lt;&#x2F;span&gt;&lt;span&gt;= {};
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Arc&amp;lt;RwLock&amp;lt;HashMap&amp;gt;&amp;gt;: readers are parallel, writers are serialized
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is CLEAR&#x27;s escape hatch — it works like Java&#x27;s &lt;code&gt;ConcurrentHashMap&lt;&#x2F;code&gt; but with explicit intent. The capability annotation makes the cost visible at the declaration site, and the compiler&#x27;s capability audit will tell you if you&#x27;re paying for it unnecessarily.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;hashing-secure-by-default&quot;&gt;Hashing — Secure by Default&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR uses &lt;strong&gt;seeded Wyhash&lt;&#x2F;strong&gt; as the default hash function for all hash maps. The seed is randomized per process, which prevents Hash DoS attacks (where an attacker crafts keys that all collide, turning O(1) lookups into O(n) traversals).&lt;&#x2F;p&gt;
&lt;p&gt;This follows CLEAR&#x27;s &quot;Correct &amp;gt; Scalable &amp;gt; Fast&quot; ordering: the default is safe against adversarial input, with near-zero overhead compared to unsalted hashes.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;future-fasttrusted-capability&quot;&gt;Future: &lt;code&gt;@fastTrusted&lt;&#x2F;code&gt; Capability&lt;&#x2F;h3&gt;
&lt;p&gt;For performance-critical internal infrastructure where keys are not attacker-controlled (e.g., internal service meshes, compiler symbol tables, game engine registries), CLEAR plans to offer an opt-in unsalted hash:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Planned syntax (not yet implemented):
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;symbols: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SymbolInfo&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@fastTrusted &lt;&#x2F;span&gt;&lt;span&gt;= {};
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;fast_sharded: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@sharded&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:fastTrusted &lt;&#x2F;span&gt;&lt;span&gt;= {};
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;@fastTrusted&lt;&#x2F;code&gt; would switch to unsalted FNV-1a or raw Wyhash — faster, but vulnerable to Hash DoS if keys come from untrusted input. The name is deliberate: it forces the developer to declare &quot;I trust this data source.&quot;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Why not yet&lt;&#x2F;strong&gt;: The default seeded Wyhash is fast enough for v1 (within ~5% of unsalted FNV). The capability will be added when real-world profiling shows the hash function is the bottleneck, not before. Premature escape hatches encourage premature optimization.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Shared Data in CLEAR</title>
        <published>2026-03-25T00:00:00+00:00</published>
        <updated>2026-05-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/sharing-capabilities/"/>
        <id>https://cuzzo.github.io/clear/docs/sharing-capabilities/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/sharing-capabilities/">&lt;p&gt;CLEAR separates:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;what data is&lt;&#x2F;strong&gt; (Types) from&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;how it&#x27;s accessed&lt;&#x2F;strong&gt; (Gates &amp;amp; Boundaries) from&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;the strategy it uses&lt;&#x2F;strong&gt; (Capabilities) from&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;when it&#x27;s available&lt;&#x2F;strong&gt; (Tense: &lt;code&gt;~T&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;types-capabilities-and-execution-boundaries&quot;&gt;Types, Capabilities, and Execution Boundaries&lt;&#x2F;h2&gt;
&lt;p&gt;Rust is not inherently complicated, nor is its type system much more complex than C++&#x27;s. The actual friction comes from Rust using a &#x27;God-like&#x27; type system forced to handle too many things at once.&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR breaks these into 4 separate components:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Types:&lt;&#x2F;strong&gt; The actual data &#x2F; memory (User)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Capabilities:&lt;&#x2F;strong&gt; What you’re allowed to do with that data (User &lt;code&gt;@shared:locked&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Execution Boundaries:&lt;&#x2F;strong&gt; When you&#x27;re do things concurrently or in parallel (&lt;code&gt;BG&#x2F;DO&#x2F;CONCURRENT&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Synchronization Gates:&lt;&#x2F;strong&gt; Where you explicitly mutate state concurrently (&lt;code&gt;WITH sharedUser AS user { … }&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;In CLEAR, concurrency is a property of the execution boundary, not the data type. CLEAR requires explicit &lt;code&gt;WITH&lt;&#x2F;code&gt; blocks for synchronization. While slightly less ergonomic than Rust for a simple Mutex, this design choice yields key structural dividends:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Zero-Friction Pass-Through:&lt;&#x2F;strong&gt; ~85% of your codebase handles shared data without a single synchronization annotation, making code substantially more maintainable &#x2F; refactorable to optimize for different synchronization strategies.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Polymorphic Synchronization:&lt;&#x2F;strong&gt; A single function can gracefully handle any of &lt;code&gt;LOCKED&lt;&#x2F;code&gt;, &lt;code&gt;SNAPSHOTTED&lt;&#x2F;code&gt;, &lt;code&gt;ACTOR&lt;&#x2F;code&gt;, &lt;code&gt;BUFFERED&lt;&#x2F;code&gt; etc data using a single block of code.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pinpoint Cost Visibility:&lt;&#x2F;strong&gt; You know exactly where and when your code blocks, yields, retries and the associated failure methods. Latency costs are isolated to the 15% of functions that actually mutate state, rather than hidden in a type signature 10 levels up the stack.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;You do not need to worry about a developer accidentally “sneaking” a slow actor synchronization into a hot loop. The costs are enforced ONLY at the synchronization boundaries (&lt;code&gt;WITH&lt;&#x2F;code&gt; blocks). The compiler will simply reject incompatible synchronization strategies inside hot loops.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; transact(
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;a: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Account@shared&lt;&#x2F;span&gt;&lt;span&gt;, 
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;b: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Account@shared&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;amount: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64
&lt;&#x2F;span&gt;&lt;span&gt;) 
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS &lt;&#x2F;span&gt;&lt;span&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Bool
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REQUIRES&lt;&#x2F;span&gt;&lt;span&gt; a, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;b: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;LOCKED &lt;&#x2F;span&gt;&lt;span&gt;| &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SNAPSHOTTED &lt;&#x2F;span&gt;&lt;span&gt;| &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BUFFERED
&lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt; amount &amp;lt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RAISE&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH 
&lt;&#x2F;span&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;POLYMORPHIC&lt;&#x2F;span&gt;&lt;span&gt; a &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; acctA,
&lt;&#x2F;span&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;POLYMORPHIC&lt;&#x2F;span&gt;&lt;span&gt; b &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; acctB {
&lt;&#x2F;span&gt;&lt;span&gt;     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt; acctA.balance &amp;lt;= amount -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RAISE&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;     acctA.balance -= amount;
&lt;&#x2F;span&gt;&lt;span&gt;     acctB.balance += amount;
&lt;&#x2F;span&gt;&lt;span&gt;   }
&lt;&#x2F;span&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ON LockTimeout &lt;&#x2F;span&gt;&lt;span&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ON Conflict &lt;&#x2F;span&gt;&lt;span&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ON QueueFull &lt;&#x2F;span&gt;&lt;span&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;There is a user-defined default policy for handling failure methods.  Not every function needs to specify failures:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; transact(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;a: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Account@shared&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;b: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Account@shared&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS &lt;&#x2F;span&gt;&lt;span&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Bool &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH POLYMORPHIC&lt;&#x2F;span&gt;&lt;span&gt; a &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; acctA, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;POLYMORPHIC&lt;&#x2F;span&gt;&lt;span&gt; b &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; acctB { ... }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This function will take any shared object: Mutex (&lt;code&gt;@locked&lt;&#x2F;code&gt;), RwLock (&lt;code&gt;@writeLocked&lt;&#x2F;code&gt;), MVCC (&lt;code&gt;@versioned&lt;&#x2F;code&gt;), AtomicPtr (&lt;code&gt;@atomic&lt;&#x2F;code&gt;), RingBuffer (&lt;code&gt;@buffered&lt;&#x2F;code&gt;), Actor (&lt;code&gt;@actor&lt;&#x2F;code&gt;). It will handle failure methods by the user-defined synchronization policy (or the system default):&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SYNC POLICY
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ON MvccConflict RETRY&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN RAISE
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ON AtomicConflict RETRY&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN RAISE
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ON LockTimeout RETRY&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN RAISE
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ON QueueFull BLOCK
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ON ActorTimeout RAISE
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Third-party code &#x2F; libraries must compile in &lt;code&gt;STRICT&lt;&#x2F;code&gt; mode, which requires them to explicitly handle all failure methods.  There is no chance your default sync policy creates spooky-action-at-distance in third party failure handling.&lt;&#x2F;p&gt;
&lt;p&gt;FAQ:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;But what about lock acquisition?
&lt;ul&gt;
&lt;li&gt;CLEAR automatically sorts locks. It raises errors on deadlock that MUST be handled if possible (regardless of compilation mode), rather than deadlocking.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;But what about the Default Policy causing Spooky-Action-at-a-Distance internally?
&lt;ul&gt;
&lt;li&gt;Compile in &lt;code&gt;STRICT&lt;&#x2F;code&gt; mode where this is not allowed, and then you know all synchronization failure methods are handled locally.&lt;&#x2F;li&gt;
&lt;li&gt;Default synchronization failure policies are meant to be a speed up for prototyping, not something to use in production.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;But what about distributed failures?
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@actor&lt;&#x2F;code&gt; in CLEAR does not imply a distributed actor.&lt;&#x2F;li&gt;
&lt;li&gt;There is &lt;code&gt;@shared:actor&lt;&#x2F;code&gt; (single-machine) and &lt;code&gt;@distributed:actor&lt;&#x2F;code&gt; (n-machines).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;@distributed&lt;&#x2F;code&gt; is not interchangeable with &lt;code&gt;@shared&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;FN foo(x: T@shared)&lt;&#x2F;code&gt; does not accept a &lt;code&gt;@distributed:actor&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;FN foo(x: T@distributed)&lt;&#x2F;code&gt; does not accept a &lt;code&gt;@shared:actor&lt;&#x2F;code&gt; (it may not exist on the machine!)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;div class=&quot;gh-alert gh-alert-note&quot;&gt;
&lt;p class=&quot;gh-alert-title&quot;&gt;&lt;svg class=&quot;gh-alert-icon&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z&quot;&#x2F;&gt;&lt;&#x2F;svg&gt; Note&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;@actor&lt;&#x2F;code&gt; and &lt;code&gt;@buffered&lt;&#x2F;code&gt; are in scope for v0.3.  They are not currently available.  &lt;code&gt;@distributed&lt;&#x2F;code&gt; is in scope for v0.4.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h3 id=&quot;analogy&quot;&gt;Analogy&lt;&#x2F;h3&gt;
&lt;p&gt;Think of &lt;code&gt;DO&#x2F;BG&#x2F;CONCURRENT&lt;&#x2F;code&gt; blocks as Execution Boundaries, and ownership capabilities (&lt;code&gt;@shared&lt;&#x2F;code&gt;) as your Keys to pass the Boundary.  A type without proper ownership cannot pass through an Execution Boundary (that is unsafe).&lt;&#x2F;p&gt;
&lt;p&gt;If you want to do something in parallel (on multiple cores at once), the data must be &lt;code&gt;@shared&lt;&#x2F;code&gt;.  If you want to do something concurrently (on a single core at once), the data can be &lt;code&gt;@shared&lt;&#x2F;code&gt; OR &lt;code&gt;@local&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Similarly, a type with a synchronization capability (&lt;code&gt;@locked&lt;&#x2F;code&gt;, &lt;code&gt;@versioned&lt;&#x2F;code&gt;, etc) requires crossing a gate for safe access.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;code&gt;WITH&lt;&#x2F;code&gt; block acts as this gate to safe access as the BG&#x2F;DO blocks act as the gate to safe boundary crossing.  &lt;code&gt;WITH&lt;&#x2F;code&gt; blocks require a type of permission to safely access synchronized data - this gives the reader insight into the cost.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Ownership (the keys)&lt;&#x2F;th&gt;&lt;th&gt;Execution Boundaries&lt;&#x2F;th&gt;&lt;th&gt;Synchronization&lt;&#x2F;th&gt;&lt;th&gt;Access Gates&lt;&#x2F;th&gt;&lt;th&gt;Access Permission (cost model)&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;@shared (any cores)&lt;&#x2F;td&gt;&lt;td&gt;BG {}&lt;&#x2F;td&gt;&lt;td&gt;@locked, @writeLocked&lt;&#x2F;td&gt;&lt;td&gt;WITH {}&lt;&#x2F;td&gt;&lt;td&gt;EXCLUSIVE&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;@local (pinned to a core)&lt;&#x2F;td&gt;&lt;td&gt;DO {}&lt;&#x2F;td&gt;&lt;td&gt;@versioned, @atomic&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;SNAPSHOT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;CONCURRENT {}&lt;&#x2F;td&gt;&lt;td&gt;@actor, @buffered&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;EVENTUAL&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;&lt;code&gt;@multiOwned&lt;&#x2F;code&gt; is an ownership capability, but it does not grant access through Execution Boundaries.  It allows an object to have multiple aliases (multiple owners - i.e. for a graph), but it does NOT grant permission to cross Execution Boundaries.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;complexity-reduced-or-just-moved-around&quot;&gt;Complexity Reduced?  Or just moved around?&lt;&#x2F;h3&gt;
&lt;p&gt;It is a fair critique from Rust or Go that this is nothing new, and arguably more complex.  Rust has a single system to keep track of.  CLEAR has three.  If anything, that’s more complex, not less.&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR thinks it is clearer to break the problem down into steps.  For one, developers not familiar with concurrent code know that anything &lt;code&gt;@shared&lt;&#x2F;code&gt; is something concurrent.  In Rust, it is hard to distinguish between &lt;code&gt;Arc&amp;lt;RwLock&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt;, &lt;code&gt;DashMap&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;, and &lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;.  Which one is something concurrent, that could have logical race bugs?&lt;&#x2F;p&gt;
&lt;p&gt;Secondly, while this might appear to be unergonomic, the concurrent benchmarks in CLEAR are only ~70% of the code as Rust (much more expressive than non-Rust people probably assume), and ~30% of the code as Go.&lt;&#x2F;p&gt;
&lt;p&gt;Lines of code on its own is a terrible benchmark for complexity. But CLEAR did not attempt to cherry-pick this metric. This is on top of the benefit of having polymorphic synchronization for almost no cost, and the ability to benchmark different strategies almost free.&lt;&#x2F;p&gt;
&lt;p&gt;Thirdly and most crucially, polymorphic synchronization allows your code to be maintainable in a way that is very difficult to achieve in Rust or Go.  &lt;code&gt;Arc&amp;lt;RwLock&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt; is viral in Rust.  &lt;code&gt;T@shared&lt;&#x2F;code&gt; is not in CLEAR.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Step 1) update your with blocks to use POLYMORPHIC access permission.&lt;&#x2F;li&gt;
&lt;li&gt;Step 2) change your synchronization strategy from @locked to @versioned.&lt;&#x2F;li&gt;
&lt;li&gt;Step 3) run &lt;code&gt;clear profile&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Step 4) profit.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;clear-levels-the-playing-field-for-non-experts&quot;&gt;CLEAR levels the playing field for non-experts&lt;&#x2F;h3&gt;
&lt;p&gt;In Rust or Go, you need to fully understand the implications of your code before you even write and test it.  Unless you are an expert (and even if you are), this is difficult to get right.
If you get it wrong, it is typically painful to rearchitect your app to do it right. It is also possible after your code continues to grow, you may need to switch again (possibly back to where you started), which can be equally painful.&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR was designed assuming that you cannot get everything right from the get-go, and to make it as easy as possible to experiment and optimize to get it right.  It was designed assuming you want to get there, even if you would have no chance in Rust or Go, because you need to understand things at a deeper level.&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR was designed to act like a high-level language like Ruby, but give you systems level speed.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;capabilities-in-depth&quot;&gt;Capabilities in Depth&lt;&#x2F;h2&gt;
&lt;p&gt;When multiple fibers need to access the same data, CLEAR must answer two questions:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Lifetime&lt;&#x2F;strong&gt;: How does the data stay alive when multiple fibers reference it?&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Thread safety&lt;&#x2F;strong&gt;: Is the reference count safe across schedulers (OS threads)?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;quick-reference&quot;&gt;Quick Reference&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Capability&lt;&#x2F;th&gt;&lt;th&gt;Zig Type&lt;&#x2F;th&gt;&lt;th&gt;Refcount&lt;&#x2F;th&gt;&lt;th&gt;Thread-safe?&lt;&#x2F;th&gt;&lt;th&gt;&lt;code&gt;@parallel&lt;&#x2F;code&gt;&lt;&#x2F;th&gt;&lt;th&gt;Use when&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@local&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;*T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;None&lt;&#x2F;td&gt;&lt;td&gt;No (single-scheduler)&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;Error&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;Fibers on one scheduler share mutable state&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@multiowned&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Rc(T)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Non-atomic&lt;&#x2F;td&gt;&lt;td&gt;No (single-scheduler)&lt;&#x2F;td&gt;&lt;td&gt;&lt;strong&gt;Error&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;Multiple owners, single scheduler, read-mostly&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@shared&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;Arc(T)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Atomic&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Allowed&lt;&#x2F;td&gt;&lt;td&gt;Cross-scheduler sharing (rare)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;local-zero-cost-shared-mutable-reference&quot;&gt;@local — Zero-Cost Shared Mutable Reference&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; c = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Counter&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@local&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ c.value += &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;; }            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# direct field access, no WITH block
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ print(c.value); }          &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# direct read
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;What it does&lt;&#x2F;strong&gt;: Heap-allocates the value and returns a bare &lt;code&gt;*T&lt;&#x2F;code&gt; pointer. No Mutex, no RwLock, no reference counting. Multiple fibers share the pointer by value copy.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Why it&#x27;s safe&lt;&#x2F;strong&gt;: The compiler auto-pins all BG&#x2F;DO blocks that capture &lt;code&gt;@local&lt;&#x2F;code&gt; variables to the local scheduler. Cooperative scheduling on a single OS thread means no two fibers ever execute simultaneously — no data races are possible.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;When to use it&lt;&#x2F;strong&gt;: This is the &lt;strong&gt;default choice&lt;&#x2F;strong&gt; for shared mutable state within a function scope. It&#x27;s the fastest option — zero synchronization overhead.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Compile-time enforcement&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@parallel &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; c.value = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;; }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# ERROR: @local variable cannot be used in @parallel block
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;multiowned-non-atomic-reference-counting-rc&quot;&gt;@multiowned — Non-Atomic Reference Counting (Rc)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;node = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TreeNode&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;left: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NIL&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;right: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NIL &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@multiowned&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Multiple owners via WITH block:
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; node &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; val { print(val.left); }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;What it does&lt;&#x2F;strong&gt;: Wraps the value in &lt;code&gt;Rc(T)&lt;&#x2F;code&gt; — a non-atomic reference-counted pointer. Each &lt;code&gt;WITH&lt;&#x2F;code&gt; unwrap increments the refcount; scope exit decrements it. The value is freed when the last reference is released.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;What it does&lt;&#x2F;strong&gt;: Wraps the value in &lt;code&gt;Rc(T)&lt;&#x2F;code&gt; — a non-atomic reference-counted pointer. Each &lt;code&gt;WITH&lt;&#x2F;code&gt; unwrap increments the refcount; scope exit decrements it. The value is freed when the last reference is released.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Why it exists&lt;&#x2F;strong&gt;: For &lt;strong&gt;graph structures&lt;&#x2F;strong&gt; and &lt;strong&gt;shared ownership&lt;&#x2F;strong&gt; patterns where multiple variables need to keep the same value alive. Unlike &lt;code&gt;@local&lt;&#x2F;code&gt; (which has one owner and shared pointers), &lt;code&gt;@multiowned&lt;&#x2F;code&gt; has multiple owners with automatic lifetime management.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Read-only access&lt;&#x2F;strong&gt;: &lt;code&gt;WITH node AS val&lt;&#x2F;code&gt; provides &lt;strong&gt;read-only&lt;&#x2F;strong&gt; access to the inner value. &lt;code&gt;@multiowned&lt;&#x2F;code&gt; does not support mutation — it&#x27;s shared ownership, not shared mutation. This is analogous to Rust&#x27;s &lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; (not &lt;code&gt;Rc&amp;lt;RefCell&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;For shared mutation&lt;&#x2F;strong&gt;, use:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;@alwaysMutable&lt;&#x2F;code&gt; — interior mutability (&lt;code&gt;RefCell&lt;&#x2F;code&gt;), mutate through const bindings&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;@local&lt;&#x2F;code&gt; — zero-cost, single-scheduler, direct field writes&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;@locked&lt;&#x2F;code&gt; — mutex-protected, cross-scheduler safe&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;Why it&#x27;s NOT thread-safe&lt;&#x2F;strong&gt;: &lt;code&gt;Rc&lt;&#x2F;code&gt; uses a plain integer for its refcount — no atomic CAS, no memory barriers. If two threads increment&#x2F;decrement simultaneously, the count corrupts (use-after-free or double-free).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Compile-time enforcement&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@parallel &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; node &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; val { ... } }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# ERROR: @multiowned (Rc) variable cannot be used in @parallel block —
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Rc uses a non-atomic reference count. Use @shared (Arc) for cross-scheduler sharing.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;When to use it&lt;&#x2F;strong&gt;: Graphs, trees, and shared ownership patterns where all fibers run on the same scheduler and data is read-only. If you need mutation, use &lt;code&gt;@local&lt;&#x2F;code&gt;. If you need cross-scheduler sharing, use &lt;code&gt;@shared&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;shared-atomic-reference-counting-arc&quot;&gt;@shared — Atomic Reference Counting (Arc)&lt;&#x2F;h2&gt;
&lt;div class=&quot;gh-alert gh-alert-note&quot;&gt;
&lt;p class=&quot;gh-alert-title&quot;&gt;&lt;svg class=&quot;gh-alert-icon&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z&quot;&#x2F;&gt;&lt;&#x2F;svg&gt; Note&lt;&#x2F;p&gt;
&lt;p&gt;Technically &lt;code&gt;@shared&lt;&#x2F;code&gt; means permission to cross an execution boundary. Atomics and atomic pointers (&lt;code&gt;@shared:atomic&lt;&#x2F;code&gt;) are NOT wrapped in Arc.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;config = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AppConfig&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;port: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;8080 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@shared&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@parallel &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; config &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; c { print(c.port); } }  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OK
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@parallel &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; config &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; c { print(c.port); } }  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# OK
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;What it does&lt;&#x2F;strong&gt;: Wraps the value in &lt;code&gt;Arc(T)&lt;&#x2F;code&gt; — an atomic reference-counted pointer. The refcount uses hardware atomic instructions (lock-prefixed CAS on x86), so it&#x27;s safe to increment&#x2F;decrement from any thread.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Why it&#x27;s expensive&lt;&#x2F;strong&gt;: Every clone&#x2F;drop of an &lt;code&gt;Arc&lt;&#x2F;code&gt; bounces the cache line containing the refcount between CPU cores. On a 16-core machine, this &quot;cache-line bouncing&quot; can cost ~100ns per operation (vs ~1ns for a non-atomic increment).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;When to use it&lt;&#x2F;strong&gt;: Only when you &lt;strong&gt;genuinely need&lt;&#x2F;strong&gt; cross-scheduler sharing — data accessed by fibers on different OS threads. This is rare in practice: most shared state is within a single function scope (use &lt;code&gt;@local&lt;&#x2F;code&gt;) or within a single scheduler (use &lt;code&gt;@multiowned&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;combining-with-sync-capabilities&quot;&gt;Combining with Sync Capabilities&lt;&#x2F;h2&gt;
&lt;p&gt;Sharing capabilities can be combined with sync capabilities for mutable cross-thread access:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Arc + Mutex: one-line mutations auto-lock
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; counter = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Counter&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@shared&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:locked&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@parallel &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; counter.value += &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;; }                             &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# auto mutex
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# Arc + RwLock: cross-scheduler read-heavy access
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; config = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Config&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;port: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;8080 &lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@shared&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;:writeLocked&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@parallel &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; config &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; c { print(c.port); } }            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# read lock
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@parallel &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; config.port = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;9090&lt;&#x2F;span&gt;&lt;span&gt;; }                             &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# auto write lock
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;@local&lt;&#x2F;code&gt; does not combine with &lt;code&gt;@locked&lt;&#x2F;code&gt; or &lt;code&gt;@writeLocked&lt;&#x2F;code&gt; — it&#x27;s already a bare pointer with no wrapper. Mutation is direct.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;decision-tree&quot;&gt;Decision Tree&lt;&#x2F;h2&gt;
&lt;pre style=&quot;background-color:#151515;color:#e8e8d3;&quot;&gt;&lt;code&gt;&lt;span&gt;Do multiple fibers need to access this data?
&lt;&#x2F;span&gt;&lt;span&gt;├── No  → default (no capability, single owner)
&lt;&#x2F;span&gt;&lt;span&gt;└── Yes
&lt;&#x2F;span&gt;&lt;span&gt;    ├── Does it need mutable access?
&lt;&#x2F;span&gt;&lt;span&gt;    │   ├── Same scheduler → @local (zero cost, direct field writes)
&lt;&#x2F;span&gt;&lt;span&gt;    │   └── Cross-scheduler → @locked or @writeLocked (mutex&#x2F;rwlock)
&lt;&#x2F;span&gt;&lt;span&gt;    └── Do multiple fibers need to OWN it (keep it alive)?
&lt;&#x2F;span&gt;&lt;span&gt;        ├── Read-only, same scheduler → @multiowned (Rc)
&lt;&#x2F;span&gt;&lt;span&gt;        ├── Read-only, cross-scheduler → @shared (Arc)
&lt;&#x2F;span&gt;&lt;span&gt;        └── Mutable + shared ownership → @local (same scheduler)
&lt;&#x2F;span&gt;&lt;span&gt;            or @shared:locked (cross-scheduler)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;Stable heap address needed (graph edges, self-referential)?
&lt;&#x2F;span&gt;&lt;span&gt;└── @indirect (combinable with any of the above)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note on primitives&lt;&#x2F;strong&gt;: Capabilities cannot be applied to primitive types (&lt;code&gt;Int64&lt;&#x2F;code&gt;, &lt;code&gt;Float64&lt;&#x2F;code&gt;, &lt;code&gt;Bool&lt;&#x2F;code&gt;, &lt;code&gt;Byte&lt;&#x2F;code&gt;, &lt;code&gt;Float32&lt;&#x2F;code&gt;). Wrap in a &lt;code&gt;STRUCT&lt;&#x2F;code&gt; first — this makes the intent explicit and gives you named fields.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;auto-pinning&quot;&gt;Auto-Pinning&lt;&#x2F;h2&gt;
&lt;p&gt;The compiler automatically pins BG&#x2F;DO blocks to the local scheduler when they capture &lt;code&gt;@local&lt;&#x2F;code&gt;, &lt;code&gt;@multiowned&lt;&#x2F;code&gt;, &lt;code&gt;@shared&lt;&#x2F;code&gt;, &lt;code&gt;@locked&lt;&#x2F;code&gt;, or &lt;code&gt;@writeLocked&lt;&#x2F;code&gt; variables. This is a &lt;strong&gt;cache-line bouncing optimization&lt;&#x2F;strong&gt; for thread-safe types and a &lt;strong&gt;safety requirement&lt;&#x2F;strong&gt; for non-thread-safe types.&lt;&#x2F;p&gt;
&lt;p&gt;To override auto-pinning for thread-safe types:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;BG &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@parallel &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt; ... }   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;# distribute across schedulers
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For non-thread-safe types (&lt;code&gt;@local&lt;&#x2F;code&gt;, &lt;code&gt;@multiowned&lt;&#x2F;code&gt;), &lt;code&gt;@parallel&lt;&#x2F;code&gt; is a compile error.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>THE ANATOMY OF A GOOD FUNCTION</title>
        <published>2026-03-01T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-function-anatomy/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-function-anatomy/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-function-anatomy/">&lt;p&gt;The most desired behavior from any function is that it &lt;strong&gt;works&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;A function should exist to serve the user, not the compiler. It should (in order of preference):&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Return (and do) what the user wants&lt;&#x2F;li&gt;
&lt;li&gt;Return a suitable default (if possible&#x2F;applicable)&lt;&#x2F;li&gt;
&lt;li&gt;Return an explicit set of errors&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;It should return exactly &lt;em&gt;ONE&lt;&#x2F;em&gt; type. A user should never need to post-process a function&#x27;s output to do what they want.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;all-public-functions-must-be-good&quot;&gt;ALL PUBLIC FUNCTIONS MUST BE GOOD&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;PUBLIC FN&lt;&#x2F;span&gt;&lt;span&gt; getFullyFormedUser(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Number&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS User OR User&lt;&#x2F;span&gt;&lt;span&gt;::DEFAULT
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;. &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Input &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Hygiene: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Handle&lt;&#x2F;span&gt;&lt;span&gt; invalid inputs *uniformly* at the top.
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;GUARD&lt;&#x2F;span&gt;&lt;span&gt; id &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR RETURN DEFAULT&lt;&#x2F;span&gt;&lt;span&gt;; 
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;. &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;The Happy &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Path: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;A&lt;&#x2F;span&gt;&lt;span&gt; clear, easy-to-follow stream of data using &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;s&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; id
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchUserFromCache
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OTHERWISE&lt;&#x2F;span&gt;&lt;span&gt;(fetchFromDb!!) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR EXIT &lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;If&lt;&#x2F;span&gt;&lt;span&gt; cache misses, try &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DB
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; hydrateFromOtherDb;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;. &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;The Catch&lt;&#x2F;span&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;All:
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;All&lt;&#x2F;span&gt;&lt;span&gt; error logic is tucked away at the bottom.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CATCH
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN DEFAULT&lt;&#x2F;span&gt;&lt;span&gt;; -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Return&lt;&#x2F;span&gt;&lt;span&gt; suitable default on error
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;internal-functions-can-be-bad&quot;&gt;INTERNAL FUNCTIONS CAN BE BAD&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;This&lt;&#x2F;span&gt;&lt;span&gt; can &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;return&lt;&#x2F;span&gt;&lt;span&gt; an error &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;`&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;!!&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;`
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Internal&lt;&#x2F;span&gt;&lt;span&gt; code can be &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Chill-Correct&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;until&lt;&#x2F;span&gt;&lt;span&gt; you&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;re ready to make it public.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;FN reciprocalId(id) -&amp;gt; 
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;  RETURN functionThatCanError!!(id);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;comparisons&quot;&gt;Comparisons&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;C:&lt;&#x2F;strong&gt; High Danger. Manual memory management and error checking.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Go:&lt;&#x2F;strong&gt; Visual Noise. Repetitive &lt;code&gt;if err != nil&lt;&#x2F;code&gt; boilerplate kills flow.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Rust:&lt;&#x2F;strong&gt; High Cognitive Load. Mandatory unwrapping of every Enum&#x2F;Result case.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CLEAR:&lt;&#x2F;strong&gt; Represents &lt;strong&gt;Flow&lt;&#x2F;strong&gt;. It projects the &quot;View&quot; of the data you want, handling the Union&#x2F;Error logic implicitly based on your definitions.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLEAR&lt;&#x2F;span&gt;&lt;span&gt; projects the view of the data you want
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;. &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Handles&lt;&#x2F;span&gt;&lt;span&gt; the &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Error &lt;&#x2F;span&gt;&lt;span&gt;(defaults to empty&#x2F;nil &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; it fails)
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;. &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Handles&lt;&#x2F;span&gt;&lt;span&gt; the &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Union &lt;&#x2F;span&gt;&lt;span&gt;(projects &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;View&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;PRINT&lt;&#x2F;span&gt;&lt;span&gt;(getUser().email);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;the-final-path&quot;&gt;THE FINAL PATH&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR is designed as a language that is native to &lt;strong&gt;Property-Based Testing&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Because &lt;em&gt;EVERY&lt;&#x2F;em&gt; public function follows a strict contract:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Inputs and outputs have suitable defaults (or explicit explosions).&lt;&#x2F;li&gt;
&lt;li&gt;We can programmatically generate permutations of every possible input for testing.&lt;&#x2F;li&gt;
&lt;li&gt;CLEAR enforces a Strict Contract at the Public boundary (RETURNS Type OR Default). This solves the &lt;em&gt;Oracle Problem&lt;&#x2F;em&gt; for automated testing.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;The easier you make code to understand and to test, the easier you make it to get &lt;strong&gt;working&lt;&#x2F;strong&gt; code.&lt;&#x2F;p&gt;
&lt;p&gt;And &lt;strong&gt;working&lt;&#x2F;strong&gt; code is all that really matters.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;verdict&quot;&gt;VERDICT&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;C&#x2F;Elixir represent &lt;strong&gt;Chaos&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Rust&#x2F;Go represent &lt;strong&gt;Bureaucracy&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;CLEAR represents &lt;strong&gt;Flow&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>THE GIVE PROBLEM</title>
        <published>2026-03-01T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-give-problem/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-give-problem/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-give-problem/">&lt;p&gt;In CLEAR, we separate &lt;strong&gt;Types&lt;&#x2F;strong&gt; from &lt;strong&gt;Capabilities&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Type:&lt;&#x2F;strong&gt; What the data is (e.g., &lt;code&gt;User&lt;&#x2F;code&gt;).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Capability:&lt;&#x2F;strong&gt; How the data is accessed (e.g., &lt;code&gt;affine&lt;&#x2F;code&gt;, &lt;code&gt;shared&lt;&#x2F;code&gt;).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;By default, objects in CLEAR are &lt;strong&gt;affine&lt;&#x2F;strong&gt; (meaning they can only be used once, and passing them to a function &quot;borrows&quot; them). When a function needs to take ownership of an object (e.g., to store it in a long-lived list), it must explicitly &lt;code&gt;TAKES&lt;&#x2F;code&gt; it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-friction-give-vs-copy&quot;&gt;The Friction: &lt;code&gt;GIVE&lt;&#x2F;code&gt; vs. &lt;code&gt;COPY&lt;&#x2F;code&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you have an affine object and you need to pass it to a function that &lt;code&gt;TAKES&lt;&#x2F;code&gt; it, you have two choices:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;GIVE it:&lt;&#x2F;strong&gt; Transfer ownership. The original variable becomes &quot;dead&quot; and can no longer be used.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;COPY it:&lt;&#x2F;strong&gt; Create a duplicate. The original variable remains &quot;alive&quot; and can still be used.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT User &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span&gt;String }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; addToCache(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;TAKES &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;u: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURNS Void &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;This&lt;&#x2F;span&gt;&lt;span&gt; function now owns &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;u&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;u = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Alice&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;addToCache(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;GIVE&lt;&#x2F;span&gt;&lt;span&gt; u);           -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Explicit Move
&lt;&#x2F;span&gt;&lt;span&gt;print(u.name);                -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;COMPILER &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;ERROR:&lt;&#x2F;span&gt;&lt;span&gt; u is dead.
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;u2 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Bob&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;addToCache(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; u2);          -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Explicit Copy
&lt;&#x2F;span&gt;&lt;span&gt;print(u2.name);               -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;OKAY:&lt;&#x2F;span&gt;&lt;span&gt; u2 is still alive.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;why-this-is-better-than-rust&quot;&gt;Why this is Better than Rust&lt;&#x2F;h3&gt;
&lt;p&gt;In Rust, &quot;moving&quot; or &quot;copying&quot; is often implicit based on the type (e.g., &lt;code&gt;i32&lt;&#x2F;code&gt; is &lt;code&gt;Copy&lt;&#x2F;code&gt;, &lt;code&gt;String&lt;&#x2F;code&gt; is not). This makes it difficult to reason about whether a variable is still alive after a function call without knowing the exact implementation details of the type.&lt;&#x2F;p&gt;
&lt;p&gt;In CLEAR, the &lt;strong&gt;developer&#x27;s intent&lt;&#x2F;strong&gt; is always explicit:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;If you see &lt;code&gt;GIVE&lt;&#x2F;code&gt;, you know the variable is gone.&lt;&#x2F;li&gt;
&lt;li&gt;If you see &lt;code&gt;COPY&lt;&#x2F;code&gt;, you know you&#x27;re paying a performance cost to keep it.&lt;&#x2F;li&gt;
&lt;li&gt;If you see neither, it&#x27;s a &lt;strong&gt;Borrow&lt;&#x2F;strong&gt; (safe and fast).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Keyword&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Meaning&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Result&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;GIVE&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Move ownership&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Original is dead, zero-cost transfer&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;COPY&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Duplicate data&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Original is alive, high-cost duplicate&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;(None)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Borrow&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Original is alive, zero-cost reference&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;&lt;strong&gt;CLEAR optimizes for local reasoning and explicit intent, making ownership semantics intuitive for everyone.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>REENTRANCY ATE MY BABY</title>
        <published>2025-12-19T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-reentrancy/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-reentrancy/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-reentrancy/">&lt;h2 id=&quot;with-blocks-are-non-reentrant&quot;&gt;WITH blocks are non-reentrant&lt;&#x2F;h2&gt;
&lt;p&gt;In CLEAR, when you open a &lt;code&gt;WITH&lt;&#x2F;code&gt; block on an object to acquire a capability (like mutation or sharing), no other &lt;code&gt;WITH&lt;&#x2F;code&gt; block for that same object can start until the first one finishes.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;This applies to other threads, but crucially, it also applies to your own recursive functions or callbacks.&lt;&#x2F;li&gt;
&lt;li&gt;This restriction gives you Rust-level determinism for mutable access to shared objects, with significantly less cognitive overhead.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;the-mental-model-capabilities-are-edges&quot;&gt;The Mental Model: Capabilities are Edges&lt;&#x2F;h3&gt;
&lt;p&gt;In CLEAR, we separate &lt;strong&gt;Types&lt;&#x2F;strong&gt; from &lt;strong&gt;Capabilities&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Types&lt;&#x2F;strong&gt; (e.g., &lt;code&gt;Player&lt;&#x2F;code&gt;) are passed into functions.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Capabilities&lt;&#x2F;strong&gt; (e.g., &lt;code&gt;shared:locked&lt;&#x2F;code&gt;, &lt;code&gt;alwaysMutable&lt;&#x2F;code&gt;) are managed at the &quot;edges&quot; using &lt;code&gt;WITH&lt;&#x2F;code&gt; blocks.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;The Rule:&lt;&#x2F;strong&gt; Functions take the &lt;strong&gt;Type&lt;&#x2F;strong&gt;, not the &lt;strong&gt;Capability&lt;&#x2F;strong&gt;. You must unwrap the capability using &lt;code&gt;WITH&lt;&#x2F;code&gt; before calling the function.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLEAR&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;s Solution: Unwrapping at the call site
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;WITH sharedPlayer AS player {
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;player&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt; is now the raw Type (User), unwrapped from its &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;shared&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt; capability
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;  damage!(player);               -- OKAY
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;  heal!(player);                 -- OKAY
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;  
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;  -- heal!(sharedPlayer);       -- COMPILER ERROR! 
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;  -- Functions take User, not shared:locked User.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This prevents the &quot;Infinite Mirror&quot; pattern where a function modifying an object accidentally tries to re-acquire a lock it already holds.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;why-this-matters&quot;&gt;Why this matters&lt;&#x2F;h3&gt;
&lt;p&gt;Re-entrancy bugs (where state changes under your feet while you&#x27;re in the middle of an operation) are the root of most concurrent complexity.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;the-problem-sheer-chaos&quot;&gt;The Problem (Sheer Chaos):&lt;&#x2F;h4&gt;
&lt;p&gt;In most languages (Java, C, Go, Swift), you cannot trust from one line of code to the next. While you are reading a list, another thread can &lt;code&gt;pop()&lt;&#x2F;code&gt; from it, causing your next line to crash with an &lt;code&gt;IndexOutOfBounds&lt;&#x2F;code&gt; error.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;the-clear-solution-scoped-sovereignty&quot;&gt;The CLEAR Solution: Scoped Sovereignty&lt;&#x2F;h4&gt;
&lt;p&gt;By banning re-entrancy via &lt;code&gt;WITH&lt;&#x2F;code&gt; blocks, CLEAR guarantees that while you are inside that scope:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;You are the sole owner&lt;&#x2F;strong&gt; of that object&#x27;s state.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;No one else&lt;&#x2F;strong&gt; (not other threads, and not your own callbacks) can touch it.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;This turns a &lt;strong&gt;global problem&lt;&#x2F;strong&gt; (unpredictable concurrency bugs) into a &lt;strong&gt;local problem&lt;&#x2F;strong&gt; (simple logic).&lt;&#x2F;p&gt;
&lt;h3 id=&quot;comparison-with-other-models&quot;&gt;Comparison with Other Models&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Actor Model (Erlang&#x2F;Go Channels):&lt;&#x2F;strong&gt; Safe, but treats your RAM like a slow network cable. It often leads to &quot;God Actors&quot; that serialize your entire program.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Rust (Borrow Checker):&lt;&#x2F;strong&gt; Perfect safety, but high cognitive cost. Rust forces you to infect every function signature with lifetimes and capability types (like &lt;code&gt;Arc&amp;lt;RwLock&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt;).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CLEAR:&lt;&#x2F;strong&gt; Gives you Rust&#x27;s safety and performance, but keeps your functions &quot;pure&quot; by handling capabilities at the call site.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;simplified-refactoring&quot;&gt;Simplified Refactoring&lt;&#x2F;h3&gt;
&lt;p&gt;In Rust, if you change an object from &lt;code&gt;Rc&lt;&#x2F;code&gt; (single-threaded) to &lt;code&gt;Arc&lt;&#x2F;code&gt; (multi-threaded), you must update every function signature that takes that object.&lt;&#x2F;p&gt;
&lt;p&gt;In CLEAR, you only change the capability at the definition site. Because your functions only take the raw Type (e.g., &lt;code&gt;User&lt;&#x2F;code&gt;), the rest of your codebase remains untouched. The &quot;Refactoring Blast Radius&quot; is zero.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;a-final-note-on-local-reasoning&quot;&gt;A final note on local reasoning&lt;&#x2F;h3&gt;
&lt;p&gt;CLEAR optimizes for the &lt;strong&gt;ROI on brain power&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Rust&lt;&#x2F;strong&gt; optimizes for the toaster (minimum RAM&#x2F;CPU at any cognitive cost).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CLEAR&lt;&#x2F;strong&gt; optimizes for the developer (maximum safety and speed with minimum cognitive load).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;By enforcing explicit scopes for capabilities, CLEAR ensures that &quot;poisoning&quot; (restricting access to data) is always visible and local. You don&#x27;t need to be a systems programming expert to write blazing-fast, thread-safe code. You just need to follow the &lt;code&gt;WITH&lt;&#x2F;code&gt; block.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>SHARED MUTABLE DEATH</title>
        <published>2025-12-18T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-deadlock/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-deadlock/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-deadlock/">&lt;h2 id=&quot;clear-the-unfair-advantage&quot;&gt;CLEAR - The Unfair Advantage&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Account &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;balance: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Float64&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Cache &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Capabilities&lt;&#x2F;span&gt;&lt;span&gt; are properties of the storage, not the type
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;items: shared:&lt;&#x2F;span&gt;&lt;span&gt;locked &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;String, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;shared:&lt;&#x2F;span&gt;&lt;span&gt;locked &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Account&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; insert(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;cache: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Cache&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;id: &lt;&#x2F;span&gt;&lt;span&gt;String, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;account: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Account&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Acquire &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;shared:&lt;&#x2F;span&gt;&lt;span&gt;locked capability
&lt;&#x2F;span&gt;&lt;span&gt;  sharedAccount = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;SHARE:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;LOCKED&lt;&#x2F;span&gt;&lt;span&gt;(account);
&lt;&#x2F;span&gt;&lt;span&gt;  
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; cache.items {
&lt;&#x2F;span&gt;&lt;span&gt;    -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Inside&lt;&#x2F;span&gt;&lt;span&gt; here, the &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt; is unwrapped and locked
&lt;&#x2F;span&gt;&lt;span&gt;    _.insert(id, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;GIVE&lt;&#x2F;span&gt;&lt;span&gt; sharedAccount);
&lt;&#x2F;span&gt;&lt;span&gt;  }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; transact(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;cache: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Cache&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLEAR&lt;&#x2F;span&gt;&lt;span&gt; automatically handles lock ordering &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;in &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; blocks to prevent deadlocks
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; cache.items.get(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; a, cache.items.get(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;b&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; b {
&lt;&#x2F;span&gt;&lt;span&gt;    a.balance += &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    b.balance -= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;What can go wrong? Not deadlock, not memory corruption.&lt;&#x2F;li&gt;
&lt;li&gt;CLEAR makes illegal states impossible at the concurrency level &lt;strong&gt;while&lt;&#x2F;strong&gt; being easy and ergonomic.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;CLEAR distinguishes between &lt;strong&gt;Types&lt;&#x2F;strong&gt; and &lt;strong&gt;Capabilities&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Account&lt;&#x2F;code&gt; is a Type.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;shared:locked&lt;&#x2F;code&gt; is a Capability.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Functions take &lt;code&gt;Account&lt;&#x2F;code&gt;, not &lt;code&gt;shared:locked Account&lt;&#x2F;code&gt;. This means your business logic remains pure and decoupled from your synchronization strategy.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;refactoring-blast-radius-zero&quot;&gt;Refactoring Blast Radius: Zero&lt;&#x2F;h3&gt;
&lt;p&gt;If you need to change from a &lt;code&gt;Mutex&lt;&#x2F;code&gt; (&lt;code&gt;shared:locked&lt;&#x2F;code&gt;) to an &lt;code&gt;RwLock&lt;&#x2F;code&gt; (&lt;code&gt;shared:writeLocked&lt;&#x2F;code&gt;), you only change the definition in the Struct. Your functions don&#x27;t change because they never knew about the capability in the first place.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rust-this-is-safe&quot;&gt;Rust - This is Safe?&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&#x2F;&#x2F; Rust infection: capabilities (Arc, RwLock) are part of the type system
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;struct &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Cache &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;sharedItems&lt;&#x2F;span&gt;&lt;span&gt;: Arc&amp;lt;RwLock&amp;lt;HashMap&amp;lt;String, Arc&amp;lt;RwLock&amp;lt;Account&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;,
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&#x2F;&#x2F; Function signatures are infected by the capabilities
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fad07a;&quot;&gt;transfer&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;: &amp;amp;Arc&amp;lt;RwLock&amp;lt;Account&amp;gt;&amp;gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;to&lt;&#x2F;span&gt;&lt;span&gt;: &amp;amp;Arc&amp;lt;RwLock&amp;lt;Account&amp;gt;&amp;gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;amount&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&#x2F;&#x2F; Manual lock ordering required to avoid deadlock
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;let &lt;&#x2F;span&gt;&lt;span&gt;(first, second, swap) = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;Arc::as_ptr(from) &amp;lt; Arc::as_ptr(to) {
&lt;&#x2F;span&gt;&lt;span&gt;        (from, to, false)
&lt;&#x2F;span&gt;&lt;span&gt;    } &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;else &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        (to, from, true)
&lt;&#x2F;span&gt;&lt;span&gt;    };
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&#x2F;&#x2F; ...
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;the-safety-gap&quot;&gt;The Safety Gap&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Rust guarantees you will not have a data race (memory corruption).&lt;&#x2F;li&gt;
&lt;li&gt;It does not guarantee you will avoid a deadlock (program halt).&lt;&#x2F;li&gt;
&lt;li&gt;CLEAR guarantees both by managing lock acquisition order and separating capabilities from types.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;swift-this-is-ergonomic&quot;&gt;Swift - This is Ergonomic?&lt;&#x2F;h2&gt;
&lt;p&gt;Swift&#x27;s Actors introduce &lt;strong&gt;Reentrancy&lt;&#x2F;strong&gt;. If you &lt;code&gt;await&lt;&#x2F;code&gt; inside an actor, the state can change underneath you, leading to logic races. CLEAR avoids this by using explicit &lt;code&gt;WITH&lt;&#x2F;code&gt; scopes that maintain invariants.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;go-this-is-simple&quot;&gt;Go - This is Simple?&lt;&#x2F;h2&gt;
&lt;p&gt;In Go, Mutexes are just structs. If you accidentally pass an &lt;code&gt;Account&lt;&#x2F;code&gt; by value, you copy the Mutex, and you&#x27;re now protecting nothing. CLEAR treats capabilities as compiler-enforced metadata, making this error impossible.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;c-yolo&quot;&gt;C - YOLO&lt;&#x2F;h2&gt;
&lt;p&gt;C is both memory-unsafe and liveness-unsafe. CLEAR is the simplest language that is both memory-safe and liveness-safe.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;CLEAR rests its case. It is both:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;The &lt;em&gt;simplest&lt;&#x2F;em&gt; language for concurrency.&lt;&#x2F;li&gt;
&lt;li&gt;The only &lt;em&gt;liveness-safe&lt;&#x2F;em&gt; language that prevents deadlocks by design.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>THE DLL PROBLEM</title>
        <published>2025-12-03T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-dll-problem/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-dll-problem/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-dll-problem/">&lt;p&gt;In most languages (C, C++, Rust), you can easily create a Doubly Linked List (DLL).&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;C&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-C &quot;&gt;&lt;code class=&quot;language-C&quot; data-lang=&quot;C&quot;&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;typedef struct&lt;&#x2F;span&gt;&lt;span&gt; Node {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; val;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span&gt; Node* prev;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span&gt; Node* next;
&lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Node&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In a DLL, every node has a pointer to its neighbor, and every neighbor has a pointer back.&lt;&#x2F;p&gt;
&lt;p&gt;This is a &lt;strong&gt;Cycle&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Cycles are the enemy of deterministic memory management.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;If you use &lt;strong&gt;Reference Counting&lt;&#x2F;strong&gt; (Swift&#x2F;Python), A will never die because B holds a reference to it, and B will never die because A holds a reference to it. They leak memory forever.&lt;&#x2F;li&gt;
&lt;li&gt;If you use &lt;strong&gt;Arena-Based Memory&lt;&#x2F;strong&gt; (CLEAR), child nodes die when the function returns. If you try to point back to a parent, you&#x27;re pointing to a corpse.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;the-solution-ids-and-centralized-lookups&quot;&gt;The Solution: IDs and Centralized Lookups&lt;&#x2F;h2&gt;
&lt;p&gt;In CLEAR, we forbid shared mutable cycles.&lt;&#x2F;p&gt;
&lt;p&gt;This seems like a huge limitation, until you realize that &lt;strong&gt;the vast majority of programs do not need DLLs.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;You need a DLL for: A text editor&#x27;s buffer, a kernel&#x27;s task scheduler, or a high-performance LRU cache.&lt;&#x2F;li&gt;
&lt;li&gt;You do NOT need a DLL for: A web server, a database client, a CLI tool, or a business application.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;In CLEAR, you&#x27;d have to use a list to manage the pointers, like so.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT List &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;nodes: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Node&lt;&#x2F;span&gt;&lt;span&gt;[]
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Node &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;val: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;prev_idx: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;next_idx: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;If this &lt;em&gt;IS&lt;&#x2F;em&gt; your product&#x2F;business, CLEAR will probably hinder you rather than help you.&lt;&#x2F;li&gt;
&lt;li&gt;CLEAR is designed to make optimization for cache locality as EASY as possible (without having to manage literally all memory like C).&lt;&#x2F;li&gt;
&lt;li&gt;By using IDs&#x2F;Indices instead of raw pointers, CLEAR guarantees:
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Memory Safety:&lt;&#x2F;strong&gt; No dangling pointers.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Concurrency Safety:&lt;&#x2F;strong&gt; No race conditions on cyclic structures.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Refactoring Ease:&lt;&#x2F;strong&gt; You can move the entire list in memory without breaking pointers.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;CLEAR optimizes for the 99% case, where safety and organization are more important than raw pointer soup.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Atomic Power: Shared Memory Without the Garbage Collector</title>
        <published>2025-12-01T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-atomic-power/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-atomic-power/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-atomic-power/">&lt;p&gt;In CLEAR, 99% of your data lives in &lt;strong&gt;Arenas&lt;&#x2F;strong&gt; (notebooks) that are incinerated when a function returns. This is fast and safe, but it has one flaw: &lt;strong&gt;Data cannot survive the death of its creator.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Sometimes, you need data to live longer than the function that created it.&lt;&#x2F;li&gt;
&lt;li&gt;Sometimes, you need data to be shared across multiple threads running in parallel.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;Enter the &#x27;shared&#x27; Capability and &lt;code&gt;shared:atomic&lt;&#x2F;code&gt;.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;1-what-is-the-shared-capability&quot;&gt;1. What is the &#x27;shared&#x27; Capability?&lt;&#x2F;h2&gt;
&lt;p&gt;In CLEAR, we separate &lt;strong&gt;Types&lt;&#x2F;strong&gt; from &lt;strong&gt;Capabilities&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Type:&lt;&#x2F;strong&gt; What the object &lt;em&gt;is&lt;&#x2F;em&gt; (e.g., &lt;code&gt;User&lt;&#x2F;code&gt;).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Capability:&lt;&#x2F;strong&gt; How the object is &lt;em&gt;accessed&lt;&#x2F;em&gt; (e.g., &lt;code&gt;shared&lt;&#x2F;code&gt;).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The &lt;code&gt;shared&lt;&#x2F;code&gt; capability (Arc in Rust) allows an object to live in the &lt;strong&gt;Global Heap&lt;&#x2F;strong&gt;, survive outside its creator&#x27;s arena, and be shared safely across threads.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Acquisition: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Acquire &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;shared&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt; capability
&lt;&#x2F;span&gt;&lt;span&gt;sharedU = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SHARE&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;.new());
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;Usage: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Pass&lt;&#x2F;span&gt;&lt;span&gt; the &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;raw&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Type&lt;&#x2F;span&gt;&lt;span&gt; to functions
&lt;&#x2F;span&gt;&lt;span&gt;process(sharedU);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;2-atomics-primitives-in-the-ether&quot;&gt;2. Atomics: Primitives in the Ether&lt;&#x2F;h2&gt;
&lt;p&gt;For simple numeric types like counters, CLEAR uses the &lt;strong&gt;&lt;code&gt;shared:atomic&lt;&#x2F;code&gt;&lt;&#x2F;strong&gt; capability. An Atomic primitive lives in the Global Heap and can be safely mutated by multiple threads at the same time.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;counter = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;SHARE:&lt;&#x2F;span&gt;&lt;span&gt;atomic(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);      -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Create&lt;&#x2F;span&gt;&lt;span&gt; an atomic integer
&lt;&#x2F;span&gt;&lt;span&gt;counter.increment!();           -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Thread&lt;&#x2F;span&gt;&lt;span&gt;-safe mutation
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;3-how-clear-handles-them-the-magic-count&quot;&gt;3. How CLEAR Handles Them: &quot;The Magic Count&quot;&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR does not use a Tracing Garbage Collector (like Java&#x2F;Go) that pauses your program. Instead, CLEAR uses &lt;strong&gt;Deterministic Reference Counting&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Every &lt;code&gt;shared&lt;&#x2F;code&gt; object has a tiny backpack holding a number (the Reference Count). This number represents how many people are holding a handle to it.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Creation:&lt;&#x2F;strong&gt; Count = 1.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sharing:&lt;&#x2F;strong&gt; When you pass a &lt;code&gt;shared&lt;&#x2F;code&gt; object to a thread (&lt;code&gt;SPAWN&lt;&#x2F;code&gt;), Count increments.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Drop:&lt;&#x2F;strong&gt; When a thread finishes, its handle goes out of scope and Count decrements.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Destruction:&lt;&#x2F;strong&gt; The microsecond Count hits 0, the memory is freed instantly.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The Result:&lt;&#x2F;strong&gt; Zero &quot;Stop the World&quot; pauses. Memory is freed precisely when it&#x27;s no longer needed.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;4-the-law-no-shared-cycles&quot;&gt;4. The Law: No Shared Cycles&lt;&#x2F;h2&gt;
&lt;p&gt;Reference counting has one fatal weakness: &lt;strong&gt;Cycles.&lt;&#x2F;strong&gt; If A holds B, and B holds A, their RefCounts will never hit 0. They will leak memory forever.&lt;&#x2F;p&gt;
&lt;p&gt;CLEAR refuses to stop your program to scan for cycles. Therefore, CLEAR enforces &lt;strong&gt;The Law&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;A &lt;code&gt;shared&lt;&#x2F;code&gt; object CANNOT hold a reference to another &lt;code&gt;shared&lt;&#x2F;code&gt; object.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;the-topology&quot;&gt;The Topology&lt;&#x2F;h3&gt;
&lt;p&gt;This forces your memory to be a &lt;strong&gt;DAG&lt;&#x2F;strong&gt; (Directed Acyclic Graph). Data ownership always flows &quot;Down&quot; or &quot;Across,&quot; never &quot;Back Up.&quot;&lt;&#x2F;p&gt;
&lt;p&gt;By forbidding cycles, CLEAR guarantees:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;No Memory Leaks:&lt;&#x2F;strong&gt; It is mathematically impossible to leak a &lt;code&gt;shared&lt;&#x2F;code&gt; object.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;No Deadlocks:&lt;&#x2F;strong&gt; You avoid the circular dependencies that often lead to circular locking.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;No GC Pauses:&lt;&#x2F;strong&gt; There&#x27;s no need to scan the heap.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Feature&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Arena (Default)&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Shared &#x2F; Atomic&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Location&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Local Arena&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Global Heap&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Lifetime&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Function Scope&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Reference Counted&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Speed&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Blazing Fast (O(1))&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Fast (System Malloc)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Concurrency&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Thread-Private (Safe)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Thread-Safe&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Usage&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;99% of variables&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Shared counters, Queues, Configs&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Cost&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Zero GC&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Zero GC (Deterministic)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>THE MATCH DILEMMA</title>
        <published>2025-11-26T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-match-dilemma/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-match-dilemma/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-match-dilemma/">&lt;p&gt;In standard Tagged-Union &#x2F; Enum languages (Rust, Swift, Kotlin), the compiler forces you to &lt;code&gt;MATCH&lt;&#x2F;code&gt; every single case of a Union type.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;Rust&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-Rust &quot;&gt;&lt;code class=&quot;language-Rust&quot; data-lang=&quot;Rust&quot;&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span&gt; user {
&lt;&#x2F;span&gt;&lt;span&gt;    User::SignedIn(u) =&amp;gt; println!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, u.email),
&lt;&#x2F;span&gt;&lt;span&gt;    User::Guest =&amp;gt; println!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Welcome guest&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;    User::Banned =&amp;gt; println!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;You are banned&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;em&gt;The Friction:&lt;&#x2F;em&gt; If you only care about the email of signed-in users, you still have to write code to handle the Guest and Banned cases. If you add a &lt;code&gt;User::Moderator&lt;&#x2F;code&gt; later, your code breaks everywhere until you handle that new case.&lt;&#x2F;p&gt;
&lt;p&gt;This is &lt;strong&gt;Bureaucracy&lt;&#x2F;strong&gt;. It prioritizes the compiler&#x27;s needs over the developer&#x27;s intent.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-solution-clear-fortress-architecture&quot;&gt;The Solution: CLEAR (Fortress Architecture)&lt;&#x2F;h2&gt;
&lt;p&gt;CLEAR is a &lt;strong&gt;Fortress Language&lt;&#x2F;strong&gt;. It handles the &quot;Safety Gap&quot; at the public boundary, allowing your internal logic to flow smoothly.&lt;&#x2F;p&gt;
&lt;p&gt;In CLEAR, any Public Union &lt;em&gt;must&lt;&#x2F;em&gt; be able to behave as a Product (a struct with fields) by projecting a &lt;strong&gt;View&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CLEAR&lt;&#x2F;span&gt;&lt;span&gt; allows this!
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;If&lt;&#x2F;span&gt;&lt;span&gt; the user is &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;NOT SignedIn&lt;&#x2F;span&gt;&lt;span&gt;, .email returns a suitable default (empty string)
&lt;&#x2F;span&gt;&lt;span&gt;-- or handles the &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Nil &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;case&lt;&#x2F;span&gt;&lt;span&gt; implicitly &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; defined &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; the &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Fortress&lt;&#x2F;span&gt;&lt;span&gt; boundary.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;PRINT&lt;&#x2F;span&gt;&lt;span&gt;(getUser().email);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;selective-matching&quot;&gt;Selective Matching&lt;&#x2F;h3&gt;
&lt;p&gt;In CLEAR, you match only what you care about.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CASE&lt;&#x2F;span&gt;&lt;span&gt; getUser() &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OF
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SignedInUser AS&lt;&#x2F;span&gt;&lt;span&gt; u =&amp;gt; doSignedInUserThing(u);
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;No&lt;&#x2F;span&gt;&lt;span&gt; need to match &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Guest &lt;&#x2F;span&gt;&lt;span&gt;or &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Banned &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; you don&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;t care!
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;  -- They flow through to the default or are ignored.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;em&gt;The Benefit:&lt;&#x2F;em&gt; &lt;strong&gt;Refactoring Blast Radius: Zero.&lt;&#x2F;strong&gt; Adding a new case to a Union doesn&#x27;t break existing code that doesn&#x27;t care about that new case.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;why-this-is-safe&quot;&gt;Why this is Safe&lt;&#x2F;h3&gt;
&lt;p&gt;CLEAR projects a &lt;strong&gt;View&lt;&#x2F;strong&gt; of the data. If you access a field that only exists in one variant of a Union:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;If the variant matches:&lt;&#x2F;strong&gt; You get the data.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;If it doesn&#x27;t:&lt;&#x2F;strong&gt; You get a suitable default (defined at the boundary) or an explosion (&lt;code&gt;!!&lt;&#x2F;code&gt;) if you&#x27;ve marked it as mandatory.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;This preserves &lt;strong&gt;understandability&lt;&#x2F;strong&gt; and &lt;strong&gt;velocity&lt;&#x2F;strong&gt; without sacrificing safety.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Language&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Approach&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Result&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Rust&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Exhaustive Match&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Bureaucracy &amp;amp; Fragility&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Go&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Type Assertion&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Error-Prone &amp;amp; Verbose&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;CLEAR&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Projected View&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Flow &amp;amp; Flexibility&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;&lt;strong&gt;CLEAR optimizes for the developer&#x27;s intent, not the compiler&#x27;s pedantry.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>CLEAR EXAMPLES</title>
        <published>2025-11-22T00:00:00+00:00</published>
        <updated>2026-05-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://cuzzo.github.io/clear/docs/manifesto-examples/"/>
        <id>https://cuzzo.github.io/clear/docs/manifesto-examples/</id>
        
        <content type="html" xml:base="https://cuzzo.github.io/clear/docs/manifesto-examples/">&lt;h2 id=&quot;example-grammar&quot;&gt;Example Grammar&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; processUsers(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;users: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;[]) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Pipelines&lt;&#x2F;span&gt;&lt;span&gt; with &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SMOOTH&lt;&#x2F;span&gt;&lt;span&gt; operator &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;s&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;
&lt;&#x2F;span&gt;&lt;span&gt;  result = users &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS @u
&lt;&#x2F;span&gt;&lt;span&gt;    s&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UNNEST&lt;&#x2F;span&gt;&lt;span&gt; _.orders
&lt;&#x2F;span&gt;&lt;span&gt;    s&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;SELECT&lt;&#x2F;span&gt;&lt;span&gt; _.price * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;@u&lt;&#x2F;span&gt;&lt;span&gt;.discount
&lt;&#x2F;span&gt;&lt;span&gt;    s&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;REDUCE&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;, (acc, x) -&amp;gt; acc + x );
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Default&lt;&#x2F;span&gt;&lt;span&gt; to &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;high&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;; override &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; result is low
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;MUTABLE&lt;&#x2F;span&gt;&lt;span&gt; info = { &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;: [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;9&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;status&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;high&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt; result &amp;lt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1000 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN
&lt;&#x2F;span&gt;&lt;span&gt;    info = { &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;: [&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;], &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;status&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;low&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; info[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;][&lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Lambda&lt;&#x2F;span&gt;&lt;span&gt; with % sigil
&lt;&#x2F;span&gt;&lt;span&gt;myLambda = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;%(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;x: Number&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;) &lt;&#x2F;span&gt;&lt;span&gt;-&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  doIt();
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN TRUE&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;sigils&quot;&gt;SIGILS&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Sigil&lt;&#x2F;th&gt;&lt;th&gt;Meaning&lt;&#x2F;th&gt;&lt;th&gt;Example&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;%(...)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Lambda parameters&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;%(x, y) -&amp;gt; x + y&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;@&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Pipeline binding &#x2F; Directives&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;users AS @u&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;!!&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Explicit panic&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;list.get(i)!!&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;_&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;Pipeline placeholder&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;s&amp;gt; SELECT _.name&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;SMOOTH operator&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;data s&amp;gt; process&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;structs&quot;&gt;STRUCTS&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Point &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;name: &lt;&#x2F;span&gt;&lt;span&gt;String,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Number DEFAULT &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Number DEFAULT &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Recursive&lt;&#x2F;span&gt;&lt;span&gt; structure with &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;indirect&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;#39;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;STRUCT Node &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;value: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Int64&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;left:&lt;&#x2F;span&gt;&lt;span&gt; indirect &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Node&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;right:&lt;&#x2F;span&gt;&lt;span&gt; indirect &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Node
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN Point&lt;&#x2F;span&gt;&lt;span&gt;::distance(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;self: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Point&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;other: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Point&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Number
&lt;&#x2F;span&gt;&lt;span&gt;  -- ...
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;myPoint = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Point&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;20 &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;oPoint = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Point&lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;x: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#7697d6;&quot;&gt;y: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;10 &lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;Method&lt;&#x2F;span&gt;&lt;span&gt; call syntax (&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;UFCS&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;d = myPoint.distance(oPoint);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;control-flow&quot;&gt;CONTROL FLOW&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHILE Loop
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WHILE&lt;&#x2F;span&gt;&lt;span&gt; x &amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DO
&lt;&#x2F;span&gt;&lt;span&gt;  ...
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF &lt;&#x2F;span&gt;&lt;span&gt;... &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN BREAK &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ELSE
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;IF&lt;&#x2F;span&gt;&lt;span&gt; x == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN
&lt;&#x2F;span&gt;&lt;span&gt;  do1();
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ELSE_IF&lt;&#x2F;span&gt;&lt;span&gt; x == &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;2 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;THEN
&lt;&#x2F;span&gt;&lt;span&gt;  do2();
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;ELSE
&lt;&#x2F;span&gt;&lt;span&gt;  doElse();
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;-- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH Capability Block
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;WITH&lt;&#x2F;span&gt;&lt;span&gt; sharedAccount &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; acc {
&lt;&#x2F;span&gt;&lt;span&gt;  acc.balance += &lt;&#x2F;span&gt;&lt;span style=&quot;color:#cf6a4c;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;error-handling&quot;&gt;ERROR HANDLING&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#151515;color:#e8e8d3;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;FN&lt;&#x2F;span&gt;&lt;span&gt; myFunc(a, b, c) -&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  -- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR RAISE&lt;&#x2F;span&gt;&lt;span&gt; bubbles up the error
&lt;&#x2F;span&gt;&lt;span&gt;  val = fetchData(a, b, c) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR RAISE
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseHeader &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR EXIT &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Invalid Header&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; parseBody &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;OR EXIT &lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Invalid Body&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;   s&amp;gt; fetchUser
&lt;&#x2F;span&gt;&lt;span&gt;      s&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RECOVER&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DefaultUser&lt;&#x2F;span&gt;&lt;span&gt;())
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;CATCH ParseError WITH&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#99ad6a;&quot;&gt;Invalid Header&lt;&#x2F;span&gt;&lt;span style=&quot;color:#556633;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;  logInvalidHeader(%e.snapshot);
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RETURN&lt;&#x2F;span&gt;&lt;span&gt; defaultPage();
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;DEFAULT
&lt;&#x2F;span&gt;&lt;span&gt;  logUnknownError(%e);
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffb964;&quot;&gt;RAISE &lt;&#x2F;span&gt;&lt;span&gt;%e;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fbfdc;&quot;&gt;END
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
</feed>
