<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en_US"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://mattsheehan.dev/feed.xml" rel="self" type="application/atom+xml" /><link href="https://mattsheehan.dev/" rel="alternate" type="text/html" hreflang="en_US" /><updated>2026-11-30T22:40:21-05:00</updated><id>https://mattsheehan.dev/feed.xml</id><title type="html">Matthew Sheehan</title><subtitle></subtitle><author><name>Matt Sheehan</name></author><entry><title type="html">Lidless and Paneless</title><link href="https://mattsheehan.dev/archives/Lidless-and-Paneless/" rel="alternate" type="text/html" title="Lidless and Paneless" /><published>2026-11-30T12:00:00-05:00</published><updated>2026-11-30T12:00:00-05:00</updated><id>https://mattsheehan.dev/archives/Lidless-and-Paneless</id><content type="html" xml:base="https://mattsheehan.dev/archives/Lidless-and-Paneless/"><![CDATA[<p>I built two menu bar apps for two things I was tired of working around. The screenshot tool I used had stopped getting updates. The Mac went to sleep every time I closed the lid. A few years ago I would have lived with both. A small personal app was more project than it was worth. It isn’t anymore. I can sit down with a coding agent, finish the tool I actually want, and keep it.</p>

<p>Paneless replaced the screenshot tool. It still opened. The part I relied on was stuck with the last release: drag a region, mark it up, copy it into whatever I was writing. Shift-Command-9 does that now. A region, a window, or the whole screen. Pen, arrow, box, highlighter, text, emoji. Return copies it.</p>

<p>I freeze the screen before drawing. Each display gets covered with the picture I just took, and the marks go on the picture. On the live desktop the window can slide out from under the arrow, and a click can land in the app behind it. The fiddly part is making that click hit the right window. The frames and the pixels come from different places, and they count y in opposite directions. Quartz starts at the top left of the main display and goes down. The overlay is an ordinary Cocoa view and goes up. Skip the conversion and the highlight misses, sometimes by a whole second monitor. The image is captured at the screen’s full resolution, and I tag it with the size I dragged so a Retina shot pastes at that size.</p>

<p>Screen Recording permission is tied to the app’s signature. I learned that by granting it after every rebuild. An ad-hoc signature changes each build, so macOS treated every one as a new app. Local builds are signed with one self-signed certificate, Paneless Local Signing, and I only had to allow it once. The hotkey goes through Carbon, so it never also asked for Accessibility. The zip on the releases page is still ad-hoc signed. There’s no Developer ID certificate behind it, so an update can bring the prompt back.</p>

<p>Lidless is the sleep problem. I wanted the Mac awake while I still needed it, and asleep when I was finished. Closing the lid always won. <code>caffeinate</code> covers the easy half, a power assertion for as long as the command is running, and I wanted that in the menu bar with a duration I could see. Pick a time, or leave it on. The icon fills in while a session is running. There’s a preference that lets the display sleep while the computer stays up.</p>

<p>The lid ignores that assertion. The setting that stops lid-close sleep is <code>pmset disablesleep</code>. It needs an administrator, and it turns sleep off for the whole machine, Apple menu included. Forget to turn it back off and sleep stays off. I didn’t want a utility that could leave my laptop like that, so most of the app is the cleanup. The first time I enable it, Lidless asks for my password once and installs <code>/etc/sudoers.d/lidless</code>, after <code>visudo</code> checks the file. The rule allows two commands:</p>

<figure class="highlight"><pre><code class="language-shell" data-lang="shell">/usr/bin/pmset <span class="nt">-a</span> disablesleep 1
/usr/bin/pmset <span class="nt">-a</span> disablesleep 0</code></pre></figure>

<p>The switch is on only during a session. The timer ends, or I choose Turn Off, or I quit, and sleep comes back. A force-quit can’t run that cleanup, so the app writes down that it disabled sleep and restores it the next time it opens. If I had already disabled sleep myself, it leaves that alone. On battery a lid-closed session stops at 10 percent. A closed laptop has nowhere to put the heat.</p>

<p><a href="https://mattsheehandev.github.io/paneless/">Paneless</a> has a demo of the markup in the browser, and the <a href="https://github.com/MattSheehanDev/paneless">source</a>. <a href="https://mattsheehandev.github.io/lidless/">Lidless</a> and its <a href="https://github.com/MattSheehanDev/lidless">source</a>.</p>]]></content><author><name>Matt Sheehan</name></author><summary type="html"><![CDATA[I built two menu bar apps for two things I was tired of working around. The screenshot tool I used had stopped getting updates. The Mac went to sleep every time I closed the lid. A few years ago I would have lived with both. A small personal app was more project than it was worth. It isn’t anymore. I can sit down with a coding agent, finish the tool I actually want, and keep it.]]></summary></entry><entry><title type="html">(Almost) Everything I Know About Choosing Colors</title><link href="https://mattsheehan.dev/archives/Everything-I-Know-About-Choosing-Colors/" rel="alternate" type="text/html" title="(Almost) Everything I Know About Choosing Colors" /><published>2016-04-06T00:00:00-04:00</published><updated>2016-04-06T00:00:00-04:00</updated><id>https://mattsheehan.dev/archives/Everything-I-Know-About-Choosing-Colors</id><content type="html" xml:base="https://mattsheehan.dev/archives/Everything-I-Know-About-Choosing-Colors/"><![CDATA[<p><em><strong>Disclaimer</strong>: It’s not a lot.</em></p>

