<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.3">Jekyll</generator><link href="https://kow.fm/feed.xml" rel="self" type="application/atom+xml" /><link href="https://kow.fm/" rel="alternate" type="text/html" /><updated>2025-08-23T00:00:20+00:00</updated><id>https://kow.fm/feed.xml</id><title type="html">KOW.FM</title><subtitle>Personal Blog and project site of Karl Oscar Weber the first: Artist, Designer , and Engineer specializing in delightful user interfaces.</subtitle><entry><title type="html">Zig</title><link href="https://kow.fm/zig" rel="alternate" type="text/html" title="Zig" /><published>2025-02-16T00:30:00+00:00</published><updated>2025-02-16T00:30:00+00:00</updated><id>https://kow.fm/zig</id><content type="html" xml:base="https://kow.fm/zig"><![CDATA[<p>I picked up this new book: <a href="https://pedropark99.github.io/zig-book/">Introduction to Zig</a>, written by <a href="https://pedro-faria.netlify.app">Pedro Duarte Faria</a>, a couple of weeks ago. I finished it today, and started to write a new programming language in it, named Mage.</p>

<p>Zig is small, simple, low level programming language suitable for high performance, embedded, and systems level tasks. It’s billed as a replacement to C; Which I think it is. And offers great interoperability with C. Like it’s really good. I initially became interested in learning Zig, because I kept seeing Rust compared to Zig, and I was learning Rust at the time. (A month ago). I really like Rust, but to me, Zig feels like a simpler alternative, at least on the memory management side. For the purposes I’m using it for, Writing a small embeddable programming language for the web, it’s a better choice.</p>

<h3 id="what-does-it-look-like">What does it look like:</h3>

<p>Here’s some Zig code:</p>

<div class="language-zig highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">const</span> <span class="n">std</span> <span class="o">=</span> <span class="nb">@import</span><span class="p">(</span><span class="s">"std"</span><span class="p">);</span>
<span class="k">const</span> <span class="n">testing</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">testing</span><span class="p">;</span>

<span class="k">export</span> <span class="k">fn</span> <span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="kt">i32</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="kt">i32</span><span class="p">)</span> <span class="kt">i32</span> <span class="p">{</span>
  <span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span><span class="p">;</span>
<span class="p">}</span>

