<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>Atomized</title>
    <link>http://atomized.org</link>
    <description></description>
    <pubDate>Mon, 25 May 2026 17:22:03 UTC</pubDate>
    <lastBuildDate>Mon, 25 May 2026 17:22:03 UTC</lastBuildDate>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>Org-page static site generator (https://github.com/kelvinh/org-page)</generator>
    <item>
      <title>Bootstrapping Nonguix</title>
      <link>http://atomized.org/blog/2026/04/18/bootstrapping-nonguix</link>
      <description><![CDATA[How to perform a fresh install of nonguix]]></description>
      <pubDate>2026-05-21</pubDate>
      <guid>http://atomized.org/blog/2026/04/18/bootstrapping-nonguix</guid>
    </item>
    <item>
      <title>Maybe Later</title>
      <link>http://atomized.org/blog/2024/11/24/maybe-later</link>
      <description><![CDATA[<div>
<div class="post">
<h1>Maybe Later</h1>
<p>
"Install update"  Maybe later.
</p>

<p>
"Sign in to access this content"  No.
</p>

<p>
"It’s better in the app!"  Whose fault is that?
</p>

<p>
"We completely redesigned this thing you need to do your job for no
good reason"  Got it.
</p>

<p>
"Disable any adblocker."  Absolutely not.
</p>

<p>
"This content is for subscribers only."  Close tab.
</p>

<p>
"Accept cookies."  No.
</p>

<p>
"Try the new experience!"  Maybe later.
</p>

<p>
"Allow random website to send you notifications?"  No.
</p>

<p>
"Rate this app."  Zero stars.
</p>

<p>
"Allow GenericTodoListApp to access your location?"  No.
</p>

<p>
"Subscribe to our newsletter!"  <i>No.</i>
</p>

<p>
"Sign in with Google"  <b>No.</b>
</p>

<p>
"Donate $2.17"  <b>NO!</b>
</p>

<hr />

<p>
Why do companies ship this garbage?  Products that barely work at all,
actively stop their users from using them, and deliver awful
experiences their users hate.  Maybe someone can point to a 2%
increase on an internal dashboard, but who actually <b>likes</b> this?  Do
the people shipping this junk use their own products?
</p>

<p>
When will they start building good experiences that solve problems
instead of create new ones?
</p>

<p>
Maybe later.
</p>

</div>
</div>]]></description>
      <pubDate>2024-11-24</pubDate>
      <guid>http://atomized.org/blog/2024/11/24/maybe-later</guid>
    </item>
    <item>
      <title>Atari Space Duel Self-Test ROM Signatures</title>
      <link>http://atomized.org/blog/2022/05/30/atari-space-duel-self-test-rom-signatures</link>
      <description><![CDATA[An explanation of how Space Duel determines if a ROM is good]]></description>
      <pubDate>2022-05-30</pubDate>
      <guid>http://atomized.org/blog/2022/05/30/atari-space-duel-self-test-rom-signatures</guid>
    </item>
    <item>
      <title>Old McCarthy Had a Form</title>
      <link>http://atomized.org/blog/2021/11/28/old-mccarthy-had-a-form</link>
      <description><![CDATA[<div>
<div class="post">
<h1>Old McCarthy Had a Form</h1>
<div id="outline-container-org49ee0f8" class="outline-2">
<h2 id="org49ee0f8">What is EIEIO?</h2>
<div class="outline-text-2" id="text-org49ee0f8">
<p>
<a href="https://www.gnu.org/software/emacs/manual/html_mono/eieio.html">EIEIO</a> is an <a href="https://www.gnu.org/software/emacs/manual/html_node/eintr/">Emacs Lisp</a> implementation of (most of) the <a href="https://www.dreamsongs.com/CLOS.html">Common Lisp
Object System</a> (CLOS), which is a library for writing object-oriented
Lisp.  Both CLOS and EIEIO are implemented as normal Lisp code, with
no special support from the runtime.
</p>
</div>
</div>
<div id="outline-container-orgdb0afe5" class="outline-2">
<h2 id="orgdb0afe5">Why OOP Lisp?</h2>
<div class="outline-text-2" id="text-orgdb0afe5">
<p>
Different problems require different solutions, which is why the
most successful programming languages are multi-paradigm.  There’s
no single approach that’s optimal for every program, so choosing the
best fit for your problem yields better results than cramming
everything into the same model.  OOP’s strengths make it a good
choice for many medium- to large-sized programs needing
encapsulation, abstraction, and/or extensibility.
</p>

<p>
My goal with this is for Emacs Lisp programmers to recognize cases
where EIEIO is a good fit, and think to themselves "aha!  there’s a
thing for that!", then get on with writing their program instead of
creating tooling that reimplements part of what EIEIO already does.
</p>
</div>
</div>
<div id="outline-container-orgafe1d9e" class="outline-2">
<h2 id="orgafe1d9e">The CLOS Model</h2>
<div class="outline-text-2" id="text-orgafe1d9e">
<p>
If you’ve used OOP languages before, you may find the CLOS approach
surprising.  It’s object-oriented, but very different than popular
OOP languages like Java, Python, Ruby, C++, etc.
</p>
</div>
<div id="outline-container-org1e63d1b" class="outline-3">
<h3 id="org1e63d1b">Classes</h3>
<div class="outline-text-3" id="text-org1e63d1b">
<p>
Classes are similar to other OOP languages: they define how a
structure encapsulates data.  Unlike other languages, CLOS classes
<i>only</i> have fields ("slots," in CLOS parlance) — no methods.
</p>

<p>
Here’s an example of a base class for an EMMS player.  It only has
one slot, a boolean to indicate if it’s playing or not.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defclass form/emms-player ()             ; parent class/es
  ((playing :type boolean :initform nil)) ; slot (field) defintions
  :abstract t)                            ; EIEIO extension
</pre>
</div>

<p>
The <code>:abstract</code> option is an EIEIO extension, but it’s a good one.
Similar to Java, an abstract class may be extended, but cannot be
instantiated by itself.  They’re not always necessary, but in this
case it represents a lower type bound.
</p>

<p>
Once the base class is defined, it can be extended.  Here’s one
which can hold an MPV implementation of the <code>form/emms-player</code>:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defclass form/emms-player-mpv (form/emms-player) ; Child of form/emms-player
  ())                                             ; no additional slots
</pre>
</div>
</div>
</div>
<div id="outline-container-org0b19855" class="outline-3">
<h3 id="org0b19855">Instantiation</h3>
<div class="outline-text-3" id="text-org0b19855">
<p>
Defining the class also defines a constructor function with the
same name, so getting an object is as simple as:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(form/emms-player-mpv)
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">#s(form/emms-player-mpv nil)
</pre>
</div>

<p>
This is the normal way of creating objects, but if you’re doing
more dynamic programming and need to instantiate different classes
based on a symbol value, <code>make-instance</code> makes that easier:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(let ((class 'form/emms-player-mpv))
  (make-instance class))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">#s(form/emms-player-mpv nil)
</pre>
</div>

<p>
The <code>#s</code> reader macro will evaluate to an equivalent object, which
means objects can be printed and read as normal:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(list #s(form/emms-player-mpv nil)
      (read "#s(form/emms-player-mpv nil)"))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(#s(form/emms-player-mpv nil)
   #s(form/emms-player-mpv nil))
</pre>
</div>
</div>
</div>
<div id="outline-container-org8301543" class="outline-3">
<h3 id="org8301543">Accessing Slots</h3>
<div class="outline-text-3" id="text-org8301543">
<p>
Once you have a class instance, you can access the slots in three
ways.
</p>

<p>
The simplest are the <code>oref</code> and <code>oset</code> macros.  Since they’re terse
and don’t evaluate the slot argument, they can be convenient in
some cases.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(let ((p (form/emms-player-mpv)))
  (progn (oset p playing t)
         (oref p playing)))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">t
</pre>
</div>

<p>
The slightly more verbose <code>slot-value</code> function takes an evaluated
slot name, making it a good choice if you need to store the slot
symbol in a variable.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(let ((slot 'playing))
  (slot-value (form/emms-player-mpv) slot))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">nil
</pre>
</div>

<p>
Both styles are =setf=’able:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(let ((p (form/emms-player-mpv)))
  (list
   (progn (setf (slot-value p 'playing) t)
          (slot-value p 'playing))
   (progn (setf (oref p playing) nil)
          (oref p playing))))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(t nil)
</pre>
</div>

<p>
But the nicest way is the <code>with-slots</code> macro, which is a bit like a
destructuring let-bind.  The first argument is a list of slot
symbols, which behave like ordinary variables within the body of
the macro.  The bound symbols are also =setf=’able:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(with-slots (playing) (form/emms-player-mpv)
  (list playing (progn (setf playing t) playing)))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(nil t)
</pre>
</div>
</div>
</div>
<div id="outline-container-orgbf53f69" class="outline-3">
<h3 id="orgbf53f69">Slot Initialization</h3>
<div class="outline-text-3" id="text-orgbf53f69">
<p>
There are three ways to set the initial value of a slot.
</p>

<p>
The class’ <code>:initform</code> (if specified) is the default if no other
value is provided.  You’re not limited to constants or static
defaults — the form is evaluated at object construction time.  So
you can do things like initialize a slot with the current time:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defclass form/now ()
  ((time :initform (current-time-string))))

(list
 (oref (form/now) time)
 (progn (sleep-for 1)
        (oref (form/now) time)))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">("Sat Dec  4 15:02:31 2021" "Sat Dec  4 15:02:32 2021")
</pre>
</div>

<p>
If the class has an <code>:initarg</code> option set, it specifies the keyword
used to initialize the slot when the object is created.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defclass form/now ()
  ((time :initform (current-time-string)
         :initarg :time)))

(list (slot-value (form/now :time "about half past noon") 'time)
      (oref (make-instance 'form/now :time "a quarter till 1") time))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">("about half past noon" "a quarter till 1")
</pre>
</div>

<p>
The third way is to define an <code>initialize-instance</code> method, which
is useful for cases where initialization depends on the value of
multiple slots.  But I haven’t covered generic functions and
methods yet, so let’s do that now.
</p>
</div>
</div>
<div id="outline-container-org3bb1bcf" class="outline-3">
<h3 id="org3bb1bcf">Generic Functions</h3>
<div class="outline-text-3" id="text-org3bb1bcf">
<p>
CLOS implements dynamic dispatch from a <i>generic function</i> to a
<i>method</i>.  The generic function is like an interface: it only
specifies the function name and argument list.  CLOS doesn’t have
explicit, named interfaces.
</p>

<p>
This example shows some generic functions that would work with an
EMMS player object.  EMMS doesn’t use CLOS, but <a href="https://git.savannah.gnu.org/cgit/emms.git/tree/emms.el?id=4529ea69dd86c5e88d7fb7d568a5258b20988042#n1412">these are the same
functions it needs</a> to define a player backend.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(cl-defgeneric form/emms-playablep (player track))
(cl-defgeneric form/emms-start     (player track))
(cl-defgeneric form/emms-stop      (player t))
</pre>
</div>
</div>
</div>
<div id="outline-container-orgf6e6ca5" class="outline-3">
<h3 id="orgf6e6ca5">Methods &amp; Specialization</h3>
<div class="outline-text-3" id="text-orgf6e6ca5">
<p>
Methods are implementations of generic functions.  In the same way
that a Java interface can have many classes implementing it, a
generic function may have many methods.  Methods are never called
directly; code calls the generic function (just like any other
function), and EIEIO dynamically dispatches to an appropriate
method.  The method definitions include <i>specializers</i> which tell
CLOS when to invoke them.
</p>

<p>
Defining a method will implicitly create the generic function, if
it hasn’t already been defined.
</p>

<p>
Building on the EMMS example, here are some fake implementations of
the EMMS player functions:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">;; Method applies when PLAYER arg is an instance of form/emms-player-mpv (or a subclass)
(cl-defmethod form/emms-playablep ((player form/emms-player-mpv) track)
  (not (eql :unplayable track)))       ; MPV can play almost anything!

(cl-defmethod form/emms-start     ((player form/emms-player-mpv) track)
  "Started")

(cl-defmethod form/emms-stop      ((player form/emms-player-mpv))
  "Stopped")
</pre>
</div>

<p>
In this example, the first argument contains the specializer, which
says that the <code>player</code> argument must be an instance of
<code>form/emms-player-mpv</code> (or an instance of a subclass of it).
</p>

<p>
Even though you can dispatch on subclass-of-type, you aren’t
limited to it.  You can:
</p>

<ul class="org-ul">
<li>Dispatch on <i>primitive</i> type: <code>(x integer)</code></li>
<li>Dispatch on <i>value</i>: <code>(x (eql 5))</code></li>
<li>Dispatch on properties of <i>multiple</i> arguments: <code>((x integer) (y float))</code></li>
<li>Fallback, <i>default</i> dispatch: <code>(x t)</code></li>
<li>Define your own: see <code>cl-generic-generalizers</code></li>
</ul>
</div>
</div>
<div id="outline-container-org9b7d5d9" class="outline-3">
<h3 id="org9b7d5d9">Qualifiers</h3>
<div class="outline-text-3" id="text-org9b7d5d9">
<p>
CLOS uses a <i>qualifier</i> to support <b>four different kinds of
methods</b>.  The examples so far have had empty qualifiers, which
makes them the <i>primary method</i>; these are equivalent to methods or
functions in other languages.  In addition to those, CLOS has:
</p>

<ul class="org-ul">
<li><code>:before</code>. Evaluated before the primary method(s).</li>
<li><code>:after</code>. Evaluated after the primary method(s).
<ul class="org-ul">
<li>Both before/after are for <b>side effects only</b>; their return
values are discarded.</li>
</ul></li>
<li><code>:around</code>.  Evaluated around the all other method types.  Their
return value is the return value of the function, and they may
choose to return the primary method’s, or substitute it with
their own.</li>
</ul>

<p>
Both the primary and around methods can choose to run the rest of
the methods, by calling <code>cl-call-next-method</code>, or choose not to,
returning their own value instead.
</p>

<p>
If you’ve done much Emacs Lisp programming, those last three type
will be very familiar: they replicate Emacs’ built-in function
advice.  But, where advice runs globally on every function call,
qualified methods may be composed into an EIEIO class hierarchy.
This allows freely mixing in new behavior to existing code, without
need for guards.
</p>
</div>
</div>
<div id="outline-container-orga3b2209" class="outline-3">
<h3 id="orga3b2209">Multiple Inheritance</h3>
<div class="outline-text-3" id="text-orga3b2209">
<p>
In addition to the single inheritance in the previous examples,
EIEIO supports full multiple inheritance.  This is a very powerful
mechanism which allows deeper separation of concerns than most
languages, where extremely generic code may be composed to get the
precise behavior desired.
</p>

<p>
For example, here’s an implementation of a logging class.  It’s
completely separated from any other concerns: it only logs, and
only knows about logging.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defclass form/logger ()
  ((messages :initform nil)))

(cl-defmethod form/log ((logger form/logger) format-string &amp;rest args)
  (with-slots (messages) logger
    (push (apply #'format format-string args) messages)))

(cl-defmethod form/logs ((logger form/logger))
  (with-slots (messages) logger messages))

(cl-defmethod form/latest-log ((logger form/logger))
  (car (form/logs logger)))

(let ((l (form/logger)))
  (form/log l "Hello, %s!" "world")
  (form/latest-log l))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">"Hello, world!"
</pre>
</div>

<p>
Building on that, a generic <i>logging</i> EMMS player class can be
defined, which adapts the logger <i>class</i> to the EMMS player
<i>interface</i>.
</p>

<p>
The methods use the three novel qualifiers: <code>:before</code> is used to
emit a log prior to a player starting; <code>:after</code> is emits a lot
after the player stops, and <code>:around</code> logs whether a track was
playable.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defclass form/emms-logging-player (form/logger)
  ())

(cl-defmethod form/emms-start :before ((player form/emms-logging-player) track)
  (form/log player "Playing track: `%s'" track))

(cl-defmethod form/emms-stop :after ((player form/emms-logging-player))
  (form/log player "Stopped"))

(cl-defmethod form/emms-playablep :around ((player form/emms-logging-player) track)
  (let ((playable (cl-call-next-method player track)))
    (prog1 playable
      (form/log player "Track `%s' is%s playable" track (if playable "" "n't")))))
</pre>
</div>

<p>
With those two classes defined, they can be composed into a logging
MPV player, by defining a new class which extends a concrete MPV
player class and a logger.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defclass form/emms-logging-player-mpv (form/emms-logging-player form/emms-player-mpv)
  ())

(let ((ml (form/emms-logging-player-mpv)))
  (list (list (form/emms-playablep ml :unplayable) (form/latest-log ml))
        (list (form/emms-playablep ml :foo) (form/latest-log ml))
        (list (form/emms-start ml :foo) (form/latest-log ml))
        (list (form/emms-stop ml) (form/latest-log ml))))
</pre>
</div>

<div class="org-src-container">
<pre class="src src-emacs-lisp">((nil "Track `:unplayable' isn't playable")
 (t "Track `:foo' is playable")
 ("Started" "Playing track: `:foo'")
 ("Stopped" "Stopped"))
</pre>
</div>

<p>
Note how generic this code is:
</p>

<ul class="org-ul">
<li><code>form/logger</code> <i>only knows about logging</i>: it doesn’t know that
it’s logging EMMS actions.</li>
<li><code>form/emms-player-mpv</code> <i>only knows about playing</i>, and doesn’t
have any logging code at all.</li>
<li><code>form/emms-logging-player</code> <i>only cares about logging actions</i>,
and knows nothing about the specific player backend.  It can be
composed with <b>any player backend</b> to extend its functionality.</li>
<li><code>form/emms-logging-player-mpv</code> only combines classes, it has no
special knowledge of what they do.</li>
</ul>

<p>
The combination of multiple inheritance and before/after/around
methods allows extremely rich &amp; flexible functionality.  Around
methods mean you can add new functionality like memoization or
performance profiling to existing code, without having to change it
at all.
</p>
</div>
</div>
<div id="outline-container-org4367f1a" class="outline-3">
<h3 id="org4367f1a">Structures</h3>
<div class="outline-text-3" id="text-org4367f1a">
<p>
If you only need to encapsulate data, there’s also <code>cl-defstruct</code>.
They don't support multiple inheritance, but perform better if
you're just encapsulating data.  Since generic functions can
dispatch on any type, they can still participate in interface
abstractions.
</p>
</div>
</div>
<div id="outline-container-orgf2962fb" class="outline-3">
<h3 id="orgf2962fb">Nice Properties</h3>
<div class="outline-text-3" id="text-orgf2962fb">
<p>
There are a bunch of things I like about how this works.
</p>

<p>
It feels like normal Lisp.  There’s limited new syntax, and you
interact with the sytem by calling functions, as usual.
</p>

<p>
If you only need to encapsulate data, you can only use classes or
structs.  If you don't need a bunch of interface abstraction, you
can pass objects to normal functions.  If you <b>only</b> need interface
abstraction, you can write generic functions without using classes
or structs.  This ala carte approach allows using only what tools
are needed, instead of pulling in unnecessary baggage or boxing you
into a particular model.
</p>

<p>
Multiple inheritance means you get type punning.  An instance of
<code>form/emms-logging-player-mpv</code> is <b>both</b> a logger <b>and</b> an EMMS
player, and can be substituted for code which expects either.
</p>

<p>
An upshot of that is that third-party code can be adapted to any
interface without needing to modify it.  Whereas Java-type systems
may require building an adapter class (which then isn't an instance
of the wrapped type), CLOS doesn't have this problem.
</p>

<p>
Dynamic dispatch is fully controlled by the <i>methods</i>, rather than
the <i>generic functions</i>.  A programmer who creates an interface may
not be able to forsee all the ways it needs to be used.  Methods
declaring their own dispatch conditions means that if you’re
implementing an interface, you’re guaranteed to be able to express
the dispatch conditions you need.
</p>

<p>
Because the calling convention is <code>(function argA argB…)</code>,
there’s no possibility for a null pointer exception, because
there’s nothing to be null; the generic function always exists.
</p>

<p>
And because you can define a method specialized to a nil argument,
you can have the same nil punning as in the rest of Lisp.
</p>
</div>
</div>
</div>
<div id="outline-container-orge8d5683" class="outline-2">
<h2 id="orge8d5683">Practical Examples</h2>
<div class="outline-text-2" id="text-orge8d5683">
<p>
Now that the model's laid out, how can it be put to use?  I think
EIEIO solves a lot of very practical problems.
</p>
</div>
<div id="outline-container-org8516076" class="outline-3">
<h3 id="org8516076">Example: <code>transmission.el</code></h3>
<div class="outline-text-3" id="text-org8516076">
<p>
Here’s some abbreviated code from Emacs’ Transmission torrent client:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defcustom transmission-host "localhost")
(defcustom transmission-service 9091)
(defcustom transmission-rpc-path "/transmission/rpc")
(defcustom transmission-rpc-auth '(:username "transmission"
                                             :password "trance mission"))
</pre>
</div>

<p>
For this to work, all four variables have to be set, and set
consistently.  Annoyingly, the customization interface sorts them
alphabetically, by variable name, instead of grouped logically, by
function.  So they end up strewn all over the buffer.
</p>

<p>
Instead, these could be expressed as an EIEIO class:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defclass form/transmission-connection ()
  ((host :type string :initarg :host
         :initform "localhost"
         :custom string
         :documentation "Hostname or IP address to connect to.")
   (port :type integer :initarg :port :initform 9091
         :custom integer :label "Port"
         :documentation "TCP port on host to connect to.")
   (path :type string :initarg :path :initform "/transmission/rpc"
         :custom string
         :label "Path"
         :documentation "Path to Transmission RPC endpoint on HOST:PORT.")
   (username :type string :initarg :username :initform "transmission"
             :custom string :label "Username"
             :documentation "User to authenticate as")
   (password :initarg :password :initform nil
             :custom (choice
                      (const :tag "Fetch from auth-source" nil)
                      (string :tag "Password"))
             :label "Password"
             :documentation "Password for USERNAME"))

  :documentation "A class encapsulating a Transmission connection.")
</pre>
</div>

<p>
This has two benefits.  Firstly, Emacs’ global namespace is less
polluted.  With four variables, they all need the <code>transimission-</code>
prefix, which is kludgey.  Using a class allows for a single global
variable, bound to an object, with the data neatly tucked into its
slots.
</p>

<p>
Secondly, Emacs’ customization interface knows how to edit EIEIO
objects.  If you load <code>eieio-custom</code>, and specify the variable
holding the object as type <code>'object</code>, like this:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(require 'eieio-custom)

(defcustom form/transmission-conn (form/transmission-connection)
  "The Transmission connection."
  :type 'object
  :tag "Transmission connection")
</pre>
</div>

<p>
Then the individual slots show up as separate (but grouped)
customizable fields, making it very easy to edit, and also to
express invariants about validity, making the configuration process
much smoother.
</p>
</div>
</div>
<div id="outline-container-org1d2167b" class="outline-3">
<h3 id="org1d2167b">Example: <code>sql.el</code></h3>
<div class="outline-text-3" id="text-org1d2167b">
<p>
Here’s the definition of the PostgreSQL backend for the built-in
<code>sql.el</code>:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(postgres                               ; from sql-product-alist
 :name "Postgres"
 :font-lock sql-mode-postgres-font-lock-keywords
 :sqli-program sql-postgres-program
 :sqli-options sql-postgres-options
 :sqli-login sql-postgres-login-params
 :sqli-comint-func sql-comint-postgres
 :list-all ("\\d+" . "\\dS+")
 :list-table ("\\d+ %s" . "\\dS+ %s")
 :completion-object sql-postgres-completion-object
 :prompt-regexp "^[[:alnum:]_]*=[#&gt;] "
 :prompt-length 5
 :prompt-cont-regexp "^[[:alnum:]_]*[-(][#&gt;] "
 :statement sql-postgres-statement-starters
 :input-filter sql-remove-tabs-filter
 :terminator ("\\(^\\s-*\\\\g\\|;\\)" . "\\g"))
</pre>
</div>

<p>
There’s a similar struct for every supported backend.  The keywords
on the left are common, shared among all backends, and the values
on the right are the backend-specific implementations.  Some are
simple values, while others are functions.
</p>

<p>
This is a very clear example of an OOP interface abstraction.  It’s
<i>already OOP</i>, but it’s expressed with an ad-hoc system instead of
a formal one.
</p>
</div>
<div id="outline-container-org10356a5" class="outline-4">
<h4 id="org10356a5">Example: Modes</h4>
<div class="outline-text-4" id="text-org10356a5">
<p>
Emacs supports defining modes based on other modes’ behaviors:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(define-derived-mode shell-mode comint-mode "Shell" ...)
(define-derived-mode inferior-python-mode comint-mode "Inferior Python" ...)
</pre>
</div>

<p>
What would it look like to have major modes implemented as EIEIO
classes?  Instead of the special-case <code>define-derived-mode</code>, new
modes could extend others with the standard EIEIO mechanism.
</p>

<p>
Following this line of thought, what about minor modes?  They’re
very similar to mixins, adding new  functionality to an existing
mode.  What if, instead of enabling minor modes with hooks, they
were classes that got mixed in with major modes?
</p>
</div>
</div>
</div>
</div>
<div id="outline-container-orgc9ddf7f" class="outline-2">
<h2 id="orgc9ddf7f">Conclusion</h2>
<div class="outline-text-2" id="text-orgc9ddf7f">
<p>
I think the CLOS/EIEIO model is extraordinarily powerful, much more
so than other OOP languages I’ve worked with.  It’s amazing that
Emacs Lisp has this rich functionality out of the box, and it's a
testament to Lisp's power that a whole new paradigm can be
implemented without modifying the runtime.
</p>

<p>
This is an expanded version of my <a href="https://emacsconf.org/2021/">EmacsConf 2021</a> talk, <a href="https://emacsconf.org/2021/talks/form/">Old McCarthy
Had a Form</a>.
</p>
</div>
</div>

</div>
</div>]]></description>
      <pubDate>2021-12-04</pubDate>
      <guid>http://atomized.org/blog/2021/11/28/old-mccarthy-had-a-form</guid>
    </item>
    <item>
      <title>Common Lisp in Practice</title>
      <link>http://atomized.org/blog/2020/07/06/common-lisp-in-practice</link>
      <description><![CDATA[<div>
<div class="post">
<h1>Common Lisp in Practice</h1>
<div id="outline-container-org1ae6a3b" class="outline-2">
<h2 id="org1ae6a3b">Introduction</h2>
<div class="outline-text-2" id="text-org1ae6a3b">
<p>
One of the things which has kept Common Lisp out of my day-to-day
toolbox is a lack of clear instructions how to get up and running
with it — not in the REPL, but building small utility programs that
can be called from the shell.  I tend to reach for Python or Emacs
Lisp, since I have a good grasp and they’re readily available, but
I’ve always felt that Common Lisp could be a potent tool for these
applications.
</p>

<p>
Building a project in Lisp can be confusing, because Lisp itself
works so differently to other languages.  While there are
fundamental similarities to other <a href="https://en.wikipedia.org/wiki/AOT_compiler">AOT</a> languages, the mechanisms are
very different than most people are used to.
</p>

<p>
After reading my friend Steve’s <a href="http://stevelosh.com/blog/2018/08/a-road-to-common-lisp/">Road to Common Lisp</a>, I was inspired
to figure this out.  Many thanks to him for helping me with the
proofreading and aiding my understanding where it lacked.
</p>
</div>
</div>
<div id="outline-container-org893f18c" class="outline-2">
<h2 id="org893f18c">Goals</h2>
<div class="outline-text-2" id="text-org893f18c">
<p>
The overarching goal is to explain how to put together a Common
Lisp Program, by walking through it step by step.  The end result
should be a functional, well-understood program.
</p>

<p>
It isn’t a tutorial on Lisp programming, because there are already
<a href="http://www.gigamonkeys.com/book/">great resources</a> <a href="http://www.paulgraham.com/onlisp.html">for that</a>.
</p>

<p>
It doesn’t rathole on every possible approach you could possibly
use, but treads and illuminates the beaten path.  It explains the
less obvious nuts-and-bolts of building Common Lisp programs by
example: Where to put source code, how to make a binary, how to use
libraries.
</p>
</div>
</div>
<div id="outline-container-orgf45ccd2" class="outline-2">
<h2 id="orgf45ccd2">Running the Examples</h2>
<div class="outline-text-2" id="text-orgf45ccd2">
<p>
If you’d like to run the example code, you’ll need to install <a href="http://www.sbcl.org/">Steel
Bank Common Lisp (SBCL)</a> (for all of them) and <a href="https://www.quicklisp.org/">Quicklisp</a> (for the
last two).  The Quicklisp installation is unusual if you’re coming
from other languages, so it’s also fine to read along and see what
things are like before investing in a Lisp environment.
</p>

<p>
This is written in a <a href="https://en.wikipedia.org/wiki/Literate_programming">literate programming</a> style using <a href="https://orgmode.org/manual/Working-with-source-code.html#Working-with-source-code">org-babel</a>.
All program output should be very, very close to what you’d see if
you ran those programs.  The <a href="https://github.com/ieure/clip/blob/source/source.org">original Org document</a> and <a href="https://github.com/ieure/cl-hello/tree/output/">source code
extracted from it</a> are available in <a href="https://github.com/ieure/clip/tree/master">my GitHub repo</a>.
</p>
</div>
</div>
<div id="outline-container-org8f269f7" class="outline-2">
<h2 id="org8f269f7">Background</h2>
<div class="outline-text-2" id="text-org8f269f7">
<p>
A typical compiler is a standalone executable which runs one OS
process for each file, producing a binary artifact corresponding to
its input; a linker executable combines those into the final binary.
Some compilers output an intermediate representation (IR), such
assembly language, then spawn a separate executable to assemble
them.
</p>

<p>
Each executable represents a capability boundary.  Their
functionality is only usable in one way: by executing them with no
context except what’s provided on their commandline.
</p>

<p>
For example, if you wanted the compiler to create the assembler
listing in memory, then have the assembler work on that (skipping
the whole compiler-output/assembler-input dance), you’re out of
luck; it can’t be done.  Or if you wanted to go one better and have
the compiler create an in-memory <a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree">AST</a> the assembler can work on
directly, this is also impossible.
</p>

<p>
Another way to think about this is that most languages have a close
relationship between <i>programs</i> and <i>binaries</i>, and typically a
single binary can run a single program.  This wall precludes tight
integration of multiple programs, because they can only communicate
across the I/O constructs afforded to OS processes.
</p>

<p>
Common Lisp does not work this way.  Much like interpreted
languages, everything is loaded into one environment, and all
functionality is accessible in the same way — by calling a function.
However, Lisp goes much further than other languages.
</p>

<p>
For example, Python 3 ships with five executables:
</p>

<div class="org-src-container">
<pre class="src src-shell">dpkg -L python3-minimal | grep -c /bin/
</pre>
</div>


<p>
This includes the interpreter, a byte-compiler, another program to
remove the files the byte-compiler creates, etc.
</p>

<p>
OpenJDK has 8:
</p>

<div class="org-src-container">
<pre class="src src-shell">dpkg -L openjdk-11-jre-headless | grep -c /bin/
</pre>
</div>


<p>
GCC has 16:
</p>

<div class="org-src-container">
<pre class="src src-shell">dpkg -L gcc | grep -c /bin/
</pre>
</div>


<p>
And in order to actually <i>use</i> GCC, you also need binutils, which
has many more:
</p>

<div class="org-src-container">
<pre class="src src-shell">dpkg -L binutils | grep -c /bin/
</pre>
</div>


<p>
Can you guess how many Steel Bank Common Lisp (SBCL) has?
</p>

<div class="org-src-container">
<pre class="src src-shell">dpkg -L sbcl | grep -c /bin/
</pre>
</div>


<p>
Just one, <code>/usr/bin/sbcl</code>.  Everything that can be done with SBCL is
done inside of the environment it provides.
</p>
</div>
<div id="outline-container-org04e2d0a" class="outline-3">
<h3 id="org04e2d0a">The Environment; Images</h3>
<div class="outline-text-3" id="text-org04e2d0a">
<p>
When Common Lisp starts, it initializes a <b>Lisp environment</b> in the
computer’s memory, then evaluates a <b>toplevel function</b>.  The
environment contains the Lisp language and tools; the standard
toplevel is the <a href="https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop">REPL</a>.  When code is typed into the REPL, or loaded
from a file, it’s added to the environment and can be used by other
programs inside it.
</p>

<p>
The state of the environment can be saved to disk in a <b>Lisp
image</b><sup><a id="fnr.1" class="footref" href="#fn.1" role="doc-backlink">1</a></sup>, and restored by giving that image to <code>sbcl(1)</code>, or
executing the image directly from the shell.  When the image is
saved, a different toplevel function can be specified.
</p>

<p>
These are the building blocks for making executables.  Code is
loaded into the environment, then an image is created from that
state, with the toplevel set to the desired entry point.
</p>
</div>
</div>
</div>
<div id="outline-container-orgffe60db" class="outline-2">
<h2 id="orgffe60db">Version 1: Quick &amp; Dirty</h2>
<div class="outline-text-2" id="text-orgffe60db">
<p>
With all that out of the way, it’s time to make a traditional
"Hello, World" program.  This program will:
</p>

<ol class="org-ol">
<li>Run from a shell.</li>
<li>Use the first argument given to it as the name of the person or
thing to greet.</li>
</ol>

<p>
Starting from the ground up, the function to create the greeting:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="orgf74e529">(defun greet (whom)
  "Create a greeting message for WHOM."
  (format nil "Hello, ~A." whom))
</pre>
</div>

<p>
Trying this in the REPL shows that it works:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(greet "World")
</pre>
</div>
</div>
<div id="outline-container-org8a10368" class="outline-3">
<h3 id="org8a10368">The Toplevel Function</h3>
<div class="outline-text-3" id="text-org8a10368">
<p>
To satisfy the first requirement, a toplevel function is needed —
this will be evaluated when the image is restored, handling the
command-line arguments and printing the greeting.
</p>

<p>
I named the toplevel function <code>MAIN</code>, but it can be called
anything.  Any function which accepts zero arguments can be used as
a toplevel.
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org3698a9d">(defun main ()
  "Greet someone, or something."
  (write-line (greet (first (uiop:command-line-arguments))))

  (uiop:quit))
</pre>
</div>

<p>
There are two functions in here that may be new to you.
</p>

<p>
The command-line arguments given to an executable aren’t turned
into arguments for the toplevel function, as with other languages;
they’re returned from <code>UIOP:COMMAND-LINE-ARGUMENTS</code>.
</p>

<p>
As one might expect, <code>UIOP:QUIT</code> terminates the process.
</p>

<p>
Neither of these functions are part of the Common Lisp standard;
both come from UIOP, which bridges some of the gaps in the spec,
and between implementations.
</p>
</div>
</div>
<div id="outline-container-orgd43a59e" class="outline-3">
<h3 id="orgd43a59e">Packages</h3>
<div class="outline-text-3" id="text-orgd43a59e">
<p>
The next thing to get a handle on is packages.  This terminology is
different than in other languages, which use it in the sense of
"package manager," meaning a downloadable library and/or mechanism
to install them.
</p>

<p>
In Common Lisp, <b>a package is a namespace</b> which contains symbols.
The symbols can be defined in the package, like <code>MAIN</code> and <code>GREET</code>,
or they can be symbols inherited from other packages, like <code>DEFUN</code>
and <code>FORMAT</code> (which both come from the <code>COMMON-LISP</code> package<sup><a id="fnr.2" class="footref" href="#fn.2" role="doc-backlink">2</a></sup>).
</p>

<p>
The Hello World example should define a package, called <code>HELLO</code>.
</p>

<p>
<b>Packages must be explicitly defined before they can be used</b>.
Many languages treat a statement like:
</p>

<div class="org-src-container">
<pre class="src src-go">package hello
</pre>
</div>

<p>
As definition <i>and</i> use, i.e. everything declared in this file is
implicitly put in the <code>hello</code> package.
</p>

<p>
The similar-looking Lisp analogue of this is <code>IN-PACKAGE</code>:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org68dfd68">(in-package :hello)
</pre>
</div>

<p>
While the code is similar, the semantics are different.  This
<i>only</i> sets the active package, it won’t create <code>:hello</code><sup><a id="fnr.3" class="footref" href="#fn.3" role="doc-backlink">3</a></sup> if it
doesn’t exist.  Creating the package is an explicit step which must
be done first.
</p>

<p>
<a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_defpkg.htm">The <code>DEFPACKAGE</code> macro</a> creates a package.  It takes a symbol naming
it:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org3ecfd36">(defpackage :hello)
</pre>
</div>

<p>
In Lisp, newly-created packages are <i>completely empty</i>, and don’t
even include core language functionality like <code>DEFUN</code>.  Those
symbols can be used to by qualifying them with the package name,
but in most cases, it’s desirable to use them directly.  Adding a
<code>(:use …)</code> form inside <code>DEFPACKAGE</code> will copy other packages’
exported symbols into the package being defined:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(defpackage :hello
  (:use :common-lisp))
</pre>
</div>

<p>
If you hypothetically wanted to use to more packages, their symbols
would need to be added after <code>:common-lisp</code><sup><a id="fnr.4" class="footref" href="#fn.4" role="doc-backlink">4</a></sup>.  Note that this
should be used with care, since updates to those packages could
collide with the symbols in <code>:hello</code>.
</p>

<p>
In the same way that defining and using a package are separate,
<b>loading and using a package are also completely separate
operations</b>.  While many languages have an <code>import</code> mechanism which
both loads <i>and</i> uses, Lisp doesn’t work this way; <code>:foo</code> and
<code>:bar</code> must have been loaded already.
</p>
</div>
<div id="outline-container-org74f6a70" class="outline-4">
<h4 id="org74f6a70">Exports</h4>
<div class="outline-text-4" id="text-org74f6a70">
<p>
The last package-related topic to cover is exported symbols.  When
a symbol is exported, it may be used by packages; the set of
exported symbols comprises the public API of a package.
Non-exported symbols should only be used within the same package.
</p>

<p>
Many languages specify visibility symbol-by-symbol, at the point
of definition:
</p>

<div class="org-src-container">
<pre class="src src-java">public int hashCode()
</pre>
</div>

<p>
Lisp declares exported symbols when the <i>package containing them</i>
is defined, using the <code>(:export …)</code> form:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="orga10ce0a">(defpackage :hello
  (:use :common-lisp)
  (:export :greet :main))
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org22960ca" class="outline-3">
<h3 id="org22960ca">Tying it All Together</h3>
<div class="outline-text-3" id="text-org22960ca">
<p>
The complete source for Hello World now looks like this:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org009c66c">(defpackage :hello
  (:use :common-lisp)
  (:export :greet :main))

(in-package :hello)

(defun greet (whom)
  "Create a greeting message for WHOM."
  (format nil "Hello, ~A." whom))

(defun main ()
  "Greet someone, or something."
  (write-line (greet (first (uiop:command-line-arguments))))

  (uiop:quit))
</pre>
</div>
</div>
</div>
<div id="outline-container-org0b4fe6a" class="outline-3">
<h3 id="org0b4fe6a">Building an Image</h3>
<div class="outline-text-3" id="text-org0b4fe6a">
<p>
Because the Common Lisp toolchain exists inside the Lisp
environment, build scripts for Common Lisp project are written in,
you guessed it, Lisp.
</p>

<p>
The first thing the build script should do is load the source of
the program, which I’ve placed in <code>hello.lisp</code>:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="orgdd8cb92">(load "hello.lisp")
</pre>
</div>

<p>
Then, tell Lisp to dump the image into an executable, which will
call <code>MAIN</code> when invoked:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org54b321d">(sb-ext:save-lisp-and-die "hello"
 :toplevel 'hello:main
 :executable t)
</pre>
</div>

<p>
I’m using SBCL for these examples, and <code>SB-EXT:SAVE-LISP-AND-DIE</code>
is the SBCL way of doing this.  The precise incantation will vary
based on Lisp implementation, because it’s not part of the Common
Lisp standard.
</p>

<p>
The call to <code>SAVE-LISP-AND-DIE</code> <b>could</b> be put at the end of
<code>hello.lisp</code> for this example, but it’s is a poor separation of
concerns for anything more complex than one-off scripts.  Its
rightful place is <code>build.lisp</code>.
</p>

<p>
The complete build script goes into <code>build.lisp</code> and looks like:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org6ded0be">(load "hello.lisp")

(sb-ext:save-lisp-and-die "hello"
 :toplevel 'hello:main
 :executable t)
</pre>
</div>

<p>
Executing the build script with <code>sbcl(1)</code> will produce the binary:
</p>

<div class="org-src-container">
<pre class="src src-shell" id="org2167fdc">sbcl --non-interactive --load build.lisp
</pre>
</div>

<p>
Running it shows the message:
</p>

<div class="org-src-container">
<pre class="src src-shell" id="orgd090b6f">./hello World
</pre>
</div>


<p>
Passing in the name of the current user also works:
</p>

<div class="org-src-container">
<pre class="src src-shell">./hello $(whoami)
</pre>
</div>


<p>
Now that the program works, and you hopefully understand why and
how, it’s time to tear it down and rebuild it a few times.
</p>
</div>
</div>
</div>
<div id="outline-container-org6612d58" class="outline-2">
<h2 id="org6612d58">Version 2: Package Structure</h2>
<div class="outline-text-2" id="text-org6612d58">
<p>
Having all the code in one file is fine for a toy, but larger
programs benefit from more organization.  If the core functionality
is split from the CLI, other projects (or other parts of the same
project) can reuse the greeting function without the CLI code.
</p>

<p>
Also, Lisp packages can span files, so it’s not good practice to put
the package definition in one of the <i>N</i> files that represent its
contents.
</p>

<p>
What this should look like is:
</p>

<ul class="org-ul">
<li><code>build.lisp</code></li>
<li><code>packages.lisp</code>
<ul class="org-ul">
<li><code>src/</code>
<ul class="org-ul">
<li><code>greet.lisp</code></li>
<li><code>main.lisp</code></li>
</ul></li>
</ul></li>
</ul>

<p>
The organization is different, but the contents of the files are
almost exactly the same.
</p>

<p>
The package definition is identical to v1, but moved into <code>packages.lisp</code>:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(defpackage :hello
  (:use :common-lisp)
  (:export :greet :main))
</pre>
</div>

<p>
The greeting code is moved to <code>src/greet.lisp</code>.  It’s identical,
except it has to declare the package it belongs to.
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org5444a32">(in-package :hello)

;; Unchanged from v1
(defun greet (whom)
  "Create a greeting message for WHOM."
  (format nil "Hello, ~A." whom))
</pre>
</div>

<p>
The CLI code moves to <code>src/main.lisp</code>, and also declares what
package it’s in:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="orgbd905b2">(in-package :hello)

;; Unchanged from v1
(defun main ()
  "Greet someone, or something."
  (write-line (greet (first (uiop:command-line-arguments))))

  (uiop:quit))
</pre>
</div>

<p>
The <code>build.lisp</code> script needs to load the new pieces in the correct
order.  Since packages must be defined before they’re used,
<code>packages.lisp</code> needs to be loaded before either of the files in
<code>src/</code>; since <code>MAIN</code> calls <code>GREET</code>, the file containing <code>GREET</code> must
be loaded before the one with <code>MAIN</code>:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(load "packages.lisp")                  ; Load package definition
(load "src/greet.lisp")                 ; Load the core
(load "src/main.lisp")                  ; Load the toplevel

;; Unchanged from v1
(sb-ext:save-lisp-and-die "hello"
 :toplevel 'hello:main
 :executable t)
</pre>
</div>

<p>
Building and running works the same way:
</p>

<div class="org-src-container">
<pre class="src src-shell">sbcl --non-interactive --load build.lisp
./hello World
</pre>
</div>
</div>
</div>
<div id="outline-container-org1fbc04d" class="outline-2">
<h2 id="org1fbc04d">Version 3: Systems</h2>
<div class="outline-text-2" id="text-org1fbc04d">
<p>
The next yak in the recursive shave is <b>systems</b>.  Packages <a href="https://www.cs.cmu.edu/Groups/AI/util/html/cltl/clm/node111.html#XPACK">are part
of the Lisp language specification</a>, but systems are not; they’re
provided by a library.  The dominant systems library at the time of
writing is <a href="https://common-lisp.net/project/asdf/">ASDF</a>, which means "Another System Definition Facility."
ASDF is a de facto standard, and comes bundled with both SBCL and
Quicklisp.
</p>

<p>
Systems and packages are orthogonal, but since they both deal with
some of the same parts of the project, and the names often overlap,
it can get confusing.
</p>

<p>
A package is <b>a way of organizing the symbols of a project inside
the Lisp environment</b>.  Lisp doesn’t have a convention for
determining what package things belong to based on the path or
filename.  One package can be split across multiple files, or one
file can contain multiple packages.
</p>

<p>
A system is <b>a description of <i>how</i> to load <i>part</i> of a project into
the environment</b>.  A system can load multiple packages, or it can
load a subset of one package.  Systems encapsulate the list and
order of files needed to produce a usable package.
</p>

<p>
Further complicating things, <b>one project can have multiple
systems</b>.  A system is a view into <i>part</i> of a project, and
different code may need different pieces.  For example, test code
will need the test library loaded, or may need to set state before
loading the code to be tested, or may need to change values inside
the package containing it.  Having a separate system for tests
allows these different usecases to be supported gracefully.
</p>
</div>
<div id="outline-container-org8235cd2" class="outline-3">
<h3 id="org8235cd2">Defining the System</h3>
<div class="outline-text-3" id="text-org8235cd2">
<p>
Systems are defined in an <code>.asd</code> file, using <a href="https://common-lisp.net/project/asdf/asdf/The-defsystem-form.html">the <code>DEFSYSTEM</code> form</a>.
To maintain good separation of concerns, the Hello World project
needs two systems: one for the core, and one for the CLI.  For
these examples, I’ll be using the CLI system to demonstrate.  If
someone wanted to reuse the core <code>GREET</code> code in their own program<sup><a id="fnr.5" class="footref" href="#fn.5" role="doc-backlink">5</a></sup>,
they’d use that system.
</p>

<div class="org-src-container">
<pre class="src src-lisp">(defsystem :hello)
</pre>
</div>

<p>
There are multiple strategies for loading code, but the easiest is
to load components in the order they appear in the system
definition.  This is indicated with <code>:serial t</code>:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(defsystem :hello
  :serial t)
</pre>
</div>

<p>
Then, the components need to be specified.  These are the files and
directories the make up the system:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org525aea4">(defsystem :hello
  :components ((:file "packages")
               (:module "src"
                        :serial t
                        :components ((:file "greet")))))
</pre>
</div>

<p>
Then a secondary system for the binary.  The only new thing is
<code>:depends-on</code>, which indicates that this system relies on the
earlier one.
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org67d7410">(defsystem :hello/bin
  :depends-on (:hello)      ; This system needs the core HELLO system…
  :components ((:module :src
                :components ((:file "main"))))) ; …and includes one
                                                ; additional file.
</pre>
</div>


<p>
Putting the two declarations together into <code>hello.asd</code> results in:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(defsystem :hello
  :components ((:file "packages")
               (:module "src"
                        :serial t
                        :components ((:file "greet")))))


(defsystem :hello/bin
  :depends-on (:hello)      ; This system needs the core HELLO system…
  :components ((:module :src
                :components ((:file "main"))))) ; …and includes one
                                                ; additional file.
</pre>
</div>

<p>
Since the system defines the files and load order, the build script
doesn’t need to replicate that anymore; it can lean on Quicklisp
and ASDF instead:
</p>

<div class="org-src-container">
<pre class="src src-lisp" id="org8df4461">(ql:quickload :hello/bin)

(sb-ext:save-lisp-and-die "hello"
 :toplevel 'hello:main
 :executable t)
</pre>
</div>

<p>
ASDF needs to be told where to find the system definition, and all
others it should be able to load.  This is <a href="https://common-lisp.net/project/asdf/asdf.html#Configuring-ASDF-to-find-your-systems">a complex topic</a>, but the
simplest approach is:
</p>

<ol class="org-ol">
<li>Use Quicklisp.</li>
<li>Make a symlink from <a href="http://blog.quicklisp.org/2018/01/the-quicklisp-local-projects-mechanism.html">Quicklisp’s <code>local-projects</code></a> directory, named
after the project, which points to the source tree.</li>
</ol>

<p>
This is easily the grossest thing about this entire setup.
</p>

<div class="org-src-container">
<pre class="src src-shell">rm ~/quicklisp/local-projects/{hello,system-index.txt}
ln -sf $PWD/v3 ~/quicklisp/local-projects/hello
</pre>
</div>

<p>
The rest of the source is unchanged from v2.
</p>

<p>
Running works the same way:
</p>

<div class="org-src-container">
<pre class="src src-shell">sbcl --non-interactive --load build.lisp
./hello World
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org7ccac41" class="outline-2">
<h2 id="org7ccac41">Version 4: Using Libraries</h2>
<div class="outline-text-2" id="text-org7ccac41">
<p>
The final step is to replace UIOP’s basic program arguments with a
more full-featured library, <a href="https://github.com/libre-man/unix-opts">unix-opts.</a>
</p>

<p>
Common Lisp libraries are installed via <a href="https://www.quicklisp.org/">Quicklisp</a>, and loaded with
ASDF.  As with other Common Lisp tasks, actually installing the
library is done from the REPL.
</p>
</div>
<div id="outline-container-org25bad47" class="outline-3">
<h3 id="org25bad47">Quicklisp</h3>
<div class="outline-text-3" id="text-org25bad47">
<p>
Quicklisp is not a package manager like other languages have.
There’s no project-specific setup, like with virtualenv or rbenv.
There’s no <a href="https://res.cloudinary.com/practicaldev/image/fetch/s--asKSgsVB--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://thepracticaldev.s3.amazonaws.com/i/9i6bs4g6cx05jeagfhum.png"><code>node_modules</code></a>.
</p>

<p>
Quicklisp is more of a caching mechanism than a package manager.
Similar to Maven’s <code>~/.m2</code>, a single copy of the code is stored in
<code>~/quicklisp/dist/quicklisp/installed</code>.  ASDF looks there when
asked to load systems into a Lisp environment.
</p>

<p>
As with other tooling, the primary interface for Quicklisp is the
Lisp environment.
</p>
</div>
</div>
<div id="outline-container-org2d0dada" class="outline-3">
<h3 id="org2d0dada">Installing unix-opts</h3>
<div class="outline-text-3" id="text-org2d0dada">
<p>
The <a href="https://www.quicklisp.org/beta/">Quicklisp documentation</a> discusses this, but I’m going to cover
the essentials.
</p>

<p>
Quicklisp has <code>QL:SYSTEM-APROPOS</code>, which searches available
libraries:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(ql:system-apropos "unix")
</pre>
</div>


<p>
Installing is done with <code>QL:QUICKLOAD</code>.  This downloads the library
(if necessary) and loads its system:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(ql:quickload "unix-opts")
</pre>
</div>
</div>
</div>
<div id="outline-container-org6b5bd8f" class="outline-3">
<h3 id="org6b5bd8f">Defining the Systems</h3>
<div class="outline-text-3" id="text-org6b5bd8f">
<p>
The only change to the system definitions is adding <code>:unix-opts</code> to
the <code>:depends-on</code> form.  <b>Note that this refers to the <i>system</i>,
not the package</b>.  Systems <i>provide</i> packages, and <i>depend on</i>
other systems.  Because <code>build.lisp</code> uses <code>QL:QUICKLOAD</code> to load
the system, it’ll notice if <code>unix-opts</code> (or any other system in
<code>:depends-on</code>) hasn’t been installed, and do that automatically.
</p>
</div>
</div>
<div id="outline-container-orgc56e670" class="outline-3">
<h3 id="orgc56e670">The New <code>MAIN</code></h3>
<div class="outline-text-3" id="text-orgc56e670">
<p>
With the <code>:unix-opts</code> system loaded, the <code>:unix-opts</code> package is
available for <code>MAIN</code> to use:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(in-package :hello)

(unix-opts:define-opts
  (:name :help
   :description "Print this help text"
   :short #\h
   :long "help"))

(defun main ()
  "Greet someone, or something."
  (multiple-value-bind (options free-args)
      (unix-opts:get-opts)
    (if (or (getf options :help) (/= (length free-args) 1))
        (unix-opts:describe
         :prefix "A Hello World program."
         :args "WHOM")
        (write-line (greet (first free-args)))))

  (uiop:quit))
</pre>
</div>

<p>
Nothing needs to change in any of the other source files.
</p>
</div>
</div>
<div id="outline-container-orgd0bb8ae" class="outline-3">
<h3 id="orgd0bb8ae">Building</h3>
<div class="outline-text-3" id="text-orgd0bb8ae">
<p>
For this to work, the Quicklisp <code>local-projects</code> symlink created in
v3 needs to be updated to point here instead:
</p>

<div class="org-src-container">
<pre class="src src-shell">rm ~/quicklisp/local-projects/{hello,system-index.txt}
ln -sf $PWD/v4 ~/quicklisp/local-projects/hello
</pre>
</div>

<p>
…and the ASDF registry cleared:
</p>

<div class="org-src-container">
<pre class="src src-lisp">(asdf:clear-source-registry)
</pre>
</div>

<p>
After building (using the same commands as previously), the new
options parser is working:
</p>

<div class="org-src-container">
<pre class="src src-shell" id="org0a682b8">sbcl --non-interactive --load build.lisp
</pre>
</div>

<div class="org-src-container">
<pre class="src src-shell">./hello
</pre>
</div>


<div class="org-src-container">
<pre class="src src-shell">./hello $(whoami)
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org71c58a3" class="outline-2">
<h2 id="org71c58a3">Conclusion</h2>
<div class="outline-text-2" id="text-org71c58a3">
<p>
At over four thousand words, this piece has been <b>a lot more</b> than I
set out to write.  The process of learning, organizing, and refining
my own understanding has been wonderful.  I hope you’ve been able to
take away some of that, and will go forth with useful new tools.
</p>
</div>
</div>
<div id="outline-container-org636b676" class="outline-2">
<h2 id="org636b676">Further reading</h2>
<div class="outline-text-2" id="text-org636b676">
<ul class="org-ul">
<li><a href="http://stevelosh.com/blog/2018/08/a-road-to-common-lisp/">A Road to Common Lisp</a></li>
<li><a href="https://www.cliki.net/CL-Launch">CL-Launch</a> is a wrapper to ease running CL from the shell.  It can
produce binaries, but is more suited to simple one-file programs.</li>
</ul>
</div>
</div>
<div id="footnotes">
<h2 class="footnotes">Footnotes: </h2>
<div id="text-footnotes">

<div class="footdef"><sup><a id="fn.1" class="footnum" href="#fnr.1" role="doc-backlink">1</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">
SBCL refers to them as "cores."
</p></div></div>

<div class="footdef"><sup><a id="fn.2" class="footnum" href="#fnr.2" role="doc-backlink">2</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">
<code>:CL</code> is an alias for the <code>:COMMON-LISP</code> package, so <code>(:use
:cl)</code> is a common equivalent.
</p></div></div>

<div class="footdef"><sup><a id="fn.3" class="footnum" href="#fnr.3" role="doc-backlink">3</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">
You may note that I’ve written the name of the package as
<code>HELLO</code> (which it is), but it’s in the code as <code>:hello</code>.  For a deeper
explanation on why this is the case, I recommend <a href="http://www.gigamonkeys.com/book/programming-in-the-large-packages-and-symbols.html">the chapter on
Packages and Symbols</a> from <a href="http://www.gigamonkeys.com/book/">Programming in the Large</a>.  In the mean time,
you’ll just have to trust that it’s right and I know what I’m
doing.
</p></div></div>

<div class="footdef"><sup><a id="fn.4" class="footnum" href="#fnr.4" role="doc-backlink">4</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">
<code>:cl</code> is an alias for <code>:common-lisp</code>, so it’s common to see
that in code in the wild.
</p></div></div>

<div class="footdef"><sup><a id="fn.5" class="footnum" href="#fnr.5" role="doc-backlink">5</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">
For example, to have their program greet the user when it
starts, or to create a massively multiplayer online Hello World
(MMOHW).
</p></div></div>


</div>
</div>
</div>
</div>]]></description>
      <pubDate>2020-07-06</pubDate>
      <guid>http://atomized.org/blog/2020/07/06/common-lisp-in-practice</guid>
    </item>
    <item>
      <title>Repairing Asteroids</title>
      <link>http://atomized.org/blog/2020/05/09/repairing-asteroids</link>
      <description><![CDATA[<div>
<div class="post">
<h1>Repairing Asteroids</h1>
<div id="outline-container-org8359f35" class="outline-2">
<h2 id="org8359f35">Repairing Asteroids&#xa0;&#xa0;&#xa0;<span class="tag"><span class="ATTACH">ATTACH</span></span></h2>
<div class="outline-text-2" id="text-org8359f35">
<p>
<a href="https://en.wikipedia.org/wiki/Asteroids_(video_game)">Asteroids</a> is one of my favorite games, and I’ve owned numerous
cabinets over the years.  If my memory serves, I’ve had three
uprights and three cabarets.  My current keeper cabinet is cabaret
s/n 750, which I took to the <a href="http://retrogamingexpo.com/">Portland Retro Gaming Expo</a> from
<span class="timestamp-wrapper"><span class="timestamp">[2019-10-18 Fri] </span></span> through <span class="timestamp-wrapper"><span class="timestamp">[2019-10-20 Sun]</span></span>.  Several former Atari
employees were there, including Ed Logg (the programmer of the game)
who was kind enough to autograph my game.
</p>


<div id="org50967e3" class="figure">
<p><img src="/assets/blog/2020/05/09/repairing-asteroids/DSC_1373.JPG" alt="DSC_1373.JPG" />
</p>
<p><span class="figure-number">Figure 1: </span>My Asteroids, autographed by Ed Logg.</p>
</div>

<p>
The game made it through the show just fine, but when I put it back
in its spot in my game room and turned it on, it was playing
blind<sup><a id="fnr.1" class="footref" href="#fn.1" role="doc-backlink">1</a></sup>.
</p>

<p>
This is a newer acquisition, so I haven’t gone through it; some
problems are to be expected.
</p>

<p>
I pulled the machine back out of the row to investigate.  I found:
</p>

<ul class="org-ul">
<li>The neck of the monitor was glowing.  With raster monitors, this
is usually a very good sign, because the 6.3V for the tube
filament (which is what’s glowing) comes off the flyback, which
means that things are mostly working.  But, on these B&amp;W vectors,
the power comes from a winding on the transformer in the bottom of
the cabinet, so this doesn’t tell us anything about the state of
the monitor.</li>

<li>The spotkiller LED was off.  This lights up if the monitor has
gone into shutdown because no video signal is present.  When the
LED is off <i>and</i> the monitor isn’t working, that points to an
issue with its power supply.</li>
</ul>

<p>
So, I removed the monitor and started looking things over.  Right
away, I found that fuses F100 and F101 on the monitor’s deflection
board appeared to be blown.  I tested them anyway, by pulling one
end out of the fuse holder and using a multimeter in continuity test
mode.  You <b>always</b> want to disconnect at least one end of the fuse
from the circuit to test.
</p>

<p>
And they were, indeed, blown.
</p>


<div id="orgbe1e584" class="figure">
<p><img src="/assets/blog/2020/05/09/repairing-asteroids/DSC_1695.JPG" alt="DSC_1695.JPG" />
</p>
<p><span class="figure-number">Figure 2: </span>Blown fuses</p>
</div>

<p>
These games came with either a Wells-Gardner 15V2000 or an Electrohome
G05-805 15" B&amp;W vector monitor.  Atari made the design, then had
Wells and Electrohome manufacture them, so they’re very similar, but
not identical.  This machine has a the Electrohome version.
</p>


<div id="org922074e" class="figure">
<p><img src="/assets/blog/2020/05/09/repairing-asteroids/g05-powersupply-schematic.jpeg" alt="g05-powersupply-schematic.jpeg" />
</p>
<p><span class="figure-number">Figure 3: </span>Power supply schematic</p>
</div>

<p>
Pulling up the schematic, you can see that this is a very simple
unregulated AC-to-DC power supply, with a bridge rectifier, two
filter caps, and two decoupling caps.
</p>

<p>
The fuses protect the AC side of the diode bridge, so it’s a fair
bet that they blew because DB100 failed short and started drawing
too much current.  So, out that comes for testing.
</p>

<p>
As the schematic shows, DB100 is four diodes potted into a single
component with four leads.  It can be tested using the diode
function of a multimeter, which I did, and found it shorted.
</p>

<p>
I didn’t have a new replacement handy, so I pulled one from a parts
monitor and put it in.  I also did a field modification; later
revisions of these monitors deleted resistors R100/R101, because
they weren’t necessary, but had a high failure rate.  They can be
bypassed by soldering 18ga wire across them, which is what I did.
</p>

<p>
Next, test.  One thing I’ve learned from working on electronics of
all kinds is: if you reassamble something before testing it, it
definitely will not work.
</p>

<p>
I have an extension cable I made for this purpose, which lets me
hook the monitor up to the game while it’s sitting outside the
cabinet.  So, I did this, flipped the power on, and... success!
</p>

<p>
Back into the cabinet it went.  I also took a few minutes to vacuum
out the inside of the cabinet, clean dust off the CRT face, etc.
</p>


<div id="org31ec5ab" class="figure">
<p><img src="/assets/blog/2020/05/09/repairing-asteroids/DSC_1696.JPG" alt="DSC_1696.JPG" />
</p>
<p><span class="figure-number">Figure 4: </span>The Asteroids multi-game bootup splash screen</p>
</div>
</div>
</div>
<div id="footnotes">
<h2 class="footnotes">Footnotes: </h2>
<div id="text-footnotes">

<div class="footdef"><sup><a id="fn.1" class="footnum" href="#fnr.1" role="doc-backlink">1</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">
"Playing blind" means the game appears to be working, but isn’t
displaying an image.
</p></div></div>


</div>
</div>
</div>
</div>]]></description>
      <pubDate>2020-05-09</pubDate>
      <guid>http://atomized.org/blog/2020/05/09/repairing-asteroids</guid>
    </item>
    <item>
      <title>I like ThinkPads</title>
      <link>http://atomized.org/blog/2019/03/20/i-like-thinkpads</link>
      <description><![CDATA[<div>
<div class="post">
<h1>I like ThinkPads</h1>
<p>
When I switched back to Linux, I bought a Dell XPS 13.  It’s a very
slick little machine, but hasn’t held up quite as well as I’d hoped.
This is partly my fault, because it’s taken a couple spills, but
several issues are due to the design of the system.  It runs hot, the
fans are noisy, the rubber feet came unglued, and after two years the
battery only holds 55% of a charge.  It still works, but the issues
add up -- I don’t think I’ll be getting another one.
</p>

<p>
ThinkPads are the other line of laptops that are known for running
Linux well, so I figured I’d see what was available there.  I ended up
ordering an X1 Carbon (6th gen) while it was on sale at the end of the
year, but found that it wasn’t to my liking.  The size and build
quality are terrific, but it had a some deal-breaker issues.  The soft
touch finish feels nice, but collects skin oil so easily that it looks
grubby all the time.  The memory card reader only accepts microSD
cards, is hidden behind a panel, and you have to close the lid to
access it.  It’s pretty much unusable, and they really shouldn’t have
even bothered including it.  The high-DPI display is a weird
resolution that’s much too small at 1x scaling and much too large at
2x; and scaling to 1.5x is a big hassle in Linux.  The speakers are
also were <i>terrible</i>.  I just don’t think a laptop with a $2,000 list
price should have these kinds of issues.  I’ve never returned a laptop
in my life, but I returned this one.
</p>

<p>
Lenovo gets some credit for the painless return process.  I got 100%
of my money back without having to speak to anyone.
</p>

<p>
The ThinkPad 25 was another model I’d considered, a modern laptop with
the classic ThinkPad style "7-row" keyboard.  I was interested when it
was first announced, but never bought one.  They’ve been discontinued,
but I found one on eBay for a decent price.  It’s very nice.  It might
be <i>too</i> nice, because I’m afraid I’ll wear it out or drop it... Then
what?  Being a limited edition, parts are hard to come by.  That nice
classic style keyboard, for example: replacements were $300... when
they were available... which they aren’t anymore.  So if that breaks,
I’m out of luck.  Or if the keys wear smooth and I want to make it
look new again, I just can’t.
</p>

<p>
But it is <i>very</i> nice.
</p>

<p>
Having heard that older ThinkPads are inexpensive and still run great,
I went looking for one and ended up with an X230 from a local seller
for $180.  It’s the highest spec Core i7-3520M CPU, with 8gb RAM and a
SSD -- and a matte screen, which I’d nearly forgotten how much I
missed.  Even though it’s nearly six years old, it still works great
and is plenty powerful.
</p>

<p>
Cosmetically, it was pretty beat up.  Compared to the ThinkPad 25,
it’s actually liberating.  I don’t have to worry about putting the
first scratch on it, since it’s already got several.
</p>

<p>
The X230 is a great laptop, and I <i>really</i> like this machine; I’ve
been using it daily.  It’s a sweet spot in the ThinkPad lineup, with
classic style and good performance.  The X230 runs faster and cooler
than its predecessor, and adds USB 3.0.  The x240 which replaced it is
inferior in several ways: It uses slower Ultrabook CPUs and removes
the physical buttons from the TrackPoint.
</p>

<p>
ThinkPads are amazingly repairable.  The amount of documentation and
support for ThinkPads is <b>incredible</b>.  Every model has <a href="https://download.lenovo.com/ibmdl/pub/pc/pccbbs/mobiles_pdf/x230_x230i_hmm_en_0b48666_01.pdf">a detailed
service manual</a> that shows how to replace every major component.  You
can <a href="https://pcsupport.lenovo.com/us/en/products/laptops-and-netbooks/thinkpad-x-series-laptops/thinkpad-x230/2306/parts">look up every part</a> used in a particular model, or put in a
specific laptop’s serial number to see exactly what was in it when
built.  Lenovo still sells parts for older laptops, and what it
doesn’t stock is usually available from third parties.  Most parts are
extremely cheap, ranging around $10-$30.  Most repair jobs only take a
few minutes.  I swapped up the LCD panel for a nice IPS one in less
than five minutes.  A replacement for the cracked LCD bezel cost $13
shipped to my door.
</p>

<p>
Because all that documentation is available, ThinkPads are extremely
hackable notebooks.  Many models can use the open-source <a href="https://www.coreboot.org/">coreboot</a>
firmware, which is a free software BIOS replacement.  It lets you
neuter the Intel Management Engine, removes hardware restrictions, and
boots faster than the stock BIOS.  With <a href="https://nitrocaster.me/store/x220-x230-fhd-mod-kit.html">a hardware modification</a>, you
can replace the original LCD panel in an X220 or X230 with a 1080p
one.  You can even <a href="http://www.thinkwiki.org/wiki/Install_Classic_Keyboard_on_xx30_Series_ThinkPads">install a classic "7-row" keyboard</a> on models after
they switched to the Mac-style "island" keys.
</p>

<p>
All this is to say: I really like ThinkPads.  They’re cheap, powerful,
repairable, and hackable -- all things I really appreciate these days.
</p>

</div>
</div>]]></description>
      <pubDate>2019-03-20</pubDate>
      <guid>http://atomized.org/blog/2019/03/20/i-like-thinkpads</guid>
    </item>
    <item>
      <title>So Long, Apple</title>
      <link>http://atomized.org/blog/2019/03/20/so-long-apple</link>
      <description><![CDATA[<div>
<div class="post">
<h1>So Long, Apple</h1>
<p>
A brief history of my last Apple product purchases.
</p>
<div id="outline-container-orgbed1bd5" class="outline-2">
<h2 id="orgbed1bd5">13" MacBook Air</h2>
<div class="outline-text-2" id="text-orgbed1bd5">
<p>
Bought brand new in 2011, maxed out.  Somewhat underpowered, but
fine for most things I did.  Great design.  A good computer I was
happy with.  After three or four years, I’m thinking of a newer
one, but there have been zero compelling upgrades.  A couple
processor bumps, but they’re all the same Ultrabook CPUs with the
same number of cores running at the same speeds.  I replace the
battery instead.
</p>

<p>
Then, one day, I try to wake it from sleep.  Instead of resuming
from suspend mode, it boots up like I’d reset it.  I put my disk
password in, it gives me half a progress bar for a few minutes,
then resets.  Try again, same story; the disk has failed at the
block level and can’t be unlocked.  I boot the recovery partition,
but it can’t repair this failure.  My only option is to reinstall.
</p>

<p>
That’s fine, since I have backups, but I’m never trusting the
storage on this machine again.  The storage is soldered to the
motherboard and can’t be replaced.  Whoops.
</p>

<p>
I consider buying a new MacBook, but see that my options are
another Air without significant upgrades, a low-end MacBook Pro, or
a mainline machine with the <a href="https://www.laptopmag.com/articles/apple-macbook-keyboard-failure-rate">terrible keyboard</a> with a row of keys
replaced with a touchscreen.
</p>

<p>
I buy a Dell XPS 13 instead.
</p>

<p>
Prior to this, I owned numerous Macs: The very first first MacBook
Pro, then a Core 2 Duo, and a 27" iMac -- not including several I
had for work.
</p>
</div>
</div>
<div id="outline-container-orgf5fb348" class="outline-2">
<h2 id="orgf5fb348">iPhone 6</h2>
<div class="outline-text-2" id="text-orgf5fb348">
<p>
Bought launch day.  I soon discover that it’s too large to use
comfortably.  The metal case bends within two weeks and I get the
whole phone replaced.  It has that godawful camera bump.  It’s the
first iPhone that I disliked.
</p>
</div>
</div>
<div id="outline-container-org37b1bef" class="outline-2">
<h2 id="org37b1bef">iPhone SE</h2>
<div class="outline-text-2" id="text-org37b1bef">
<p>
The iPhone SE comes out, and I buy one as soon as I can.  It’s the
perfect form factor, has no camera bump, and it’s fairly
inexpensive despite being a very good performer.  I like it a lot
and am very happy with it.
</p>

<p>
iOS 11 happens, and it’s <i>terrible</i>, easily the single worst iOS
release ever.  Performance takes a huge hit, battery life suffers
significantly, and the number of obvious, embarrassing bugs is
through the roof.  Text overflows its containers, controls are
obscured by other things so they can’t be used, Night Shift mode
makes the whole device slow down, and it keeps popping up errors
about the iTunes store when I’m not doing anything related to it.
I loathe it.
</p>

<p>
The hardware sleep/wake button fails.  The phone thinks it’s always
being pressed, which makes it bring up the power-off screen
constantly.  I power it off.  It turns back on because the button
is pressed, but before it can finish booting, it turns off again
because the button is stuck.
</p>

<p>
The phone’s 18 months old and I don’t want to spend $100 repairing
it.  I don’t want to buy a new one, because they’re 18 months out
of date and barely run the current iOS.  Every current iPhone is
too large and still has that camera bump.  I hold out for a bit,
hoping they’ll refresh the SE, but it doesn’t happen.
</p>

<p>
I buy a Sony Xperia XZ1 Compact instead.
</p>

<p>
Prior to this, I’d owned at least every other iPhone generation
back to the very first model, and have never owned an Android
phone.
</p>
</div>
</div>
<div id="outline-container-org844f49b" class="outline-2">
<h2 id="org844f49b">iPad Mini 4</h2>
<div class="outline-text-2" id="text-org844f49b">
<p>
Having owned the first two iPad models, I was very excited to own
an iPad Mini.  It’s the perfect size.  I buy them for everyone in
my family.  My daughter breaks hers and I buy myself a nice Mini 4
and hand her down my Mini 3.
</p>

<p>
Years pass with no upgrades.  I break the screen on mine, and
again, can’t justify the repair cost, and there is no new model of
the same size.
</p>

<p>
I buy nothing instead.
</p>

<p>
Prior to this, I owned the very first iPad, an iPad 2, and iPad
Mini 1.
</p>
</div>
</div>
<div id="outline-container-orgc1a3792" class="outline-2">
<h2 id="orgc1a3792">Bye</h2>
<div class="outline-text-2" id="text-orgc1a3792">
<p>
It took me a while to write this, and in the interim, there have
been new iPad Mini and MacBook Air models released.  I don’t think
I’ll be buying them.  If I buy now, it’s going to be another four
years of neglecting the hardware, while the software makes it more
and more frustrating to use.
</p>

<p>
I love vintage hardware, but it loses its charm when you can’t run
the same vintage software -- and Apple makes it difficult or
impossible to do so.
</p>

<p>
It’s very clear to me that Apple doesn’t care about the parts of
their product lineup I did.  It’s very frustrating to see the
parade of new stuff I will never, ever buy (Apple Watch, HomePod,
AirPods) while chomping at the bit for a refreshed iPhone SE.
</p>
</div>
</div>

</div>
</div>]]></description>
      <pubDate>2019-03-20</pubDate>
      <guid>http://atomized.org/blog/2019/03/20/so-long-apple</guid>
    </item>
    <item>
      <title>Handling OS-9 RBF (Fluke 9100) floppies on Linux</title>
      <link>http://atomized.org/blog/2018/12/17/handling-os-9-rbf-(fluke-9100)-floppies-on-linux</link>
      <description><![CDATA[<div>
<div class="post">
<h1>Handling OS-9 RBF (Fluke 9100) floppies on Linux</h1>
<p>
I recently had need to figure out how to read and write floppy disks
for the Fluke 9100 on a Linux box.  There are various other methods
for accomplishing this, but I was specifically looking for something
that would work without special hardware or booting a non-Linux
operating system.  Since programs like TeleDisk / <a href="http://www.classiccmp.org/dunfield/img/index.htm">ImageDisk</a> / <a href="https://github.com/simonowen/samdisk">SAMdisk</a>
can read using the same hardware, this is purely a software issue.
</p>

<p>
You need a machine with a real floppy disk controller (FDC) -- USB
floppy drives won’t work.
</p>
<div id="outline-container-org3cbeffb" class="outline-2">
<h2 id="org3cbeffb">Background</h2>
<div class="outline-text-2" id="text-org3cbeffb">
<p>
Floppy controller hardware can’t autodetect disk formats, it needs
to be told what the format is.  When a disk is ejected/inserted, the
parameters reset to the defaults.  If the disk doesn’t match them,
the controller needs to be told what its format is again.
</p>

<p>
Linux’s floppy subsytem has many knobs exposed via <a href="https://fdutils.linux.lu/">fdutils</a>, but the
documentation isn’t great, so this requires some sleuthing.
</p>
</div>
</div>
<div id="outline-container-orgd6edd5c" class="outline-2">
<h2 id="orgd6edd5c">Disk Format</h2>
<div class="outline-text-2" id="text-orgd6edd5c">
<p>
Knowing the disk format up-front helps a lot.  The 9100A uses
soft-sector, double-sided, double-density floppies.
</p>

<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">


<colgroup>
<col  class="org-left" />

<col  class="org-right" />
</colgroup>
<tbody>
<tr>
<td class="org-left">Bytes per sector</td>
<td class="org-right">256</td>
</tr>

<tr>
<td class="org-left">Sectors per track</td>
<td class="org-right">16</td>
</tr>

<tr>
<td class="org-left">Tracks (cylinders)</td>
<td class="org-right">80</td>
</tr>

<tr>
<td class="org-left">Formatted capacity</td>
<td class="org-right">655,360 bytes</td>
</tr>
</tbody>
</table>

<p>
Later machines upgraded to a high-density drive.  All the parameters
are the same, except the sectors per track were doubled to 32,
resulting in 1,310,720 of raw storage.
</p>

<p>
Each sector on the disk has its number recorded along with the
data.  PC disk formats start numbering their sectors at 1, but OS-9
begins numbering them at 0.  This is important.
</p>
</div>
</div>
<div id="outline-container-org6c294e1" class="outline-2">
<h2 id="org6c294e1">Tuning</h2>
<div class="outline-text-2" id="text-org6c294e1">
<p>
The approach is to put the 9100 disk in, configure the controller
with <code>setfdprm(8)</code>, then read the raw sectors with <code>dd(1)</code>.  The
manpage for <code>setfdprm(8)</code> describes itself as "woefully inadequate,"
but a jaunt through the source code is enlightening, and provides us
with the following parameters for a high-density disk:
</p>

<pre class="example" id="org4305923">
sect=32 ssize=256 cyl=80 ds hd zerobased
</pre>

<p>
... which matches up nicely with what we know about the disk format.
</p>

<p>
From here, it’s a simple matter to configure and image a disk:
</p>

<div class="org-src-container">
<pre class="src src-bash">setfdprm /dev/fd0 sect=32 ssize=256 cyl=80 ds hd zerobased
dd bs=256 if=/dev/fd0 of=disk.img
</pre>
</div>

<p>
Handling a double-density disk requires a bit more tweaking, but the
following is what’s required:
</p>

<pre class="example" id="org04481dd">
sect=16 ssize=256 cyl=80 ds dd zerobased
</pre>
</div>
</div>
<div id="outline-container-org9a6dec9" class="outline-2">
<h2 id="org9a6dec9">Formatting and Writing</h2>
<div class="outline-text-2" id="text-org9a6dec9">
<p>
Before writing the disk, it has to be low-level formatted using the
correct parameters.  The arguments we’ve already discussed are
accepted by most everything in the fdutils arsenal, including
<code>superformat(8)</code>, so we can use that:
</p>

<div class="org-src-container">
<pre class="src src-shell"><span class="linenr">1: </span>superformat /dev/fd0 sect=32 ssize=256 cyl=80 ds hd zerobased
</pre>
</div>

<p>
Formatting will also set the parameters -- if you just formatted the
disk, you can <code>dd(1)</code> the image onto it now.  If the disk was
already formatted, you can call <code>setfdprm(8)</code> after inserting it and
just <code>dd(1)</code> the image.
</p>

<p>
This works for double-density media as well, however, the usual
caveats about writing DD media in a HD drive apply.  If it doesn’t
work, format the disk on a true DD drive, or degauss the media
entirely.
</p>
</div>
</div>
<div id="outline-container-org6e21e8c" class="outline-2">
<h2 id="org6e21e8c">But why</h2>
<div class="outline-text-2" id="text-org6e21e8c">
<p>
Because even though the 9100 is awesome, its editing facilities
leave a lot to be desired.  There’s no concept of version control,
and it’s relatively difficult to get debugged programs off it.
Because of all that, I’ve been making an effort to move as much
development as possible onto my regular workstation.  I wrote <a href="https://github.com/ieure/tl1-mode">an
Emacs mode</a> for the TL/1 programming language and have a Git repo
with all my TL/1 code in it.  I’ve created a build process which
syntax checks everything (using Fluke’s MS-DOS <code>TLC.EXE</code>, inside a
headless DOSBox), creates a userdisk structure, copies it into a
disk image, and writes it to disk -- all with a single <code>make(1)</code>
invocation.
</p>
</div>
</div>

</div>
</div>]]></description>
      <pubDate>2018-12-17</pubDate>
      <guid>http://atomized.org/blog/2018/12/17/handling-os-9-rbf-(fluke-9100)-floppies-on-linux</guid>
    </item>
    <item>
      <title>Repairing a Sharp PC-1261 Pocket Computer</title>
      <link>http://atomized.org/blog/2018/12/02/repairing-a-sharp-pc-1261-pocket-computer</link>
      <description><![CDATA[<div>
<div class="post">
<h1>Repairing a Sharp PC-1261 Pocket Computer</h1>
<div id="outline-container-orgcf02a0c" class="outline-2">
<h2 id="orgcf02a0c">Background</h2>
<div class="outline-text-2" id="text-orgcf02a0c">
<p>
I’ve been getting interested in vintage portable computers lately, and have bought a few to play with.  The latest is a Sharp Pocket Computer PC-1261, which is a tiny calculator-sized machine from 1984.  It has 10kb RAM, a two-line 24-character LCD display, a custom CPU that runs at 768khz, and you can program it in BASIC with the built-in QWERTY keypad.  It runs for ever on two CR2032 button batteries.
</p>

<p>
While limited, it compares pretty favorably with other early-80s machines, and the portability you get for the compromise is pretty good.
</p>

<p>
Sharp made dozens of models and variants of pocket computers from the early 80s up until the late 1990s.  They all blur the lines between computer and calculator, with the later models resembling graphing calculators, but also having an optional proprietary 2.5" external floppy disk drive.
</p>

<p>
The PC-1261 is one of the last/better models of the line which goes back to the PC-1211 from 1980.  I got mine with a CE-125 microcasette/tape interface/thermal printer, which the
PC-1261 slots right into, for programming on the go.
</p>
</div>
</div>
<div id="outline-container-org6e41002" class="outline-2">
<h2 id="org6e41002">The Problem</h2>
<div class="outline-text-2" id="text-org6e41002">
<p>
When I got mine, the batteries were dead, but fortunately not leaking.  I replaced them and it seemed to work, but would occasionally have some weird behavior when I was programming it.  It worked perfectly in RUN mode (which is immediate, like a calculator), but didn’t work right in PRO (BASIC programming) mode.  I also was seeing issues where the machine would seem to reset midway through entering a sequence, no matter what mode it was in.
</p>

<p>
This inconsistent, partly working behavior made me afraid it might be a fault on one of the parts on the PCB.  Since they’re all custom QFP parts, this wasn’t something I would be able to repair, except by replacing the board with one from another machine.  But, after messing with it a little more, I realized that it was a much simpler problem.
</p>

<p>
To change modes, you move a physical slide switch, and this switch wasn’t working reliably.  When moved into PRO mode, the computer wouldn’t recognize it.  Since you can’t enter BASIC programs in RUN mode, that explained the errors I was seeing.  Also, when I’d stretch my hand to reach a key and the machine would seem to reset, that was the switch breaking contact and the machine losing power.  This, then, is a problem I can fix.
</p>
</div>
</div>
<div id="outline-container-org2ef846f" class="outline-2">
<h2 id="org2ef846f">Opening and Repairing the Computer</h2>
<div class="outline-text-2" id="text-org2ef846f">

<div id="org1d7cbdf" class="figure">
<p><img src="/assets/blog/2018/12/02/repairing-a-sharp-pc-1261-pocket-computer/DSC_0117.JPG" alt="DSC_0117.JPG" />
</p>
<p><span class="figure-number">Figure 1: </span>Back of the computer, showing a label with the former owner’s name</p>
</div>

<p>
Two small Philips screws hold the metal back of the computer on, and removing them reveals this:
</p>


<div id="orgf7c9d1b" class="figure">
<p><img src="/assets/blog/2018/12/02/repairing-a-sharp-pc-1261-pocket-computer/DSC_0035.JPG" alt="DSC_0035.JPG" />
</p>
<p><span class="figure-number">Figure 2: </span>The inside back of the PC-1261</p>
</div>

<p>
The metal cover on the left is where the batteries are.  The PCB in the center holds the RAM.  Top left is the display contrast pot.  The right side has a cutout for the piezo speaker, as well as the expansion bus in the lower-right.
</p>


<div id="org0311cb4" class="figure">
<p><img src="/assets/blog/2018/12/02/repairing-a-sharp-pc-1261-pocket-computer/DSC_0038.JPG" alt="DSC_0038.JPG" />
</p>
<p><span class="figure-number">Figure 3: </span>RAM module removed</p>
</div>


<div id="org8f5df44" class="figure">
<p><img src="/assets/blog/2018/12/02/repairing-a-sharp-pc-1261-pocket-computer/DSC_0039.JPG" alt="DSC_0039.JPG" />
</p>
<p><span class="figure-number">Figure 4: </span>RAM module</p>
</div>

<p>
Next step is to remove the three screws securing the RAM module and remov it.  There are two grounding springs and the actual connector is a rubberized conductive foam material.
</p>

<p>
The last screw secures the PCB and back plastic frame to the front of the machine.  After the screw is removed, grab the bottom of the frame and PCB and lift it out.  There are tabs which secure them under the top lip of the front of the case.
</p>

<p>
<i>Be careful</i> when removing these parts.  The battery contacts in the plastic frame are soldered to the main PCB with thin wires.  Also, this can happen:
</p>


<div id="orgf089f0a" class="figure">
<p><img src="/assets/blog/2018/12/02/repairing-a-sharp-pc-1261-pocket-computer/DSC_0040.JPG" alt="DSC_0040.JPG" />
</p>
<p><span class="figure-number">Figure 5: </span>Tiny plastic keys all over the place</p>
</div>

<p>
They keys are tiny and will fly all over the place and get lost if you’re not careful.
</p>


<div id="org142bc96" class="figure">
<p><img src="/assets/blog/2018/12/02/repairing-a-sharp-pc-1261-pocket-computer/DSC_0042.JPG" alt="DSC_0042.JPG" />
</p>
<p><span class="figure-number">Figure 6: </span>Separated halves of the computer</p>
</div>

<p>
Once the computer is open, you can see the key membrane.  The mode switch and contacts are on the left.  The switch has two metal contacts which touch pads on the PCB.  The left side seems to be power to the computer, while the right controls the mode.
</p>

<p>
There was some visile crud on the PCB, which I cleaned the PCB with DeOxIt.  I also used it on the switch contacts, then put everything back together.  Unfortunately, it still didn’t work reliably.
</p>

<p>
Another trip inside the machine (along with messing up the keyboard again), I pulled the switch out completely, and bent the contacts down so they would make better contact with the PCB, and put it back together.  Success!  It worked perfectly.  Except I put the A key back in sideways, and reversed the DEF and SHIFT keys.  I opened it once again to correct these issues.  The switch is working like it should now, and all the keys are where they should be.
</p>


<div id="org7b385ef" class="figure">
<p><img src="/assets/blog/2018/12/02/repairing-a-sharp-pc-1261-pocket-computer/DSC_0118.JPG" alt="DSC_0118.JPG" />
</p>
<p><span class="figure-number">Figure 7: </span>The repaired computer, showing "HELLO, WORLD"</p>
</div>
</div>
</div>

</div>
</div>]]></description>
      <pubDate>2018-12-02</pubDate>
      <guid>http://atomized.org/blog/2018/12/02/repairing-a-sharp-pc-1261-pocket-computer</guid>
    </item>
  </channel>
</rss>