<p>The reason I’m not writing everything I know about choosing colors, is because I only spend about 2 minutes proofreading, so the shorter an essay is, the more errors I can catch. I’m sure though, that if I would have written everything and was born with more patience, I could have gone on for at least another paragraph or two. :)</p>

<p><strong>Use HSL (Hue, Saturation, Light) Color Represenations</strong></p>

<p>A lot of times you’ll see hex representations of colors like #F938AD, using the hexadecimal numbers 0-F or RGB representations like rgb(212,50,185) using the decimal numbers 0-256, but what do those even mean? Sure RGB is the amount of red, green, and blue in a color, but unless you’re a computer pixel or a superb color theorist who mixed a lot of watercolors when she was four years old, the blue-y-ness or the red-y-ness of a color doesn’t mean much to me. Unless your meaning is purple, I understand how purple works. But there are still lots of other colors, precisely, using three decimal values between 0 and 256, there are 256^3 colors, or using six hexadecimal values between 0-F (0-16), there are 16^6 colors, which both reduce to 16,777,216 color representations. So my point stands that red-y-ness, to a middle school art dropout, doesn’t mean much.</p>

<p>But what about this HSL representation? Turns out HSL is much closer to how humans like me think. HSL means that I can set the approximate hue of the color I want, and then play with the saturation and the light (which from now on we’re going to call brightness) and I still have a variation of the same color that I started with. Try doing something like that with RGB. You can’t. Add too much red-y-ness to a color and you no longer have the same color anymore, it’s like mixing paint, I’m going to end up with poop brown. Want to change the brightness of that green color you have? Go ahead! You’ll just end up with a brighter green. How about the saturation? No problem! You’ll just have a more saturated green. There is no direct path to poop brown, unless you set the hue to a brown.</p>

<p><strong>Never Use Pure Black</strong></p>