<span class="k">test</span> <span class="s">"basic add functionality"</span> <span class="p">{</span>
  <span class="k">try</span> <span class="n">testing</span><span class="p">.</span><span class="nf">expect</span><span class="p">(</span><span class="n">add</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</span> <span class="o">==</span> <span class="mi">10</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Now what you see, is a C like syntax, with some keywords, variables, and types. Simple. <code class="language-plaintext highlighter-rouge">i32</code> means a 32 bit, signed, integer. You’ll often see <code class="language-plaintext highlighter-rouge">u8</code> which is a byte. function signatures are simple and expected, <code class="language-plaintext highlighter-rouge">fn</code> followed by the function name, some parameters, and a return value. The return values are just sittin’ at the end there. Afterwards a block is opened with a curly brace, and it’s assigned to the function. Stuff that we come to expect from these types of languages.</p>

<p>What made me real happy when I started learning Zig, (and earlier, Rust), is the direct inclusion of testing in the source code. I’m accustomed to seeing tests spread across a Ruby code base. Seeing them colocated with the code, at least initially, was great. Built in testing is legit.</p>

<p>Zig feels C like, in that C is very close to the memory. In zig, practically everything is just bytes. Each type is series of bytes put together in some way. Take a look at this:</p>

<div class="language-zig highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">const</span> <span class="n">std</span> <span class="o">=</span> <span class="nb">@import</span><span class="p">(</span><span class="s">"std"</span><span class="p">);</span>

<span class="k">pub</span> <span class="k">fn</span> <span class="n">isAlphabetic</span><span class="p">(</span><span class="n">c</span><span class="p">:</span> <span class="kt">u8</span><span class="p">)</span> <span class="k">bool</span> <span class="p">{</span>
	<span class="k">return</span> <span class="k">switch</span> <span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="p">{</span>
		<span class="sc">'A'</span><span class="o">...</span><span class="sc">'Z'</span><span class="p">,</span> <span class="sc">'a'</span><span class="o">...</span><span class="sc">'z'</span><span class="p">,</span> <span class="sc">'_'</span> <span class="o">=&gt;</span> <span class="kc">true</span><span class="p">,</span>
		<span class="k">else</span> <span class="o">=&gt;</span> <span class="kc">false</span><span class="p">,</span>
	<span class="p">};</span>
<span class="p">}</span>

<span class="k">test</span> <span class="s">"check charater's alphabeticality."</span> <span class="p">{</span>
	<span class="k">try</span> <span class="n">testing</span><span class="p">.</span><span class="nf">expect</span><span class="p">(</span><span class="n">isAlphabetic</span><span class="p">(</span><span class="sc">'a'</span><span class="p">));</span> <span class="c">// passes</span>
	<span class="k">try</span> <span class="n">testing</span><span class="p">.</span><span class="nf">expect</span><span class="p">(</span><span class="n">isAlphabetic</span><span class="p">(</span><span class="sc">'G'</span><span class="p">));</span> <span class="c">// passes</span>
	<span class="k">try</span> <span class="n">testing</span><span class="p">.</span><span class="nf">expect</span><span class="p">(</span><span class="n">isAlphabetic</span><span class="p">(</span><span class="sc">'9'</span><span class="p">));</span> <span class="c">// passes</span>
	<span class="k">try</span> <span class="n">testing</span><span class="p">.</span><span class="nf">expect</span><span class="p">(</span><span class="n">isAlphabetic</span><span class="p">(</span><span class="sc">'*'</span><span class="p">));</span> <span class="c">// fails</span>
<span class="p">}</span>
</code></pre></div></div>

<p>We’ve got a switch, with a series of ranges, that return true. But we’re passing a character to that switch. It’s checking the numerical value of the character, to ensure it’s within any of those ranges. Because characters are just numbers, Just bytes.</p>

<p>This: <code class="language-plaintext highlighter-rouge">u8</code>, means a byte. An unsigned 8 bit integer. In Zig you can have arbitrary bit-width integers, meaning, an integer as many bits wide as you want. <code class="language-plaintext highlighter-rouge">u19</code> would be an unsigned, 19 bit integer. <code class="language-plaintext highlighter-rouge">i5</code> is a signed 5 bit integer. floats can’t be arbitrarily long, we’ve got <code class="language-plaintext highlighter-rouge">f16</code>, <code class="language-plaintext highlighter-rouge">f32</code>, <code class="language-plaintext highlighter-rouge">f64</code>, <code class="language-plaintext highlighter-rouge">f80</code>, <code class="language-plaintext highlighter-rouge">f128</code>, and <code class="language-plaintext highlighter-rouge">c_longdouble</code>. Those arbitrary bit-width integers are exciting though. They make more sense when diving into unions, and making gnarly stuff.</p>

<h3 id="structs">Structs</h3>

<p>Structs are the loose object things in Zig, and are great. They act as namespaces, kinda, and let you pack data and functions together.</p>

<div class="language-zig highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">const</span> <span class="n">std</span> <span class="o">=</span> <span class="nb">@import</span><span class="p">(</span><span class="s">"std"</span><span class="p">);</span>
<span class="c">// const Self = @This();</span>
<span class="k">pub</span> <span class="k">const</span> <span class="n">Color</span> <span class="o">=</span> <span class="k">enum</span> <span class="p">{</span>
  <span class="n">red</span><span class="p">,</span>
  <span class="n">green</span><span class="p">,</span>
  <span class="n">blue</span><span class="p">,</span>
  <span class="n">yellow</span>
<span class="p">};</span>

<span class="k">const</span> <span class="n">Person</span> <span class="o">=</span> <span class="k">struct</span> <span class="p">{</span>
  <span class="n">name</span><span class="p">:</span> <span class="p">[]</span><span class="k">const</span> <span class="kt">u8</span><span class="p">,</span>
  <span class="n">age</span><span class="p">:</span> <span class="kt">usize</span><span class="p">,</span>
  <span class="n">favorite_color</span><span class="p">:</span> <span class="n">Color</span><span class="p">,</span>
	
  <span class="k">pub</span> <span class="k">fn</span> <span class="n">init</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="p">[]</span><span class="k">const</span> <span class="kt">u8</span><span class="p">,</span> <span class="n">age</span><span class="p">:</span> <span class="kt">usize</span><span class="p">)</span> <span class="n">Person</span> <span class="p">{</span>
    <span class="k">return</span> <span class="n">Person</span> <span class="p">{</span>
      <span class="p">.</span><span class="py">name</span> <span class="o">=</span> <span class="n">name</span><span class="p">,</span>
      <span class="p">.</span><span class="py">age</span> <span class="o">=</span> <span class="n">age</span><span class="p">,</span>
      <span class="p">.</span><span class="py">favorite_color</span> <span class="o">=</span> <span class="n">Color</span><span class="p">.</span><span class="py">blue</span><span class="p">,</span>
    <span class="p">};</span>
  <span class="p">}</span>
<span class="p">};</span>

<span class="k">test</span> <span class="s">"who is this?"</span> <span class="p">{</span>
  <span class="k">const</span> <span class="n">jim</span> <span class="o">=</span> <span class="n">Person</span><span class="p">.</span><span class="nf">init</span><span class="p">(</span><span class="s">"James T Kirk"</span><span class="p">,</span> <span class="mi">43</span><span class="p">);</span>
  <span class="k">try</span> <span class="n">std</span><span class="p">.</span><span class="py">testing</span><span class="p">.</span><span class="nf">expect</span><span class="p">(</span><span class="n">jim</span><span class="p">.</span><span class="py">age</span> <span class="o">==</span> <span class="mi">43</span><span class="p">);</span> <span class="c">// passes</span>
  <span class="c">// does not compile, don't try.</span>
  <span class="k">try</span> <span class="n">std</span><span class="p">.</span><span class="py">testing</span><span class="p">.</span><span class="nf">expect</span><span class="p">(</span><span class="n">jim</span><span class="p">.</span><span class="py">name</span> <span class="o">==</span> <span class="s">"James T Kirk"</span><span class="p">);</span> <span class="c">// does not compile.</span>
<span class="p">}</span>
</code></pre></div></div>

<p>What’s that note about not compiling? Well we’re trying to compare two strings. Strings are of type: <code class="language-plaintext highlighter-rouge">[]const u8</code>, which means a constant array of <code class="language-plaintext highlighter-rouge">u8</code> bytes. Because strings are just… strings of bytes. arrays of bytes. Just like in C, and in reality really. Anyways to compare them you’ll need to compare the memory of them, thankfully the Zig standard library has something we can use:</p>

<div class="language-zig highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">// ... abbreviated</span>
  <span class="k">try</span> <span class="n">std</span><span class="p">.</span><span class="py">testing</span><span class="p">.</span><span class="nf">expect</span><span class="p">(</span><span class="n">std</span><span class="p">.</span><span class="py">mem</span><span class="p">.</span><span class="nf">eql</span><span class="p">(</span><span class="kt">u8</span><span class="p">,</span> <span class="n">jim</span><span class="p">.</span><span class="py">name</span><span class="p">,</span> <span class="s">"James T Kirk"</span><span class="p">));</span> <span class="c">// passes now.</span>
<span class="c">// ...</span>
</code></pre></div></div>

<h3 id="memory">Memory</h3>

<p>Zig is a memory managed language. I’m not very good at those yet, but It’s memory management model thing seems pretty simple. Take a look at what I’ve got down here:</p>

<div class="language-zig highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">const</span> <span class="n">std</span> <span class="o">=</span> <span class="nb">@import</span><span class="p">(</span><span class="s">"std"</span><span class="p">);</span>
<span class="k">const</span> <span class="n">stdout</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">io</span><span class="p">.</span><span class="nf">getStdOut</span><span class="p">().</span><span class="nf">writer</span><span class="p">();</span>

<span class="k">pub</span> <span class="k">fn</span> <span class="n">main</span><span class="p">()</span> <span class="o">!</span><span class="k">void</span> <span class="p">{</span>
  <span class="k">const</span> <span class="n">name</span> <span class="o">=</span> <span class="s">"karl"</span><span class="p">;</span>
  <span class="k">const</span> <span class="n">status</span> <span class="o">=</span> <span class="s">"totalled"</span><span class="p">;</span>
  <span class="k">try</span> <span class="n">stdout</span><span class="p">.</span><span class="nf">print</span><span class="p">(</span><span class="s">"{s}'s car was {s}."</span><span class="p">,</span> <span class="o">.</span><span class="p">{</span><span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="p">});</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Resulting in:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>karl<span class="s1">'s car was totalled.
</span></code></pre></div></div>

<p>Now theres a lot here, but in that main function, you’ve got name, and status. They’re constants, so they’re not changing, and below we print some stuff out with the <code class="language-plaintext highlighter-rouge">stdout.print</code> thing. When the program exits all of the memory is freed. But what would happen if this wasn’t the main function? What would the memory for name and status go? Will it be freed?</p>

<p>Yes it will. Memory, or variables that are used like this are placed on the stack. This memory is freed at the end of each function. It’s stack memory. If you want memory to stick around, you’ll need to put it on the heap. To do that you’ll need a memory allocator.</p>

<div class="language-zig highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">const</span> <span class="n">std</span> <span class="o">=</span> <span class="nb">@import</span><span class="p">(</span><span class="s">"std"</span><span class="p">);</span>
<span class="k">const</span> <span class="n">stdout</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">io</span><span class="p">.</span><span class="nf">getStdOut</span><span class="p">().</span><span class="nf">writer</span><span class="p">();</span>
<span class="k">const</span> <span class="n">ArrayList</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">ArrayList</span><span class="p">;</span>
<span class="k">const</span> <span class="n">testing</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">testing</span><span class="p">;</span>

<span class="c">// make a Card struct</span>
<span class="k">const</span> <span class="n">Card</span> <span class="o">=</span> <span class="k">struct</span> <span class="p">{</span>
  <span class="n">name</span><span class="p">:</span> <span class="p">[]</span><span class="k">const</span> <span class="kt">u8</span><span class="p">,</span>
  <span class="n">suit</span><span class="p">:</span> <span class="p">[]</span><span class="k">const</span> <span class="kt">u8</span><span class="p">,</span>
<span class="p">};</span>

<span class="c">// Make a Cards List</span>
<span class="k">const</span> <span class="n">Cards</span> <span class="o">=</span> <span class="n">ArrayList</span><span class="p">(</span><span class="n">Card</span><span class="p">);</span>

<span class="k">test</span> <span class="s">"I mean whatever"</span> <span class="p">{</span>
  <span class="k">var</span> <span class="n">deck</span> <span class="o">=</span> <span class="n">Cards</span><span class="p">.</span><span class="nf">init</span><span class="p">(</span><span class="n">testing</span><span class="p">.</span><span class="py">allocator</span><span class="p">);</span>
  <span class="k">defer</span> <span class="n">deck</span><span class="p">.</span><span class="nf">deinit</span><span class="p">();</span>

  <span class="k">try</span> <span class="n">deck</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">Card</span><span class="p">{</span> <span class="p">.</span><span class="py">name</span> <span class="o">=</span> <span class="s">"Queen"</span><span class="p">,</span> <span class="p">.</span><span class="py">suit</span> <span class="o">=</span> <span class="s">"hearts"</span><span class="p">,</span> <span class="p">});</span>
  <span class="k">try</span> <span class="n">deck</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">Card</span><span class="p">{</span> <span class="p">.</span><span class="py">name</span> <span class="o">=</span> <span class="s">"King"</span><span class="p">,</span> <span class="p">.</span><span class="py">suit</span> <span class="o">=</span> <span class="s">"hearts"</span><span class="p">,</span> <span class="p">});</span>
  
  <span class="k">const</span> <span class="n">one</span> <span class="o">=</span> <span class="n">deck</span><span class="p">.</span><span class="nf">pop</span><span class="p">();</span>
  <span class="k">const</span> <span class="n">two</span> <span class="o">=</span> <span class="n">deck</span><span class="p">.</span><span class="nf">pop</span><span class="p">();</span>
  
  <span class="k">try</span> <span class="n">stdout</span><span class="p">.</span><span class="nf">print</span><span class="p">(</span><span class="s">"Card One is the {s} of {s}.</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">.</span><span class="p">{</span><span class="n">one</span><span class="p">.</span><span class="py">name</span><span class="p">,</span> <span class="n">one</span><span class="p">.</span><span class="py">suit</span><span class="p">});</span>
  <span class="k">try</span> <span class="n">stdout</span><span class="p">.</span><span class="nf">print</span><span class="p">(</span><span class="s">"Card Two is the {s} of {s}.</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">.</span><span class="p">{</span><span class="n">two</span><span class="p">.</span><span class="py">name</span><span class="p">,</span> <span class="n">two</span><span class="p">.</span><span class="py">suit</span><span class="p">});</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Ok that above is a bad example because there’s a lot going on. But let’s walk through it. First we make a card struct, it’s got two properties, or attributes. I don’t know what they’re called. They’re strings. But specifically, const strings. So their size won’t change. Then we call the <code class="language-plaintext highlighter-rouge">ArrayList</code> Function. This makes a type and returns it. The type is a growing, heap allocated, array. It’s typed, and we supply it a type of <code class="language-plaintext highlighter-rouge">Card</code>. So we end up with <code class="language-plaintext highlighter-rouge">Cards</code>. I very much like this.</p>

<p>Now, it’s this allocator thing that actually does the allocation of memory. It grabs some memory on the heap, and gives you back an ArrayList that you can put stuff into. <code class="language-plaintext highlighter-rouge">append()</code> inserts <code class="language-plaintext highlighter-rouge">Card</code> structs into the ArrayList. We can <code class="language-plaintext highlighter-rouge">pop</code> those values and use them below in the print statements. But putting this all in a single test seems silly, let’s have a helper function.</p>

<div class="language-zig highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">const</span> <span class="n">std</span> <span class="o">=</span> <span class="nb">@import</span><span class="p">(</span><span class="s">"std"</span><span class="p">);</span>
<span class="k">const</span> <span class="n">stdout</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">io</span><span class="p">.</span><span class="nf">getStdOut</span><span class="p">().</span><span class="nf">writer</span><span class="p">();</span>
<span class="k">const</span> <span class="n">ArrayList</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">ArrayList</span><span class="p">;</span>
<span class="k">const</span> <span class="n">Allocator</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">mem</span><span class="p">.</span><span class="py">Allocator</span><span class="p">;</span>
<span class="k">const</span> <span class="n">testing</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">testing</span><span class="p">;</span>

<span class="k">const</span> <span class="n">Card</span> <span class="o">=</span> <span class="k">struct</span> <span class="p">{</span> <span class="n">name</span><span class="p">:</span> <span class="p">[]</span><span class="k">const</span> <span class="kt">u8</span><span class="p">,</span> <span class="n">suit</span><span class="p">:</span> <span class="p">[]</span><span class="k">const</span> <span class="kt">u8</span><span class="p">,</span> <span class="p">};</span>
<span class="k">const</span> <span class="n">Cards</span> <span class="o">=</span> <span class="n">ArrayList</span><span class="p">(</span><span class="n">Card</span><span class="p">);</span>

<span class="c">// returns a deck of cards</span>
<span class="k">pub</span> <span class="k">fn</span> <span class="n">makeDeck</span><span class="p">(</span><span class="n">allocator</span><span class="p">:</span> <span class="n">Allocator</span><span class="p">)</span> <span class="o">!</span><span class="n">Cards</span> <span class="p">{</span>
  <span class="k">var</span> <span class="n">deck</span> <span class="o">=</span> <span class="n">Cards</span><span class="p">.</span><span class="nf">init</span><span class="p">(</span><span class="n">allocator</span><span class="p">);</span>
  <span class="k">try</span> <span class="n">deck</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">Card</span><span class="p">{</span> <span class="p">.</span><span class="py">name</span> <span class="o">=</span> <span class="s">"Queen"</span><span class="p">,</span> <span class="p">.</span><span class="py">suit</span> <span class="o">=</span> <span class="s">"hearts"</span><span class="p">,</span> <span class="p">});</span>
  <span class="k">try</span> <span class="n">deck</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">Card</span><span class="p">{</span> <span class="p">.</span><span class="py">name</span> <span class="o">=</span> <span class="s">"King"</span><span class="p">,</span> <span class="p">.</span><span class="py">suit</span> <span class="o">=</span> <span class="s">"hearts"</span><span class="p">,</span> <span class="p">});</span>
  <span class="k">return</span> <span class="n">deck</span><span class="p">;</span>
<span class="p">}</span>

<span class="k">test</span> <span class="s">"I mean whatever"</span> <span class="p">{</span>
  <span class="k">var</span> <span class="n">deck</span> <span class="o">=</span> <span class="k">try</span> <span class="n">makeDeck</span><span class="p">(</span><span class="n">testing</span><span class="p">.</span><span class="py">allocator</span><span class="p">);</span>
  <span class="k">defer</span> <span class="n">deck</span><span class="p">.</span><span class="nf">deinit</span><span class="p">();</span>

  <span class="k">const</span> <span class="n">one</span> <span class="o">=</span> <span class="n">deck</span><span class="p">.</span><span class="nf">pop</span><span class="p">();</span>
  <span class="k">const</span> <span class="n">two</span> <span class="o">=</span> <span class="n">deck</span><span class="p">.</span><span class="nf">pop</span><span class="p">();</span>

  <span class="k">try</span> <span class="n">stdout</span><span class="p">.</span><span class="nf">print</span><span class="p">(</span><span class="s">"Card One is the {s} of {s}.</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">.</span><span class="p">{</span><span class="n">one</span><span class="p">.</span><span class="py">name</span><span class="p">,</span> <span class="n">one</span><span class="p">.</span><span class="py">suit</span><span class="p">});</span>
  <span class="k">try</span> <span class="n">stdout</span><span class="p">.</span><span class="nf">print</span><span class="p">(</span><span class="s">"Card Two is the {s} of {s}.</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">.</span><span class="p">{</span><span class="n">two</span><span class="p">.</span><span class="py">name</span><span class="p">,</span> <span class="n">two</span><span class="p">.</span><span class="py">suit</span><span class="p">});</span>
<span class="p">}</span>
</code></pre></div></div>

<p>In this new example, we give makeDeck an allocator, and it gives us back a deck with some heap allocated memory. Notice the return value: <code class="language-plaintext highlighter-rouge">!Cards</code>, that means that, possibly, it could fail. That’s why we’re putting <code class="language-plaintext highlighter-rouge">try</code> everywhere. (Try/Catch works differently in Zig.).</p>

<p>Once we get our deck back we can play around with it and print our stuff.</p>

<p>Now try removing the line: <code class="language-plaintext highlighter-rouge">defer deck.deinit();</code>. If you do, and you run some tests: <code class="language-plaintext highlighter-rouge">zig test deck.zig</code>, then you’ll see a whole bunch of debug output, and at the bottom the messages:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>All 1 tests passed.
1 errors were logged.
1 tests leaked memory.
</code></pre></div></div>

<p>It’s catching our leaked memory! Why? because when you use an allocator it puts memory on the heap, not the stack. So the variables and data you make don’t get freed at the end of the block. They stick around. It’s up to you to free them later.</p>

<h3 id="defer">Defer</h3>

<p>Zig has this thing called <code class="language-plaintext highlighter-rouge">defer</code> which defers an action until the end of a block.</p>

<div class="language-zig highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">const</span> <span class="n">std</span> <span class="o">=</span> <span class="nb">@import</span><span class="p">(</span><span class="s">"std"</span><span class="p">);</span>
<span class="k">const</span> <span class="n">testing</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">testing</span><span class="p">;</span>
<span class="k">const</span> <span class="n">print</span> <span class="o">=</span> <span class="n">std</span><span class="p">.</span><span class="py">debug</span><span class="p">.</span><span class="py">print</span><span class="p">;</span>

<span class="k">test</span> <span class="s">"I mean whatever"</span> <span class="p">{</span>
  <span class="k">var</span> <span class="n">count</span><span class="p">:</span> <span class="kt">usize</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span>
  <span class="n">print</span><span class="p">(</span><span class="s">"count is:{d}</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">.</span><span class="p">{</span><span class="n">count</span><span class="p">});</span>
  <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span>
  <span class="k">defer</span> <span class="p">{</span>
    <span class="n">print</span><span class="p">(</span><span class="s">"count is:{d}</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">.</span><span class="p">{</span><span class="n">count</span><span class="p">});</span>
  <span class="p">}</span>
  <span class="k">defer</span> <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span>
  <span class="k">defer</span> <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span>
  <span class="n">print</span><span class="p">(</span><span class="s">"count is:{d}</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">.</span><span class="p">{</span><span class="n">count</span><span class="p">});</span>
<span class="p">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">defer</code> blocks are executed in reverse order. Which is actually fantastic. Oftentimes you build up some heap allocated state from top to bottom, but as you go down you get deeper and deeper into the state of some more complicated data structures. With <code class="language-plaintext highlighter-rouge">defer</code> you can pair allocations with <code class="language-plaintext highlighter-rouge">deinit()</code>, and unwind that state, and free that memory.</p>

<p>I can talk a lot more about this. Like about slices, and how they are easier to work with than arrays. Or that strings are just arrays and working with them is easier when they are slices. But I’ll get into that later when I describe more of the internals of <strong>Mage</strong> and <strong>Kona</strong> which will be written in Zig.</p>

<p>Talk to you soon.</p>

<p>-kow</p>]]></content><author><name></name></author><category term="blog" /><category term="programming-languages" /><category term="zig" /><category term="mage" /><category term="kona" /><summary type="html"><![CDATA[I talk a little about the Zig progrmaming language. A low level, fast, modern C.]]></summary></entry><entry><title type="html">Fate &amp;amp; Circumstance</title><link href="https://kow.fm/fate-circumstance" rel="alternate" type="text/html" title="Fate &amp;amp; Circumstance" /><published>2025-02-08T00:26:00+00:00</published><updated>2025-02-08T00:26:00+00:00</updated><id>https://kow.fm/fate-circumstance</id><content type="html" xml:base="https://kow.fm/fate-circumstance"><![CDATA[<p>Fate, circumstance, and the unreliability of our cities’ electrical grid have mildly altered the lives of about a dozen people. Earlier today, while driving on the highway, a car collided with the driver side of our vehicle, while going through an intersection. There was a sudden power outage to the city, shutting off all the lights. To me, as I approached the intersection, it appeared funky, and not right. I began to slow down, but not enough. Another vehicle making their way across the vast intersection hit my car as we serendipitously entered the same physical space in the cosmos, at the same time.</p>

<p>If I was going a little slower, or a little faster, we would be dead. The collision happened towards the aft of my vehicle, just ahead of the left rear tire. The conflicting vectors of the colliding vehicle, and our own, caused our vehicle to spin 200 degrees counter clockwise and land with a calm jerk and a slight startle. Indeed this motion swung my car’s big ass around, and swiped off the front bumper of another vehicle just sittin’ there. But the spinning motion itself dissipated the momentum, and diffused the kinetic energy. Nobody was injured beyond a bump, or scrape, and an inconvenience. The cars looked like paper maché models partially desiccated by a toddler.</p>

<p>Some folks would say: “how lucky, that our modern cars are so safe to render a collision like this no big deal”. But I am not that man.</p>

<p>Cars are Aluminum coffins, death machines we’re forced to enter, at the danger of never leaving them, because of the inconvenient and vast world we’ve constructed that require them. Car culture is Violence. It turns everyone into a deadly enemy, and routine, into danger. I fucking hate driving.</p>

<p>The vehicle we immediately collided with held a mother and two small children, they exited the vehicle, unscathed but shaken.  Still clutching their new, colorful toy guns. Harmless specters of America’s other deadly obsession, Firearms. Ironic. Poetic. Often, My own son, three years old, sings: “A B C D E F GUN!”. A grim innocence that we allow. We hasten to instruct, that actual weapons make us all unsafe.</p>

<p>My initial reaction, upon collision, was of immediate relief, neither fear nor surprise. I saw the near fatality less than two seconds before impact. A narrow window, closing, was before the car crossing the intersection. I reasoned the safest place for me to go, would be into that spot, where there was space to dissipate the kinetic energy. I truly didn’t realize until later how close I was to serious injury or death. A moment of haste or hesitation and it would be over. That’s all she wrote. Fin.</p>

<p>I checked on my only passenger, my wife, safe, unscathed. Myself, unscathed. Then hopped out of the car and immediately checked on the others affected. Everyone safe and unharmed. Now financial and time inconvenience is all that remains.</p>

<p>As I mentioned earlier. The collision was precipitated by a city wide power outage. In fact, as the fireman and paramedics that quickly attended us said, fire alarms across the city had been going off because of the outage. The police said that this same intersection had already lost power, and been restored only moments before. The arrival of first responders felt eerily quick. A handful of seconds and they were there. I didn’t imagine it. They were already on their way, unaware as to what danger could be found, but finding it almost instantly.</p>

<p>My wife has become rather good at fitness, she wears an Apple Watch. And that thing immediately called the cops. It knew we crashed, a prescient message on the screen: “It looks like you’ve been in a crash.”. Yes. I know.</p>

<p>There is a clear and stark division between knowing ABOUT something, hypothetically, and understand and mitigating those risks. Quite another to understand intimately the danger by narrowly escaping death in one of these death machines. That’s experience. Having crossed that division at 37 years old in a near fatal incident, my calm exhortations to be safe, careful, and suspicious, are now haunted by the sound of death’s scythe cutting through the air just ahead of me. A near miss.</p>

<p>I’m tired. Very mildly shaken. But mostly Angry. I don’t have time to handle the inconvenience of another tragedy. I attempt to make Stability and Reliability my reputation. A struggle. Now further complicated by this messy thing we call life. On Monday I start a new job, my family is safe, and I have a warm place to sleep. Trauma, some new hidden scars, but nothing beyond what life promises. Which is just life.</p>

<p>-kow</p>]]></content><author><name></name></author><category term="blog" /><category term="cars" /><category term="cars-suck" /><summary type="html"><![CDATA[We got into one of those HIGH SPEED collisions while piloting a vehicle and holy shit]]></summary></entry><entry><title type="html">My brother in law committed suicide.</title><link href="https://kow.fm/My-brother-in-law-committed-suicide" rel="alternate" type="text/html" title="My brother in law committed suicide." /><published>2025-02-06T00:26:00+00:00</published><updated>2025-02-06T00:26:00+00:00</updated><id>https://kow.fm/My-brother-in-law-committed-suicide</id><content type="html" xml:base="https://kow.fm/My-brother-in-law-committed-suicide"><![CDATA[<p>I only met them a few times, My sister’s Husband. We’re not on the best relationship terms, my direct family and I, because of all the trump supporter stuff. You know, the explicit support of republicans and their agenda. That sort of thing. What got me really mad today was that my dad called me asking if I could help them find his phone. The dead husband’s phone, the one that just shot himself. Apparently they can’t find it.</p>

