The Misp Chronicles VII: Seven of Nine

Over the last seven episodes, we’ve looked at seven of Misp’s constructs. In the next few episodes, we’ll examine that last two. Then we’ll take the final step of implementing a Misp meta-interpretor. Before pressing on, let’s review the first seven constructs we’ve used so far.

Syntax

Misp has two kinds of objects: symbols and pairs. We use strings to represent symbols. Here are some symbols:

look bunny RaPiD voluntary-scuba-diving fabric $++%++ perlification nil

We use parenthesis and dots to represent pairs:

(head . tail)

We adopt two rules for abbreviating constructs involving pairs:

Nil Hiding: (head) is short for (head . nil).

Tail Folding: (head tail . etc) is short for (head . (tail . etc)).

We use the shorthand rules to make Misp easier to write and read.

Semantics

Languages give meaning to structure. The structure a language uses can be anything: sound, shapes, hand motions. In Misp, it’s symbols and pairs.

In a programming language, determining the meaning of an expression is the same as running a program. Misp is a pure language: when you run a Misp program it returns a result without having any other meaningful side effects.

Misp has a generic rule for evaluating expressions. Formulating the rule precisely amount to writing an interpreter for Misp. Later in the series, we will write an interpreter for Misp using Misp.

The meaning of a pair depends on its head. Once you know the meaning of the head. You know how to use the tail to determine the meaning of the whole. The meaning of a symbol depends on context. Regardless of context nine symbols have special meaning. Today, we review how seven of the nine special symbols are interpreted.

nil evaluates to itself. nil is used to represent a “no” answer, falsehood, the empty list, or anything generally vacuous. nil => nil

quote. Quoting an expression causes it to be interpreted literally. Use quote to get a hold of the literal structure of an expression. Notation: ‘expression is short for (quote expression). ‘hi => hi ‘(a . pair) => (a . pair) ‘(what (is up)) => (what (is up)) ’’double-quote => ‘double-quote ‘(a nested ‘quote) => (a nested ‘quote)

eq tests if things are identical. Two symbols are identical if they have the same letters. No two quoted pairs are identical. (eq ‘hello ‘world) => nil (eq ‘hello ‘hello) => true (eq nil nil) => true (eq nil (eq ‘hello ‘world)) => true (eq ‘(pair) ‘(pair)) => nil

atom tests if something is a symbol. (atom nil) => true (atom ‘true) => true (atom ‘(pair)) => nil (atom ‘(pair of ((pair) . (pair)))) => nil

pair creates a pair of things. (pair nil nil) => (nil) (pair ‘pair nil) => (pair) (pair ‘hello (pair ‘world nil)) => (hello world) (pair (pair ‘a ‘b) (pair ‘c ‘d)) => ((a . b) . (c . d))

hd gets the head of a pair. (hd ‘(head . tail)) => head (hd (pair ‘head ‘tail)) => head (hd (hd (pair (pair ‘a ‘b) (pair ‘c ‘d)))) => a

tl gets the tail of a pair. (tl ‘(head . tail)) => tail (tl (pair ‘head ‘tail)) => tail (tl (tl (pair (pair ‘a ‘b) (pair ‘c ‘d)))) => d