<p>Have you been noticing how blue Facebook is, because you should be. Even look look at the background grey color, it’s not grey, it’s blue-grey. In fact, its this color `hsl(225, 10%, 92%). Which if we look at a color wheel, means that, if we start at the top and go 225 degrees around, we’ll land on the blue square, then we take that rocking blue we found and set it to 10% of complete saturation, followed by 92% of total brightness. As a note you can take any color, crank up the brightness to 100%, and you’ll end up with white. Turn down the brightness to 0%, and you’ll end up with black, regardless of hue or saturation, that’s just how light works.
So next time instead of using a rocking blue and then proceeding to use rgb(180,180,180) as the dullest grey. Take the rocking blue, tone done the saturation, crank up the brightness and there’s you’re blue grey.</p>

<p class="soliloquy">There are probably dozens of well paid designers at Facebook that put a lot of thought and attention to their color choices, but you’d never be able to tell, which I think is testament to their worth, since their choices are simple and not flashy.</p>

<p><strong>Keep Your Color Scheme To Two Colors</strong></p>

<p>Really just a guideline, but you should only ever need one primary color and a splash of some complementary color. Now these two colors are not including your greys, or variations on you primary color. How do you pick your complementary color? I don’t know how you pick your complementary color, I pick it by going to <a href="paletton.com">paletton</a>, choosing my primary color and clicking the add complementary button. I know that there is some reason about how two colors complement each other that could enable me to choose with my brain, but I also know that there’s a service that does this for me.</p>]]></content><author><name>Matt Sheehan</name></author><summary type="html"><![CDATA[Disclaimer: It’s not a lot.]]></summary></entry><entry><title type="html">Design pt. 1</title><link href="https://mattsheehan.dev/archives/Design-Part-1/" rel="alternate" type="text/html" title="Design pt. 1" /><published>2015-12-23T00:00:00-05:00</published><updated>2015-12-23T00:00:00-05:00</updated><id>https://mattsheehan.dev/archives/Design-Part-1</id><content type="html" xml:base="https://mattsheehan.dev/archives/Design-Part-1/"><![CDATA[<p><strong>TL;DR</strong>: start from the beginning, then, start from the beginning again.</p>

<p>After hours of thinking about design, I made my mind up that design has to be <strong>holistic</strong>. If I was designing a system with some 5 features, I should start from the beginning and incorporate how each one of those features fits into and interacts with the program, then if another feature was added I should start from the beginning again because now each piece of the system has 5 other interactions instead of 6. And although it’s common to just hammer the 6th feature in there, that’s impossible to do without compromising the entire integrity of the program and leaving the feeling that the entire program isn’t as solid as it should be (even though only a few people would be able to put their finger on exactly what was wrong with it).</p>

<p>One of the most difficult aspects of any design is the giving the final impression that the entire system was created by the hand of one person. Very rarely does one person get the chance (if they even have the desire, or the ability) for end to end control, from the initial feature requests, to the first draft of the design, to the final implementation. It wouldn’t be unusual for a few people to pull the feature requests together, then have a few people architect the design, and then leave the implementation of the program to any number of people who had no hand in what the design should be or if a feature is even worth implementing.</p>

<p>The end result becomes a compromised program. Too many people had an input and the design wasn’t done <strong>holistically</strong>. Everything feels disjointed. I think this is the biggest hurdle for most projects and I’m not sure if there is one cure all. Each new project needs to be designed from the beginning (and be wary of letting a program grow <em>organically</em>, love should grow organically, systems should be by design), and when the requirements change and now there are 6 features instead of 5, don’t be afraid to design <strong>from the beginning</strong>.</p>]]></content><author><name>Matt Sheehan</name></author><summary type="html"><![CDATA[TL;DR: start from the beginning, then, start from the beginning again.]]></summary></entry><entry><title type="html">Ruby is Object-Oriented Lisp</title><link href="https://mattsheehan.dev/archives/ruby-is-oo-lisp/" rel="alternate" type="text/html" title="Ruby is Object-Oriented Lisp" /><published>2015-09-22T00:00:00-04:00</published><updated>2015-09-22T00:00:00-04:00</updated><id>https://mattsheehan.dev/archives/ruby-is-oo-lisp</id><content type="html" xml:base="https://mattsheehan.dev/archives/ruby-is-oo-lisp/"><![CDATA[<p>I’ve fooled around and hankey-pankeyed with lisps for years. I’ve even wrote a toy <a href="https://github.com/sheehamj13/mslisp">lisp dialect</a>. I’ve also gotten dirty with Ruby. This site itself is build using Jekyll<sup id="fnref:1"><a href="#fn:1" class="footnote" rel="footnote" role="doc-noteref">1</a></sup>, a static site generator written with Ruby, and I’ve wrote a few custom plugins to help my development along.</p>

<p>But I had a shower thought after using the two. Ruby is really just an object-oriented (OO) dialect of lisp<sup id="fnref:2"><a href="#fn:2" class="footnote" rel="footnote" role="doc-noteref">2</a></sup>. Sure there are libraries that add OO design principles to lisp, but Ruby takes all of the best parts of lisp and bakes OO constructs directly into it.</p>

<p class="soliloquy">I would lump Ruby, lisp, and Javascript into one language family. They’re the languages I consider the <em>fun</em> programming languages. Sure they’re not taken seriously by any of the ‘real’ developers, but how many times do you get to use the word ‘fun’ and programming in the same sentence. You might here ‘oh, that’s interesting’ or ‘very clever’<sup id="fnref:3"><a href="#fn:3" class="footnote" rel="footnote" role="doc-noteref">3</a></sup> said by the real devs, but rarely ‘this is fun’, and I think that deserves remark.</p>

<p class="primtitle">The value of everything</p>

<p>Both Ruby and most lisp dialects attribute a value to everything (even if that value is NIL, a keyword that is shared). Undefined does not exist and something never goes uninitialized with some randomness.</p>

<p class="primtitle">The truth of everything</p>

<p>Everything is true, except NIL and FALSE. In boolean conversions, “x” is true, “nil” is true, and NIL is false. If you ever find yourself asking, ‘is 0 equivalent to true or false?’, the answer is ‘is 0 the equivalent of NIL or FALSE? No.’, so theres your answer. This makes using boolean logic less painful, you never have to type <strong>if x == nil</strong> or any equivalent.</p>

<p><strong>if x <em>body</em></strong> or the lispy <strong>(if x <em>body</em>)</strong> is good enough.</p>

<p class="primtitle">Operators are functions</p>

<p>Ok, alright already. Operators are basically always functions in every language. But I promise it’s different here, they really feel like functions. In lisp you have <strong>(+ 2 2)</strong>, which at any point you can <strong>(set! + (lambda (x y) (- x y)))</strong>, and now addition is subtraction. Since Ruby is just an OO dialect of lisp, this function-ness goes a step further, <strong>2.+(2)</strong>, is the equivalent of 2 + 2, except in the former the +-operator appears as a method on the <em>Integer Class</em><sup id="fnref:4"><a href="#fn:4" class="footnote" rel="footnote" role="doc-noteref">4</a></sup>.</p>

<p class="soliloquy">Everybody should still write 2 + 2 for clarity, but the fact that you can write it alternatively relays my point across.</p>

<p class="primtitle">Everything is a Function-Object</p>

<p>In lisp everything is a function since there is no OO classes and in Ruby, everything is technically an object, but can be thought of as a function (in the same way as Javascript). Just like in lisp where in the line of code <strong>(defun <em>name</em> <em>body</em>)</strong>, which defines a new function, <strong>defun</strong> is really just another function that takes a <em>name</em> parameter and a <em>body</em> parameter. The same can be said of Ruby. In the line of code <strong>def <em>name</em> <em>body block</em></strong>, which defines a new class method, <strong>def</strong> is really just a function that takes two parameters.</p>

<p class="soliloquy">In ruby this also extends to the class access modifiers (public, private, and protected). In the line <strong>private def <em>method name</em> <em>body block</em></strong>, <strong>private</strong> is just a function that takes the return of the function <strong>def</strong>.</p>

<p class="primtitle">Conventions</p>

<p>And finally the naming conventions, which Ruby has taken from lisp. Functions with question marks at the end usually answer boolean questions about something, while functions with exclamation marks the end usually denote that the function modifies its input.</p>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1">
      <p>Btw, Jekyll v3.0 is leaps and bounds better than v2.x. Unfortunately, v3.0 is still in beta. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:2">
      <p>I know Ruby looks a lot like Python, I too thought they would be about the same, because of the similar importance attributed to vertical white-space and their bracketless syntax. But those are just syntactical details, and the similarities between the <em>design</em> of the language ends there. <a href="#fnref:2" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:3">
      <p>Other things developers might say are ‘Neat!’, ‘Cool!’, and ‘Awesome!’, as well as any conjugations such as ‘Neato!’ and ‘Coolio!’. <a href="#fnref:3" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:4">
      <p>Yeah. Even numbers are objects. <a href="#fnref:4" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Matt Sheehan</name></author><summary type="html"><![CDATA[I’ve fooled around and hankey-pankeyed with lisps for years. I’ve even wrote a toy lisp dialect. I’ve also gotten dirty with Ruby. This site itself is build using Jekyll1, a static site generator written with Ruby, and I’ve wrote a few custom plugins to help my development along. Btw, Jekyll v3.0 is leaps and bounds better than v2.x. Unfortunately, v3.0 is still in beta. &#8617;]]></summary></entry><entry><title type="html">The Economics of Information Technology</title><link href="https://mattsheehan.dev/archives/Startup-Economics/" rel="alternate" type="text/html" title="The Economics of Information Technology" /><published>2015-09-15T00:00:00-04:00</published><updated>2015-09-15T00:00:00-04:00</updated><id>https://mattsheehan.dev/archives/Startup-Economics</id><content type="html" xml:base="https://mattsheehan.dev/archives/Startup-Economics/"><![CDATA[<p class="primtitle">The Law of Supply</p>

<p class="subtitle">Definition</p>

<p>As price increases, the quantity supplied increases. As price decreases, the quantity supplied decreases.</p>

<p class="subtitle">Example</p>

<p>We see the this (the law of supply) in the mobile phone industry today. When Apple first entered the market with, what was then, an expensive phone and had success with large margins for profit, other suppliers began entering the market. Until we got to the point where we are now, with a glut of phone suppliers and a lot of phones selling with thin margins and little profits trying to compete on price.</p>

<p class="subtitle">Prediction</p>

<p>I think we’re going to see a lot of phone suppliers leave the market as the price and profit margin of phones get driven lower. This isn’t a radical prediction as we’re already seeing the beginnings of this and it logically follows from the law of supply that as price decreases the supply will decrease.</p>

<p>Market saturation, in the U.S as least, has been reached, but <em>Market equilibrium</em> hasn’t. There are more phones being supplied (at a given price) than being demanded. Market equilibrium has not been reached in developing countries either, but for the opposite reasons.</p>

<p class="subtitle">Outlier</p>

<p>Apple remains one of the only phone suppliers that has retained it’s pricing and is actually increasing sales as demand is driven higher as most other phones are seen as inferior goods.</p>

<p class="primtitle">Normal goods/Inferior goods</p>

<p class="subtitle">Definition</p>

<p>A normal good is any good in which demand increases and decreases with income. As income increases, demand for normal goods increases. As income decreases demand for normal goods decreases. An inferior good is any good in which demand decreases as income increases and increases as income decreases.</p>

<p class="subtitle">Example</p>

<p>Piggybacking on our last example, in the phone market, Apple and Samsung are the two normal goods suppliers (maybe even Apple being considered ‘more normal’), with most other phone supplies seen as inferior goods. As income increases $700, usually spread over $30 a month, doesn’t seem too intimidating, and a lot of people will trade up from their $99 phone. But as income decreases, more people will settle for their $99 phones and a cheaper monthly bill, rather than spend $100 a month (monthly payment + data plan + talk/text plan) to have the iPhone 6s Plus.</p>

<p class="subtitle">Prediction</p>

<p>No change, Apple will remain to be seen as a ‘normal’ good, while everyone else races to cater to those who can only afford ‘inferior’ goods.</p>

<p class="primtitle">Elasticity</p>

<p class="subtitle">Definition</p>

<p>Elasticity is how much demand is influenced by price. A product (or service) is said to be elastic if a given percentage change in price leads to a large percentage change in demand. Another way to put this is that demand is highly influenced by price. A product is said to be inelastic if a given percentage change in price leads to a small percentage change in demand. Another way to put this is that demand is not influenced by price very much.</p>

<p class="subtitle">Formula</p>

<p>% change in quantity demanded / % change in price</p>

<p class="subtitle">Remarks</p>

<p>It’s important to note that elasticity is the <em>percent</em> changed. So if you price your product at $2.00 and have a demand of 30 units and then increase the price to $4.00 and have a demand of 20 units, you will have a higher elasticity because you increased price by 50% but demand only dropped by 33%.</p>

<p>You might also notice that total revenue can be increased by increasing the price to $4.00 ($4.00 * 20 &gt; $2.00 * 30). Which means that it would make financial sense to set the price at $4.00.</p>

<p class="subtitle">Relevance?</p>

<p>How is this relevant to what is happening in our industry? Well instead of companies setting prices at $4.00 to increase total revenue, prices are being kept low (at say the hypothetical $2.00) sacrificing total revenue, so that the user base and market share can grow faster.</p>

<p class="subtitle">Consequences</p>

<p>The most insane part is that investors actually like this model. Especially with startups where most profit that investors see will not come from the revenue of the company, but from the acquistion of the company by a larger company or after the startup’s IPO.</p>

<p>This <em>hope</em> for future returns is flawed in its fundamental premise, that users are loyal to one brand and the cost of switching brands is higher than the cost of staying.</p>

<p>Users will also become accustomed to the lower prices and as soon as prices increase, demand will increase for substitute goods by competitors and most of their market share will be wiped as quickly as it was created.</p>

<p class="soliloquy">Here’s an idea. Look for companies that don’t take or need a lot of outside money and grow their revenue alongside their quantity demanded until market equilibrium has been reached.
<br />
Instead of the current unsustainable model where market surplus is reached, the company is sold or goes public, everyone cashes in, and the company implodes as the market contracts, rapidly shrinking the companies overgrowth.</p>]]></content><author><name>Matt Sheehan</name></author><summary type="html"><![CDATA[The Law of Supply]]></summary></entry><entry><title type="html">Processing and parabola’s</title><link href="https://mattsheehan.dev/archives/processing/" rel="alternate" type="text/html" title="Processing and parabola’s" /><published>2015-08-30T00:00:00-04:00</published><updated>2015-08-30T00:00:00-04:00</updated><id>https://mattsheehan.dev/archives/processing</id><content type="html" xml:base="https://mattsheehan.dev/archives/processing/"><![CDATA[<p>This weekend I was playing with <a href="https://processing.org/">processing</a> after coming working through the first lesson of <a href="https://www.khanacademy.org/partner-content/pixar">Pixar in a Box</a> on <a href="https://khanacademy.org">Khan Academy</a>.</p>

<p>There’s also this super neat javascript library that renders your processing scripts on an html canvas element called <a href="http://processingjs.org/">processing.js</a>. Which makes processing not only a fun tool for your computer, but lets you make fun projects for the web as well<sup id="fnref:1"><a href="#fn:1" class="footnote" rel="footnote" role="doc-noteref">1</a></sup>.</p>

<p>To summarize, Pixar in a Box begins with environment modeling. Rendering a blade of grass is given as an example and is described in terms of a parabola, or more specifically a parabolic arc. The first part is an intro with examples, and for those that want to venture further, can venture into the second part which explains the algebra.</p>

<p>I decided it’d be fun and more concrete to implement what I learned myself, so I dug up processing again and had fun making this! I’d check out khan academy if you wanted to know more, since it would be explained better there than I could explain myself.</p>

<p>If you want to view the demo (below), make sure you navigate to the full post page by clicking the title above (if you haven’t already).</p>

<canvas width="640" height="360" data-processing-sources="/projects/parabolic_arc/parabolic_arc.pde /projects/parabolic_arc/parabolic_controls.pde">
</canvas>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1">
      <p>It’s much easier working with processing than any specific javascript library for rendering to a canvas. I guess that’s <a href="https://en.wikipedia.org/wiki/The_Pros_and_Cons_of_Hitch_Hiking">the pro’s and con’s of working with a domain specific language</a>. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Matt Sheehan</name></author><summary type="html"><![CDATA[This weekend I was playing with processing after coming working through the first lesson of Pixar in a Box on Khan Academy.]]></summary></entry><entry><title type="html">(LOAD ‘MSLisp)</title><link href="https://mattsheehan.dev/archives/MsLisp/" rel="alternate" type="text/html" title="(LOAD ‘MSLisp)" /><published>2015-06-29T00:00:00-04:00</published><updated>2015-06-29T00:00:00-04:00</updated><id>https://mattsheehan.dev/archives/MsLisp</id><content type="html" xml:base="https://mattsheehan.dev/archives/MsLisp/"><![CDATA[<p>I’ve been working fervently the past <strong>15 days</strong><sup id="fnref:1"><a href="#fn:1" class="footnote" rel="footnote" role="doc-noteref">1</a></sup> on my first language and interpreter, a dialect of lisp I’ve come to refer to as <em>MsLisp</em>. I had a few goals starting, some of which are still in progress.</p>

<h6 id="what-i-wanted">What I wanted</h6>

<ul>
  <li>I wanted an embeddable lisp that could run on tiny specialized hardware.</li>
  <li>A minimal interpreter with most implementation written in lisp itself (for portability).</li>
  <li>Written in portable C++.</li>
</ul>

<h6 id="what-i-have">What I have</h6>

<ul>
  <li>A working dialect of lisp with a minimal interpreter.</li>
  <li>A small standard library with basic functionality.</li>
  <li>Written in C#.</li>
</ul>

<p>I plan on reading up some more on some lisp functionality and fixing up some design changes before porting the code to C++ or start working on any other versions of it. Most of MsLisp is inspired by <a href="http://www.gnu.org/software/mit-scheme/">Scheme</a> with some of parts stolen from the <a href="http://www.clisp.org/">CLisp</a> implementation of Common Lisp. I’ve started working through <a href="https://mitpress.mit.edu/index.php?q=books/little-schemer"><em>The Little Schemer</em></a> for some less dry insights into Scheme.</p>

<h6 id="features">Features<sup id="fnref:2"><a href="#fn:2" class="footnote" rel="footnote" role="doc-noteref">2</a></sup></h6>

<p><strong>First Class Macros.</strong></p>

<p>Lisp macros are unlike macros in other languages. I can best describe macros as functions that return code as data (which I understand still isn’t clear).</p>

<p>In order to really understand macros (and the implications of macros, without which you don’t really actually understand macros), you need to understand how lisp code is interpreted. The process can be broken down into three parts.</p>

<ol>
  <li><strong>Parsing</strong>. Which can be broken down into two sub-steps,
    <ol>
      <li>Lexing (tokenizing).</li>
      <li>Parsing the tokens into lisp values (numbers, strings, expressions, symbols…).</li>
    </ol>
  </li>
  <li><strong>Expanding</strong>. This is the step where macros are evaluated and <em>expand</em> into the code they return.</li>
  <li><strong>Evaluating</strong>. This is your normal evaluation step where function and variable execution and manipulation happen.</li>
</ol>

<p>Let me give some code examples.</p>

<figure class="highlight"><pre><code class="language-common-lisp" data-lang="common-lisp"><span class="p">(</span><span class="nv">define</span> <span class="nv">pair</span>
  <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">x</span> <span class="nv">y</span><span class="p">)</span>
    <span class="p">(</span><span class="nb">cons</span> <span class="nv">x</span> <span class="p">(</span><span class="nb">cons</span> <span class="nv">y</span> <span class="o">'</span><span class="p">()))))</span></code></pre></figure>

<p>That’s a completely valid function in lisp that takes two arguments and adds them into an empty list, which is then returned.</p>

<p class="soliloquy">Protip: Whatever statement is last <em>evaluated</em> is what is returned. Every function at least returns <code>NIL</code>.</p>

<p>Now lets define a macro.</p>

<figure class="highlight"><pre><code class="language-common-lisp" data-lang="common-lisp"><span class="p">(</span><span class="nv">define</span> <span class="k">let</span>
  <span class="p">(</span><span class="nv">macro</span>
    <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">var-value</span> <span class="nv">body</span><span class="p">)</span>
      <span class="o">`</span><span class="p">((</span><span class="k">lambda</span> <span class="p">(</span><span class="o">,</span><span class="p">(</span><span class="nb">car</span> <span class="nv">var-value</span><span class="p">))</span>
         <span class="o">,</span><span class="nv">body</span><span class="p">)</span> <span class="o">,</span><span class="p">(</span><span class="nb">cadr</span> <span class="nv">var-value</span><span class="p">)))))</span></code></pre></figure>