<p>Yes I use iPhones, so I should be able to find it, right?. The conversation quickly went to why he killed himself. They don’t know, maybe he was depressed or sad. No signs of mental distress. My Dad said it’s everyone’s choice what they do. That’s true, but it’s also a choice to make Guns so readily available in America that anyone can have one. “<em>It’s their right to have one</em>”. Sure, but this is the result, He’s dead. “<em>No but it was his choice to kill himself</em>”. A choice that would be so fucking hard to carry out if he didn’t have a fucking gun where you just pull the trigger and something dies.</p>

<p>I got mad at him, because I like my dad and he’s pretty reasonable. But this Gun shit pisses me off. Because Our rights and the Law and the rules are all made up. We make them up. And when we have rules and laws and a culture to follow them, things happen. We create an environment. Right now we have an environment in America where gun deaths are easy to come by. Suicide is easy, Mass Shootings are easy, and School Shootings are easy. You want your rights, sure, have your guns, but this is the result.</p>

<p>America <em>wants</em> mass suicide and school shootings. That’s the purpose of these laws. <strong>The purpose of a system is what it does</strong>. It’s a fucking fact. Our system kills people. That is the design.</p>

<p>I feel really sad for my sister. But I can’t mourn or be gentle or careful because we rarely speak. I don’t know him very well at all, there’s no emotional sadness. I’m not gonna fake that. I am fucking enraged though. So mad that it can be so clear why something happened, and the people that you used to look up to and turn to for advice and wisdom, will say reductive defeated things to explain away why someone killed themselves.</p>