<p>Wait a second. That looks a lot like a function. Yep, macros are alot like functions, except for when they are evaluated.</p>

<p class="soliloquy">Protip: Noticed in the first example how the lambda function was just set to the variable pair? That makes it a <code>First class function</code>, which can be passed to other functions just like any other variable. In MsLisp, macros just wrap a lambda function (see the <code>macro</code> keyword before the <code>lambda</code> keyword?) to let the interpreter know that this particular function is special. Therefore, macros are <code>First class macros</code> and can be passed to other functions just like their function counterparts. Most lisp macro implementations are not implemented this way, although I find understanding and mostly implementing macros in the interpreter easier this way compared to the standard implemenations.</p>

<p>Now we can implement a macro to make it less verbose to write normal lambda functions</p>

<figure class="highlight"><pre><code class="language-common-lisp" data-lang="common-lisp"><span class="p">(</span><span class="nv">define</span> <span class="nb">defun</span>
  <span class="p">(</span><span class="nv">macro</span>
    <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">name</span> <span class="nv">params</span> <span class="nv">body</span><span class="p">)</span>
      <span class="o">`</span><span class="p">(</span><span class="nv">define</span> <span class="o">,</span><span class="nv">name</span>
         <span class="p">(</span><span class="k">lambda</span> <span class="o">,</span><span class="nv">params</span>
            <span class="o">,</span><span class="nv">body</span><span class="p">)))))</span>

<span class="p">(</span><span class="nb">defun</span> <span class="nv">pair</span> <span class="p">(</span><span class="nv">x</span> <span class="nv">y</span><span class="p">)</span>
  <span class="p">(</span><span class="nb">cons</span> <span class="nv">x</span> <span class="p">(</span><span class="nb">cons</span> <span class="nv">y</span> <span class="o">'</span><span class="p">())))</span></code></pre></figure>

<p>See what we did there? We wrote the macro <code>defun</code> which we use to rewrite our pair function with. When the interpreter see’s this, it’ll replace (defun pair …) with all the code returned from the <code>defun</code> macro. After expansion, both pair functions, old and new, result in the same code. Pretty cool huh?!</p>

<p>The implication of macros really clicked for me when write the <code>+</code> macro. MsLisp has a builtin function called <code>add</code>, which adds exactly two arguments. Not one, not three, but exactly two like so <code>(add 1 2)</code>. But what if we wanted to do this <code>(add 1 2 3 4)</code>? Well we can! But we’ll have to write a macro.</p>

<p>Note: I’ve gone ahead and replaced <code>define **name** (macro (lambda (args)))</code> with <code>(defmacro **name** (args))</code>.</p>

<figure class="highlight"><pre><code class="language-common-lisp" data-lang="common-lisp"><span class="p">(</span><span class="nb">defmacro</span> <span class="nb">+</span> <span class="p">(</span><span class="k">&amp;rest</span> <span class="nv">x</span><span class="p">)</span>
  <span class="p">((</span><span class="nv">Y</span>
    <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">f</span><span class="p">)</span>
      <span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="nv">x</span><span class="p">)</span>
        <span class="p">(</span><span class="k">if</span> <span class="p">(</span><span class="nb">=</span> <span class="p">(</span><span class="nb">length</span> <span class="nv">x</span><span class="p">)</span> <span class="mi">1</span><span class="p">)</span>
           <span class="p">(</span><span class="nb">car</span> <span class="nv">x</span><span class="p">)</span>
           <span class="p">(</span><span class="nv">f</span> <span class="p">(</span><span class="nb">cons</span> <span class="o">`</span><span class="p">(</span><span class="nv">add</span> <span class="o">,@</span><span class="p">(</span><span class="nv">first-pair</span> <span class="nv">x</span><span class="p">))</span> <span class="p">(</span><span class="nb">cddr</span> <span class="nv">x</span><span class="p">)))))))</span>
   <span class="nv">x</span><span class="p">))</span></code></pre></figure>

<p>There are a few functions we haven’t defined yet in that function such as <code>Y</code>, the recursive y-combinator, <code>first-pair</code>, which returns the first two elements of a list, and <code>cddr</code>, which skips the first two elements of a list and returns the remainder.</p>

<p>Our new <code>+</code> macro expands <code>(+ 1 2 3 4)</code> into <code>(add (add (add 1 2) 3) 4)</code>.</p>

<p><strong>C# Reflection in lisp.</strong></p>

<p>This isn’t so much of a feature that I wanted, but just something that I though was neat and gives MsLisp a lot more functionality. Since C# can reflect on itself and know what methods it has, when can dynamically invoke these methods and create new instances of objects by calling methods like the following.</p>

<figure class="highlight"><pre><code class="language-common-lisp" data-lang="common-lisp"><span class="p">(</span><span class="nv">new</span> <span class="s">"Mslisp.Lexical.Parser"</span> <span class="vg">*args-if-we-need-any*</span><span class="p">)</span>

<span class="p">(</span><span class="nv">invoke-static</span> <span class="p">(</span><span class="nv">get-type</span> <span class="s">"System"</span> <span class="s">"Console"</span><span class="p">)</span> <span class="s">"Write"</span> <span class="s">"string arg to print to console"</span><span class="p">)</span></code></pre></figure>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1">
      <p>Actually 19 days counting breaks and days I didn’t commit any work. 15 is the number of work days. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:2">
      <p>As MsLisp gets updated, redesigned, ported, these <em>features</em> are sure to be added/removed and strengthened/weakened in functionality. <a href="#fnref:2" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Matt Sheehan</name></author><summary type="html"><![CDATA[I’ve been working fervently the past 15 days1 on my first language and interpreter, a dialect of lisp I’ve come to refer to as MsLisp. I had a few goals starting, some of which are still in progress. Actually 19 days counting breaks and days I didn’t commit any work. 15 is the number of work days. &#8617;]]></summary></entry><entry><title type="html">Note on Jekyll Plugins</title><link href="https://mattsheehan.dev/archives/Jekyll-Plugins/" rel="alternate" type="text/html" title="Note on Jekyll Plugins" /><published>2015-04-21T00:00:00-04:00</published><updated>2015-04-21T00:00:00-04:00</updated><id>https://mattsheehan.dev/archives/Jekyll-Plugins</id><content type="html" xml:base="https://mattsheehan.dev/archives/Jekyll-Plugins/"><![CDATA[<p>There’s not a lot of really good documentation on how to roll your own <a href="http://jekyllrb.com">Jekyll</a> plugins, and most of the plugins that currently exist aren’t very good. That includes a few of my first attempts. Through some trial and error, <a href="http://stackoverflow.com">Stackoverflow</a> searching, and <a href="https://github.com/jekyll/jekyll">source code</a> browsing, I’ve managed to gather a few ‘best practices’. Especially for writing Generators, the most popular and used type.</p>

<p class="soliloquy">There are four types of <a href="http://jekyllrb.com/docs/plugins/">plugins</a>, Generators, Converters, Commands and Tags. This post is about generators<sup id="fnref:1"><a href="#fn:1" class="footnote" rel="footnote" role="doc-noteref">1</a></sup>.</p>

<p>There are four important things you should know about generators first.</p>

<ul>
  <li>They are invoked before the site is built, but after it is initialized, and usually directly copied to the _site folder.</li>
  <li>They must inherit from Jekyll’s base Generator class.</li>
  <li>Like all other plugins, they belong in your _plugins folder.</li>
  <li>They’re often written wrong, or at least not optimal, and most of the generators you steal will clutter up your directory.</li>
</ul>

<p>Generator’s only have one important function to know which is <code class="highlight">generate</code>, and is passed one argument <code>site</code>.</p>

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">module</span> <span class="nn">Jekyll</span>
    <span class="k">class</span> <span class="nc">MyGenerator</span> <span class="o">&lt;</span> <span class="no">Generator</span>
        <span class="k">def</span> <span class="nf">generate</span><span class="p">(</span><span class="n">site</span><span class="p">)</span>
            <span class="c1"># do stuff here</span>
        <span class="k">end</span>
    <span class="k">end</span>
<span class="k">end</span></code></pre></figure>

<p>There’s two important properties of <code>site</code> that you should learn first, those being the array <code>static_files</code> and the hash map <code>pages</code>. If you want your generator to create files that need to be converted, therefore have YAML front matter, you should add your page to <code>site.pages</code>.</p>

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">module</span> <span class="nn">Jekyll</span>
    <span class="k">class</span> <span class="nc">MyGenerator</span> <span class="o">&lt;</span> <span class="no">Generator</span>
        <span class="k">def</span> <span class="nf">generate</span><span class="p">(</span><span class="n">site</span><span class="p">)</span>
            <span class="n">site</span><span class="p">.</span><span class="nf">pages</span> <span class="o">&lt;&lt;</span> <span class="no">MyPage</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">site</span><span class="p">.</span><span class="nf">source</span><span class="p">,</span> <span class="s1">'some/directory'</span><span class="p">,</span> <span class="s1">'file.html'</span><span class="p">)</span>
        <span class="k">end</span>
    <span class="k">end</span>

    <span class="k">class</span> <span class="nc">MyPage</span> <span class="o">&lt;</span> <span class="no">Page</span>
        <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">base</span><span class="p">,</span> <span class="n">dir</span><span class="p">,</span> <span class="nb">name</span><span class="p">)</span>
            <span class="k">super</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">base</span><span class="p">,</span> <span class="n">dir</span><span class="p">,</span> <span class="nb">name</span><span class="p">)</span>
        <span class="k">end</span>
    <span class="k">end</span>
<span class="k">end</span></code></pre></figure>

<p>I created a custom page class that inherits from Jekyll’s base <code>Page</code> class. That’s not necessary in this example if you’re not doing any custom page work, but that will be important later.</p>

<p>What I’m more concerned about is <code>static_files</code>. These do not have YAML front matter and do no post-processing. But the problem with static files you see, is if you create static files in your generator and add them to the sites static_files array, those files would first get created in your project directory and then copied into your site’s root folder, which is usually _site.</p>

<p>Do you see the problem? There are duplicate files being created then immediately copied and cluttering up your source directory. Since files created at build shouldn’t be added to source control you then end up ignoring those created directories and files in your .gitignore file. I know this isn’t super performant code, so it’s not really a big deal. But sometimes it’s fun to just be clever and see how much better you can do.</p>

<p>There’s actually another secret that Jekyll hides that let us take advantage of waiting to write our static files until after the site is build and therefore only write it once into your site root folder. The base <code>Page</code> class used above actually has an important method called ‘write’, which is passed a `dest’ string.</p>

<p>When write is invoked is when we should actually be writing all of our static files. So our end code would look something like below.</p>

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">class</span> <span class="nc">MyGenerator</span> <span class="o">&lt;</span> <span class="no">Generator</span>
    <span class="k">def</span> <span class="nf">generate</span><span class="p">(</span><span class="n">site</span><span class="p">)</span>
        <span class="c1"># add our pages here to static files array</span>
        <span class="n">site</span><span class="p">.</span><span class="nf">static_files</span> <span class="o">&lt;&lt;</span> <span class="no">MyPage</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">site</span><span class="p">.</span><span class="nf">source</span><span class="p">,</span> <span class="s1">'some/directory'</span><span class="p">,</span> <span class="s1">'file.html'</span><span class="p">)</span>
    <span class="k">end</span>
<span class="k">end</span>

<span class="k">class</span> <span class="nc">MyPage</span> <span class="o">&lt;</span> <span class="no">StaticFile</span>
    <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">base</span><span class="p">,</span> <span class="n">dir</span><span class="p">,</span> <span class="nb">name</span><span class="p">)</span>
        <span class="k">super</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">base</span><span class="p">,</span> <span class="n">dir</span><span class="p">,</span> <span class="nb">name</span><span class="p">)</span>
    <span class="k">end</span>

    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="n">dest</span><span class="p">)</span>
        <span class="c1"># write is called after _site directory is built</span>
        <span class="c1"># lets write our static files once here</span>
        <span class="n">path</span> <span class="o">=</span> <span class="no">File</span><span class="p">.</span><span class="nf">join</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="n">base</span><span class="p">,</span> <span class="vi">@dir</span><span class="p">)</span>
        <span class="no">FileUtils</span><span class="p">.</span><span class="nf">mkdir_p</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>

        <span class="c1"># build up your file...</span>
        <span class="o">...</span>

        <span class="c1"># write file</span>
        <span class="no">File</span><span class="p">.</span><span class="nf">open</span><span class="p">(</span><span class="no">File</span><span class="p">.</span><span class="nf">join</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="vi">@name</span><span class="p">),</span> <span class="s1">'w'</span><span class="p">)</span> <span class="p">{</span> <span class="o">|</span><span class="n">f</span><span class="o">|</span> <span class="n">f</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="n">file</span><span class="p">)</span> <span class="p">}</span>
    <span class="k">end</span>
<span class="k">end</span></code></pre></figure>

<p>The secret is overloading the pages write method, which is usually invoked to just copy static files<sup id="fnref:2"><a href="#fn:2" class="footnote" rel="footnote" role="doc-noteref">2</a></sup>.</p>

<p class="soliloquy">You should also notice that MyPage is inheriting from StaticFile this time instead of Page. And remember to put your class’s under the Jekyll namespace.</p>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1">
      <p>This is probably the first post I’ve written in two years with any meat on it. Not good meat mind you, think more pink slime. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:2">
      <p><del>I should link these notes in the post.</del> Done. <a href="#fnref:2" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Matt Sheehan</name></author><summary type="html"><![CDATA[There’s not a lot of really good documentation on how to roll your own Jekyll plugins, and most of the plugins that currently exist aren’t very good. That includes a few of my first attempts. Through some trial and error, Stackoverflow searching, and source code browsing, I’ve managed to gather a few ‘best practices’. Especially for writing Generators, the most popular and used type.]]></summary></entry></feed>