<p>The difference between a bad day and his last day, was a gun.</p>

<hr />

<p>I don’t know if you’ve been reading the news lately, but in America, there’s mass deportations going on. Or at least the attempt of it. The mass dissolution of our rights, and our institutions. The looting of our public works and sensitive data. The robber barons have returned in force and are taking everything they can get their hands on. But we don’t have to cede anything to them, or accept it, or do nothing.</p>

<p>I’m enraged because a Coup is genuinely being carried out in my country in broad daylight, but we are culturally bound from doing anything because our entire society is built around respecting capital. The rich are smart, the masses dumb. They are skilled, we are not. The police protect the property of the wealthy, while trampling the rights and well being of everyone else. Which is everyone. I’m fucking mad because I NEED to work, and provide for my family, and pay off a shit ton of debt, when I also NEED to be organizing and educating. Beating the doors of my neighbors down, and demanding that they bear witness to the wholesale destruction of what we take for granted.</p>

<p>We are not powerless, or outnumbered. I will not succumb to fear, nor will I become overwhelmed and allow my joy and focus to wander and be ruined. I’ve learned that in America nobody is coming to save you, you have to save yourself.</p>

<p>Nobody is coming to save us, we have to save ourselves.</p>

<p>Nothing will get better unless we <strong>MAKE</strong> it better.</p>

<p>I’ll tell you what I’m going to do. I’m going to organize. Double down on my studies of Spanish, economics, and our political system. I’ll spread as much literature and knowledge of our rights in this country as I can, with the time that I have. I won’t stand a racist shit to persist in my presence without making them feel unwelcome, and ashamed. I’m also gonna get jacked as fuck.</p>

<p>I don’t give a fuck about debating or reasoning with the shitheads. That’s not how you change things. You force change. You change the culture, what’s accepted, and what’s not acceptable by making a stand. Over and Over and Over again. You give the people, the majority, the tools to know what their capable of, and the courage to wield their power. We are all in this together, not one of us are alone.</p>

<p>If you want a better world, make one.</p>

<p>I’m gonna fucking make one.</p>

<p>-kow</p>]]></content><author><name></name></author><category term="blog" /><category term="suicide" /><category term="fuck-you-i-wont-do-what-you-tell-me" /><summary type="html"><![CDATA[Karl talks about how fucking pissed he is after learning that his brother in law committed suicide and his dad shrugged and oh welled it away saying that guns are still our right to have.]]></summary></entry><entry><title type="html">Systems Work Better With Slack.</title><link href="https://kow.fm/systems-work-better-with-slack" rel="alternate" type="text/html" title="Systems Work Better With Slack." /><published>2025-02-03T00:26:00+00:00</published><updated>2025-02-03T00:26:00+00:00</updated><id>https://kow.fm/systems-work-better-with-slack</id><content type="html" xml:base="https://kow.fm/systems-work-better-with-slack"><![CDATA[<p>Every system is connected to the next. A chain of connected things. Assumptions, needs, environments, concerns. Each system has a capacity, and every system needs slack to perform well under normal loads and to bear surprises under strain. Money is a system. Time is a system. Thought is a system. Space is a system. Health is a system. etc… etc… etc…</p>

<p>I often find myself stretched thin, breaking the money or time systems. Not enough money, not enough time. In a capitalist society, the two are tightly connected. My Money system doesn’t have enough slack. I have a budget. I usually keep within spending limits. But it’s that lack of slack that breaks things. The 3 birthday’s in a row in the same month, or the unexpected bill. Living within a budget becomes harder and harder every day. Having a robust money “system” just means having more money. A buffer, a cache, a cushion.</p>

<p>Time is the same way, although it feels like it operates more like trains do. I have responsibilities, promises that I’ve made. Fulfilling a promise, or keeping my word takes up a certain amount of time. Work takes time. If a task or project takes a little more time than anticipated, then I have to “borrow” that time from somewhere. Sleep? Family? Fun? The next Promise? Other systems. Other commitments. All systems run on time, and running out of time is no fun. Like trains crashing. A Wreck.</p>

<hr />

<p>My career is engineering, programming, and design. Estimates are always a little fuzzy. Oftentimes I’m asked to do things, or solve problems I’ve never faced before. To offer my perspective and expertise in delivering solutions, but towards unfamiliar concerns. The estimations always start the same, sus out what’s familiar, and what’s not. Allot time, based on past experience, provide a buffer. Later, during the act, the true requirements present themselves. Well laid plans change, time scales slip. It’s in that buffer that I find respite and rescue. A saving, bonus zone of attention and energy to overcome the unexpected.</p>

<p>The only way I’ve found to relieve stress, in many senses of that word, is to have more slack in my systems. Under schedule, under promise, over deliver, deliver early, spend less, budget more. I now plan 3 or 4 days of actual work. It means choosing to do far far less than I’m honestly capable, to make certain every train runs on time, and every promise is fulfilled. Putting slack back into the system of my life. My daily efforts to survive, provide, breath, and live.</p>

<p>Leave more time to make mistakes, and recover from them. To do nothing, think of nothing, and expect nothing. Sit with yourself a bit longer.</p>

<p>It’s incredibly difficult, I feel like I’m getting better at it though.</p>

<p>-kow</p>]]></content><author><name></name></author><category term="blog" /><category term="systems" /><category term="slack" /><summary type="html"><![CDATA[Let's talk about capacity, and having enough capacity.]]></summary></entry><entry><title type="html">new-design</title><link href="https://kow.fm/new-design" rel="alternate" type="text/html" title="new-design" /><published>2025-02-03T00:10:00+00:00</published><updated>2025-02-03T00:10:00+00:00</updated><id>https://kow.fm/new-design</id><content type="html" xml:base="https://kow.fm/new-design"><![CDATA[<p>Hi Friends,</p>

<p>New year, new design. This is my new website for 2025. Hopefully for far beyond this year too.</p>

<p>It’s designed more minimialistic than past experiments. I’ve gotten a lot better with CSS Grid. Which is Over powered. I also have a fun little idea about adding grunge and graffiti to the blog, as if it was some wall somewhere, arbitrarily. Like covering text, and images in silly ways. I think it will be fun. Also it gives me a recurring outlet for small pieces of Art. Like for fun. Just hacking away on my website when I’m bored, vandalizing it.</p>

<p>I’m gonna vandalize this web page.</p>

<p>-kow</p>]]></content><author><name>Karl Oscar Weber</name></author><category term="design" /><category term="html" /><category term="css" /><summary type="html"><![CDATA[With the new year, a new, refreshed, blog design thing.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://kow.fm/assets/blog/new-design/new-design-banner.jpg" /><media:content medium="image" url="https://kow.fm/assets/blog/new-design/new-design-banner.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">The wren programming language</title><link href="https://kow.fm/the-wren-programming-language" rel="alternate" type="text/html" title="The wren programming language" /><published>2024-11-19T06:26:00+00:00</published><updated>2024-11-19T06:26:00+00:00</updated><id>https://kow.fm/the-wren-programming-language</id><content type="html" xml:base="https://kow.fm/the-wren-programming-language"><![CDATA[<p>Hi Friends.</p>

<p>A while ago I declared online that I really really hated Javascript. Lately, I still don’t like it, but my hate just doesn’t seem to go as deep. Then I declared that I would replace it with something better. In that pursuit I began working on my own language, named <a href="https://konascript.org">Kona</a>. Intended to be compiled to WASM, and shipped in your browser like a 200KB party favor.</p>

<p>Kona isn’t ready yet. In fact I’ve barely begun the compiler/interpreter/VM. The thing about writing a programming language is that you need to know how to do that. If you don’t know how to do that, well… then you can’t do it. So I decided to learn.</p>

<p>I began by reading the book <a href="https://craftinginterpreters.com">Crafting Interpreters</a>, which is absolutely excellent. But before I could finish I needed to go learn <strong>C</strong>, A language I had never written. Then I went and I learned <a href="https://lua.org">Lua</a>, Thinking I could write all of Kona, in Lua, and ship it as a single binary. I got pretty far there, and learned a lot. But then I stumbled upon <a href="https://wren.io">Wren</a>, a small, object oriented language written by Robert Nystrom the author behind crafting interpreters.</p>

<p>I was immediately intrigued. It’s a small, fast scripting language. comparable in speed to Lua, But with a heavily simplified object oriented syntax. Purpose built to be embedded in other applications, like Lua, but with a simpler API.</p>

<p>The best thing about this language, is how <em>EASY</em> it is to learn it’s internals. Volumes of comments and descriptions populate the source code, making it easy to poke around and understand how it all works. In my pursuit of writing Kona, it was never my intention of building the whole thing from scratch. I mean, I want to <em>Finish</em> the project after all. I was content to start by writing Kona’s interpreter in Lua, then learning C and porting it to that. Now I’m emboldened to write Kona’s compiler in C, and target Wren’s VM, initially, To execute the code.</p>

<p>Anyways, to actually ship the project I want the project to be much smaller than fully a new language. Targeting a VM with unique syntax seems like a good tradeoff. Although, as I go along, I know I’ll find myself making those changes, and writing my own unique VM.</p>

<h2 id="how-does-a-programming-language-work-anyway">How does a programming language work anyway?</h2>

<p>I should explain how we get a new language at all.</p>

<p>Computer processors each have their own dialect of instructions. x86, RISC-V, ARM, etc… Learning to write programs for each specific architecture is arduous. So some smart folks decided that they would write a program that would transform simpler instructions, into the specific instructions of a processor. A compiler.</p>

<p>Compilers have quite a few parts, but the top most part, called the front end, scans code in it’s particular syntax, and translates it into tokens. String, Number, Name, Operator. Then takes these tokens and translates them into the machine code of whatever computer your targeting. There are other concepts that are captured too, like scope, and upvalues, etc..</p>

<p>Scripting languages are a bit different. Instead of compiling the code to native machine code, scripting languages compile your code into an intermediate, but internally represented Byte Code. The scripting language then runs the byte code through it’s Virtual Machine or VM, and executes the program accordingly.</p>

<p>The journey to get from your code, to tokens, to byte code, and then finally to be executed, offers a host of benefits or disadvantages, depending on your choice of language. New languages are made every day, or existing ones are improved. All in the pursuit to make certain tasks easier.</p>

<p>Consider this code:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">class</span> <span class="nc">Person</span> <span class="p">{</span>
  <span class="nx">name</span> <span class="p">{</span> <span class="nx">_name</span> <span class="p">}</span>
  <span class="nx">construct</span> <span class="k">new</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="p">{</span> <span class="nx">_name</span> <span class="o">=</span> <span class="nx">name</span> <span class="p">}</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">jim</span> <span class="o">=</span> <span class="nx">Person</span><span class="p">.</span><span class="k">new</span><span class="p">(</span><span class="dl">"</span><span class="s2">Jimmy</span><span class="dl">"</span><span class="p">)</span>
<span class="c1">// &gt; jim</span>
<span class="nx">System</span><span class="p">.</span><span class="nf">print</span><span class="p">(</span><span class="nx">jim</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span>
<span class="c1">// &gt; Jimmy</span>
</code></pre></div></div>

<p>We have words, symbols, spaces, curly braces, all sorts of stuff. Along with a litany of rules and practices you’ll just need to learn about the language. All in the pursuit to make our lives a bit easier. These rules and how it influences the way you write your programs, the syntax, determines what’s easy, what’s possible, and what’s enjoyable. That is the sweet spot I’m trying to pursue.</p>

<h3 id="tokens">Tokens</h3>

<p>The parser takes source code and converts it to tokens. Consider this:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">thing</span> <span class="o">=</span> <span class="dl">"</span><span class="s2">whatever</span><span class="dl">"</span>
</code></pre></div></div>

<p>Which, when parsed, produces the following tokens:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>  VARIABLE] <span class="o">=&gt;</span> var 0..2
<span class="o">[</span>      NAME] <span class="o">=&gt;</span> thing 4..8
<span class="o">[</span>ASSIGNMENT] <span class="o">=&gt;</span> <span class="o">=</span> 10..10
<span class="o">[</span>    STRING] <span class="o">=&gt;</span> whatever 12..21
</code></pre></div></div>

<p>Now, Wren’s compiler is a one-pass compiler. That means these intermediate tokens are never really created, and Byte Code is emitted directly. Wren’s compiler has a single token look-ahead, look-behind, So it only really knows what’s immediately ahead and behind a token. This severely limits certain syntax possibilities, but in turn, it makes the parser very simple.</p>

<p>Consider this structure:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">class</span> <span class="nc">Nuts</span> <span class="p">{</span>
  <span class="nx">go</span> <span class="p">{</span> <span class="nx">_nuts</span> <span class="p">}</span>
  <span class="nx">go</span><span class="o">=</span><span class="p">(</span><span class="nx">v</span><span class="p">)</span> <span class="p">{</span> <span class="nx">_nuts</span> <span class="o">=</span> <span class="nx">v</span> <span class="p">}</span>
  <span class="nx">construct</span> <span class="k">new</span><span class="p">()</span> <span class="p">{}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>We define a class, using a keyword <strong>class</strong>, and add some setters, getters, and a constructor. In wren, the method signature is part of it’s name, and all properties, called fields, are private, so you need to add setters and getters.</p>

<p>Instead of marking the methods with <code class="language-plaintext highlighter-rouge">def</code> or <code class="language-plaintext highlighter-rouge">func</code> or something else, they are simply Naked <code class="language-plaintext highlighter-rouge">names</code> with blocks after them. <code class="language-plaintext highlighter-rouge">name + block</code> is a simple pattern for making a method. Now let’s call some methods:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">nutty</span> <span class="o">=</span> <span class="nx">Nuts</span><span class="p">.</span><span class="k">new</span><span class="p">()</span>
<span class="nx">nutty</span><span class="p">.</span><span class="nx">go</span>
<span class="c1">// &gt; null</span>
<span class="nx">nutty</span><span class="p">.</span><span class="nx">go</span> <span class="o">=</span> <span class="dl">"</span><span class="s2">Nuts!</span><span class="dl">"</span>
<span class="nx">nutty</span><span class="p">.</span><span class="nx">go</span>
<span class="c1">// &gt; Nuts!</span>
</code></pre></div></div>

<p>Here we show some more goodies. A var keyword to tell the compiler that nutty is a new variable. The compiler emits bytecode to create that space, and then later it’s assigned. Because the Wren compiler is a single pass, with only limited look ahead, we need to emit these tokens:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">[</span>   VARIABLE] <span class="o">=&gt;</span> var 0..2
<span class="o">[</span>       NAME] <span class="o">=&gt;</span> nutty 4..8
<span class="o">[</span> ASSIGNMENT] <span class="o">=&gt;</span> <span class="o">=</span> 10..10
<span class="o">[</span>      CLASS] <span class="o">=&gt;</span> Nuts 12..15
<span class="o">[</span>        DOT] <span class="o">=&gt;</span> <span class="nb">.</span> 16..16
<span class="o">[</span>       NAME] <span class="o">=&gt;</span> new 17..19
<span class="o">[</span> LEFT_PAREN] <span class="o">=&gt;</span> <span class="o">(</span> 20..20
<span class="o">[</span>RIGHT_PAERN] <span class="o">=&gt;</span> <span class="o">)</span> 21..21
</code></pre></div></div>

<p>Now whitespace is usually ignored, so we don’t add those, but we do want to know what each token is. You can tell from the first token and the second, that a <code class="language-plaintext highlighter-rouge">VARIABLE</code> declaration immediately followed by a <code class="language-plaintext highlighter-rouge">NAME</code>. This means that we want to set aside some storage. The bytecode to do that is then emitted. The next token is <code class="language-plaintext highlighter-rouge">ASSIGNMENT</code>, a binary operator. It takes the next <code class="language-plaintext highlighter-rouge">STATEMENT</code>, and assigns it to the name that came before. At this point we know that what comes next needs to be a valid statement, so the compiler begins interpreting the next tokens assuming this. If it runs into an unexpected situation, it can emit an error.</p>

<p>It may not seem immediately recognizable, but a single pass compiler means that certain features just aren’t feasible, or pretty difficult. Additionally, to keep the syntax simple, certain other features are not as easy. Consider free floating functions:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nf">myFunction</span><span class="p">()</span>
</code></pre></div></div>

<p>In an object oriented language like Wren, we have a name token, and an opening and closing paren token. The name is resolved at runtime, and the following tokens become part of the name to make an invocation. But what is it being invoked on? In Wren the parameter list, or at least it’s arity, are part of a methods signature, so a free floating function, as an object, would have to be implicitly called against <code class="language-plaintext highlighter-rouge">this</code>, like other naked methods are. But what is <em>this</em>? If you call <code class="language-plaintext highlighter-rouge">myFunction()</code> inside of a method in a class or outside in a free space what is the value of <code class="language-plaintext highlighter-rouge">this</code>? It’s different in each situation.</p>

<p>This is where the design of the language and it’s syntax begin to have consequences. What do we want to make easy in a language? And what are the consequences for making something easy.</p>

<p>Anyways. I really like Wren, and I’m excited to see where that language goes. It is a bit restricted from what I’d like to do. Classes can’t be reopened, method and function calling is explicit, which is nice, but restricts certain patterns. The compiler is single pass which means that complicated features like optional parens are not feasible.</p>

<h2 id="my-goal">My Goal</h2>

<p>Kona is intended for building UIs and interfaces on the web. A general purpose programming language, sure, but focused on a single platform. That focus means that syntax limitations, and in effect the design of the language, needs to be reconsidered at every step. i’m aiming for a multi-pass compiler to give some more complicated syntax features. Built in JSON, and HTML parsing. Built in HTML templates, Builders, class reopening, functions as first class citizens, and object tree diffing.</p>

<p>The target is the web, a Programming language VM as a WASM module that listens to and interacts with the webpage through the available APIs. We’ll see how far I get.</p>

<p>-kow</p>]]></content><author><name>Karl Oscar Weber</name></author><category term="blog" /><category term="programming-languages" /><category term="kona" /><category term="wren" /><summary type="html"><![CDATA[I talk all about the work I've been doing on the side writing my own programming language, and the language I discovered along the way: Wren.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://kow.fm/assets/blog/the-wren-programming-language/wren.svg" /><media:content medium="image" url="https://kow.fm/assets/blog/the-wren-programming-language/wren.svg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Fuck it</title><link href="https://kow.fm/fuck-it" rel="alternate" type="text/html" title="Fuck it" /><published>2024-11-06T06:26:00+00:00</published><updated>2024-11-06T06:26:00+00:00</updated><id>https://kow.fm/fuck-it</id><content type="html" xml:base="https://kow.fm/fuck-it"><![CDATA[<p>I’ve got more to lose than most when a guy comes into power that promises to deport my wife, my extended family, and most of my friends, and my kid’s friends’.</p>

<p>America has shifted to be more Fascist, Racist, and Misogynistic than I hoped. I was hoping for not that.</p>

<p>I’m not depressed. Or Sad. A little Angry maybe.</p>

<p>Being led by the mediocre is the price of Apathy.</p>

<p>Building a better world means fucking building it. Doing the work, whatever that is. And taking others along the way with you. That’s what I plan on doing.</p>

<p>-kow</p>]]></content><author><name>Karl Oscar Weber</name></author><category term="blog" /><summary type="html"><![CDATA[Karl gets serious]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://kow.fm/assets/blog/fuck-it/just-fuck-it.jpg" /><media:content medium="image" url="https://kow.fm/assets/blog/fuck-it/just-fuck-it.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Giving Up</title><link href="https://kow.fm/giving-up" rel="alternate" type="text/html" title="Giving Up" /><published>2024-10-05T06:26:00+00:00</published><updated>2024-10-05T06:26:00+00:00</updated><id>https://kow.fm/giving-up</id><content type="html" xml:base="https://kow.fm/giving-up"><![CDATA[<p>Hi Friends,</p>

<p>It’s me, Karl,</p>

<p>I’ve just been feeling incredibly depressed and burnt out lately. Some things happened at work that were not completely in my control, and some other things that were in my control and I just really failed. I think My EGO has been hit and beat up. I’m unmotivated every day. I’m not sleeping well. I’m barely getting my current work done. I have looming deadlines that are still far off, that I want to hit early, but now I feel like I’m gonna come in just before the wire. Just before they are due.</p>

<p>When I was younger in my career I would get really depressed when I couldn’t deliver something at work. I would feel like a complete failure, that at any moment I should be fired and just jettisoned. Hindsight has provided perspective, that I was too hard on myself. A good environment is a safe environment where we can learn and grow. Make mistakes and improve. Capitalism prompts a pressure to deliver. If we don’t, we could lose our jobs and shit can hit the fan.</p>

<p>I’ve lived with that pressure more than most, I think. At least far more than other folks I know in the industry. Which is a bummer. Constant fight or flight mode does not a healthy person make. I’ve talked before about the stresses of being laid off and trying to build a new business as fast as possible. It’s very hard, with lots of failure mixed in.</p>

<p>I don’t know. I’m just thinking: How do I get really stable and reliable again without fucking up? Without pushing myself to the breaking point? Folks are depending on me and I wanna deliver.</p>

<p>I haven’t even talked about my family and kiddos. I’ve sacrificed so much time and attention with them for my career to still end up at, like…. the bottom? I can’t just work way more to make things better and ignore them anymore.</p>

<p>Honestly this whole experience has made me want to have less responsibility, expenses, and worries. Just less of everything, but more time. More time to rest, be healthy, be with my family while they are still really little. If I’m really broke, but calm and dependable, that’s a good trade off for me.</p>

<p>I’m gonna do a lot less from now on, but just deliver. I think I need to slow down.</p>

<p>-kow</p>]]></content><author><name>Karl Oscar Weber</name></author><category term="blog" /><category term="programming-languages" /><category term="kona" /><category term="wren" /><summary type="html"><![CDATA[Karl talks about the intense burnout and failure he's been experiencing lately.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://kow.fm/assets/blog/giving-up/gingin_up.jpg" /><media:content medium="image" url="https://kow.fm/assets/blog/giving-up/gingin_up.jpg" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">New Blog</title><link href="https://kow.fm/new-blog" rel="alternate" type="text/html" title="New Blog" /><published>2024-07-03T06:26:00+00:00</published><updated>2024-07-03T06:26:00+00:00</updated><id>https://kow.fm/new-blog</id><content type="html" xml:base="https://kow.fm/new-blog"><![CDATA[<p>It was a long and dusty road to get to this point. I had a balance of 0.94 cents on the prepaid cash card attached to my digital ocean account. I had been racking up my balance doing some client work. The “Unsuccessful charge” emails had starting coming in daily. Inbox zero was a distant dream. And then… An email saying that everything was deleted. My entire account, wiped. bummer. Almost 10 years of blog posts gone. No backups.</p>

<p>What a relief.</p>

<p>Starting over new, and fresh, and shiny, seems like a lot of fun. Keeping things simple also seems like a lot of fun. My last website ran on Ghost, which is fine. It’s good. It’s Great. But there were drawbacks. Like the necessity to have a runtime to get it to… Run. Every attempt I had to make a dynamic experience that required a server with log ins, and a web editor, failed. It was a pile of unnecessary. There’s nothing dynamic here. I can write HTML and CSS myself I don’t need a server. I don’t need logins</p>

<p>I hope to have a server that needs all that again. Truly, But ever since going freelance again I’ve been making more websites in less time than I ever have. Piles and Piles of HTML and CSS. I’ve got these muscles loosey goosey. I’m Dialed in. Focusing on my craft.</p>

<h2 id="design-inspirations">Design inspirations</h2>

<p>I ripped off the feeling of this blog from A nike design book and the old Nasa style guide from the sixties. There’s something fresh and clean about a san serif typeface that looks a little too much like Helvetica. The typeface is <strong><em>General Sans</em></strong>, a favorite of mine. It’s clean, bold, and has a punch of personality. Most importantly it’s a bit weightier in the mid weights just like I like it. I’m not fond of a medium or regular font weight that feels too light. Give me meat on them bezier curves.</p>

<h2 id="development-credo">Development Credo</h2>

<p>I wanted to challenge myself a little, and also actually ship a project quickly, so I followed a few rules.</p>

<ul>
  <li>Very simple layout only.</li>
  <li>No fancy styles.</li>
  <li>Use the same base typography settings for everything.</li>
  <li>Images optional.</li>
</ul>

<p>I also decided to Use Jekyll. I gutted it, and dropped my stuff right on into the joint. Works great. Also works with RSS too. I actually wanted to use Camping, but it’s not ready yet. But that will change this summer. It’s been moving along at a steady pace, needs some database love, and a some deployment love, and it’s golden.</p>

<p>To fulfill these development requirements the design also had to be more streamlined and focused. I went with a two column layout, split down the middle. Everything is split on that axis. Narrow screen sizes are just stacked vertically. You know, the classics.</p>

<p>Repurposing typography decisions and only minimally making some changes. This means that Blog post previews, the little <em>cards</em>, only require a few styles to get it to behave like a card. The text just works inside because I did a good job. Only two Heading types are used to keep it simple too. h1, h2, that’s it. A couple of page headings get some love to adjust their top margins in certain contexts, like on the home page.</p>

<p>Instead of having special layouts for each page, I make a layout context using CSS Grid. Then setting that on a container by using a custom attribute:</p>

<figure class="highlight"><pre><code class="language-css" data-lang="css"><span class="nt">main</span><span class="o">[</span><span class="nt">layout</span><span class="o">=</span><span class="s1">"home"</span><span class="o">]</span> <span class="p">{</span>
  <span class="nl">display</span><span class="p">:</span><span class="n">grid</span><span class="p">;</span>
  <span class="py">grid-template-columns</span><span class="p">:</span><span class="m">1</span><span class="n">fr</span> <span class="m">1</span><span class="n">fr</span><span class="p">;</span>
  <span class="py">grid-template-rows</span><span class="p">:</span> <span class="nb">auto</span><span class="p">;</span>
  <span class="py">grid-template-areas</span><span class="p">:</span> <span class="s1">"left right"</span><span class="p">;</span>

  <span class="nl">column-gap</span><span class="p">:</span> <span class="n">var</span><span class="p">(</span><span class="n">--space-l</span><span class="p">);</span>
  <span class="py">row-gap</span><span class="p">:</span> <span class="m">0</span><span class="p">;</span>
<span class="p">}</span></code></pre></figure>

<figure class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt">&lt;main</span> <span class="na">layout=</span><span class="s">"home"</span> <span class="na">aria-label=</span><span class="s">"Content"</span><span class="nt">&gt;</span>
  {{ content }}
<span class="nt">&lt;/main&gt;</span></code></pre></figure>

<p>This makes a two column grid with equal width for both sides. I put it in a vertical column when things get too small:</p>

<figure class="highlight"><pre><code class="language-css" data-lang="css"><span class="k">@media</span> <span class="p">(</span><span class="n">max-width</span><span class="p">:</span> <span class="m">800px</span><span class="p">)</span> <span class="p">{</span>
  <span class="nt">main</span><span class="o">[</span><span class="nt">layout</span><span class="o">=</span><span class="s1">"home"</span><span class="o">]</span> <span class="p">{</span>
    <span class="py">grid-template-columns</span><span class="p">:</span><span class="m">1</span><span class="n">fr</span><span class="p">;</span>
    <span class="py">grid-template-areas</span><span class="p">:</span> <span class="s1">"left left"</span> <span class="s1">"right right"</span><span class="p">;</span>
    <span class="py">row-gap</span><span class="p">:</span> <span class="n">var</span><span class="p">(</span><span class="n">--space-l</span><span class="p">);</span>
  <span class="p">}</span>
<span class="p">}</span></code></pre></figure>

<p>I’ve tried to push things to be incredibly simple, with a little style on this build. I think I’ve achieved it. I hit all my goals. Looks nice, Shipped fast, Nothing broken.</p>

<p>All in all it turned out alright.</p>

<p>-kow</p>]]></content><author><name>Karl Oscar Weber</name></author><category term="blog" /><category term="update" /><summary type="html"><![CDATA[Check out the new digs! Karl's brand new blog is live and everybody loves it. After accidentally nuking my last website I've finally pulled together a new personal website. kow.fm version 25.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://kow.fm/assets/images/homepage/imagen.png" /><media:content medium="image" url="https://kow.fm/assets/images/homepage/imagen.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Welcome to Jekyll</title><link href="https://kow.fm/welcome-to-jekyll" rel="alternate" type="text/html" title="Welcome to Jekyll" /><published>2024-05-07T04:26:09+00:00</published><updated>2024-05-07T04:26:09+00:00</updated><id>https://kow.fm/welcome-to-jekyll</id><content type="html" xml:base="https://kow.fm/welcome-to-jekyll"><![CDATA[<p>You’ll find this post in your <code class="language-plaintext highlighter-rouge">_posts</code> directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run <code class="language-plaintext highlighter-rouge">jekyll serve</code>, which launches a web server and auto-regenerates your site when a file is updated.</p>

<p>Jekyll requires blog post files to be named according to the following format:</p>

<p><code class="language-plaintext highlighter-rouge">YEAR-MONTH-DAY-title.MARKUP</code></p>

<p>Where <code class="language-plaintext highlighter-rouge">YEAR</code> is a four-digit number, <code class="language-plaintext highlighter-rouge">MONTH</code> and <code class="language-plaintext highlighter-rouge">DAY</code> are both two-digit numbers, and <code class="language-plaintext highlighter-rouge">MARKUP</code> is the file extension representing the format used in the file. After that, include the necessary front matter. Take a look at the source for this post to get an idea about how it works.</p>

<p>Jekyll also offers powerful support for code snippets:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">print_hi</span><span class="p">(</span><span class="nb">name</span><span class="p">)</span>
  <span class="nb">puts</span> <span class="s2">"Hi, </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">"</span>
<span class="k">end</span>
<span class="n">print_hi</span><span class="p">(</span><span class="s1">'Tom'</span><span class="p">)</span>
<span class="c1">#=&gt; prints 'Hi, Tom' to STDOUT.</span>
</code></pre></div></div>

<p>Check out the <a href="https://jekyllrb.com/docs/home">Jekyll docs</a> for more info on how to get the most out of Jekyll. File all bugs/feature requests at <a href="https://github.com/jekyll/jekyll">Jekyll’s GitHub repo</a>. If you have questions, you can ask them on <a href="https://talk.jekyllrb.com/">Jekyll Talk</a>.</p>]]></content><author><name></name></author><category term="blog" /><category term="update" /><summary type="html"><![CDATA[Yes that's right, Capsule is getting bigger, better, stronger! A new drug is in stock. Meet one of my favorite people.]]></summary></entry></feed>