Compilers, LISP,
Life, Meditation, etc
Meta: Who am I? |
What's new? |
Welcome!
Nav: Books |
Programming |
Papers & Essays |
Sci-Fi |
Retro |
Attic
Books I've Written
[Choosing one of my compiler books]
- LISP From Nothing
-
This text plays with the theme of minimal LISP by providing several
implementations from a simple metacircular evaluator to a full
compiler that emits a single, self-contained C program. The discussion
is embedded in reflections on what hacking looked like in the days
of punched cards and mainframe computers. All source code from the
book is in the public domain.
- Write Your Own Retro Compiler
-
Study the complete source code for a self-hosting compiler that
runs on and generates code for CP/M on the Z80 processor. No prior
knowledge in the field of compiler construction is required. The
T3X/0 language that is discussed and implemented in the book has
its roots in Pascal and BCPL and is very simple. A complete T3X manual
is contained in the book.
-
Mental Development
– An Introduction to Theravada Buddhist Practice
-
This book introduces the reader to the basics of Buddhism with
emphasis on fundamental concepts, Pāli terminology, and meditation
practice. Mental development in Buddhist practice is based on
experiential knowledge, which can only be gained in meditation.
This book provides enough background and instructions for beginning
meditation practice and guiding the practitioner until practice
matures.
- Practical Compiler Construction
-
This book offers a tour through the full compiler for a clean and
sane subset of the C programming language (C89), covering lexical
analysis, parsing, semantics, code generation, optimization, and
runtime support, including lots of clarifying annotations and
diagrams. The SubC compiler discussed in the book is in the public
domain and can be downloaded on the book page.
- LISP System Implementation
-
A rather massive volume about the design and implementation of an
interactive LISP environment in C and LISP. Focusing on compilation
to abstract machine code, but covers all aspects of LISP implementation,
including garbage collection, syntax analysis, code generation,
semantics, tail call elimination, non-local exits, error handling,
I/O, image files, and much, much more...
- Scheme 9 from Empty Space
-
S9fES is both a book and an interpreter for the R4RS Scheme programming
language. The book offers a guided tour through every single line
of the interpreter with lots of annotations and diagrams. It covers
even the gory details, such as macro expansion,
call/cc
, and tail-call
elimination.
- Write Your Own Programs
-
This book introduces you to the world of computer programming.
Little prior knowledge is needed except for starting a text editor
and typing (but existing knowledge will not stop you from enjoying
the book). The text accompanies you all the way, from first experiments
to writing real-world programs.
- An Introduction to Array Programming in Klong
-
This book introduces you to the world of problem solving with array
operators, adverbs, idioms, and functions. Using examples of varying
complexity, from a mundane matrix formatter to a complete Gaussian
elimination solver, it takes you on an entertaining tour through
the Klong language.
- Raja Yoga Revisited
-
This book translates the ancient yoga scriptures to prose that
scientifically oriented readers of the 21st century can digest. It
explains the backgrounds of traditional yoga as described in the
Upanishads, the Bhagavad Gita, and the Yoga Sutras, and then develops
a modern metaphor for learning and teaching raja yoga. It contains
instructions for meditation practice and many tips for supporting
the practice in day-to-day life.
- Write Your Own Compiler
-
The tiniest compiler book I have ever written. It covers all steps
in the compilation process from high level language (T3X) to
executable (ELF). Lots of diagrams, lots of code, zero theory. The
tour through the compiler itself spans less than 100 pages. All
code in the book is provided under the CC0 license (public domain).
- Compiling Lambda Calculus
-
An introduction to lambda calculus and the compilation of functional
languages. Covers reduction, convertiblity, fixed points, representation
of closures, and compilation of Scheme to C. The text is completely
self-contained, but basic understanding of formal logic and programming
will be helpful. Code is in Scheme and provided under the CC0
license.
- Sketchy Scheme, 4.5th Edition
-
A beginner-friendly introduction to functional programming in Scheme.
This is a step-by-step guide to problem-solving in the functional
way. The book contains lots of examples, from trivial to advanced,
as well as Scheme definitions of many standard procedures, an
informal explanation of continuations, and a digression dealing
with lambda calculus and the Y combinator.
- Logic Programming in Scheme
-
An introduction to the principles of logic programming in MicroKANREN,
covering predicates, goals, negation, cutting, and the translation
of functional code to declarative code. Chapter two uses logic
programming to solve the well-known Zebra puzzle, and chapter three
contains the complete and annotated implementation of MicroKANREN
in portable Scheme.
- Statistics – A Short and Painless Introduction
-
A small book that covers the most fundamental principles of probability
and statistics in simple and straight-forward prose, but without
dumbing it down. Intended for students of natural and social sciences
as well as everybody else who always wanted to know how statistics
work.
- The T3X Programming Language – Formal Definition
-
This book attempts to define the semantics of T3X/0 formally,
in terms of basic functions (zero, successor, identity, μ) and naive
set theory. It assumes that you already know that basic math
(addition, multiplication, etc) can be defined in terms of basic
functions, but recommends literature, if you don't. When I started
writing this book, it seemed like a good idea for some reason.
- NMH's Incomplete Dictionary of Statistics
-
A dictionary of statistics and probability that focuses on application
and comprehensibility rather than completeness, hence an incomplete
dictionary. Topics covered include probability, inference, modelling,
regression, hypothesis testing. Contains lots of beautiful
illustrations. The PDF of this book freely available, so you can take
your own sample.
- Lightweight Compiler Techniques
-
A discussion of techniques for implementing simple yet efficient
compilers for procedural languages. Covers all phases of compilation:
scanning, parsing, optimization, code synthesis. Little theory,
lots of code. The T3X compiler described in this book can be found
below.
- Zen-Style Programming
-
An introduction to various aspects of computer science at break-neck
speed: functional programming, arbitrary-precision arithmetics,
meta-circular evaluation, searching and sorting, the limits of
computability, streams and generators, formal grammars, syntax
analysis, regular expressions, logic programming, design and
implementation of programming languages, and much more...
Programming
- The T3X Compilers
-
[Try T3X online here]
-
T3X is a small, portable, procedural, block-structured, recursive,
almost typeless, and to some degree object-oriented programming
language. It targets the Tcode machine, the 8086 under DOS, and the
386 and Alpha processors under Unix.
-
T3X/0 is superset of T3X9 and a subset of full T3X.
It has a super-portable compiler that targets CP/M on the Z80, DOS
on the 8086, various flavors of Unix on the 386, ARMv6, and ARMv7,
as well as a virtual 16-bit stack machine.
-
T3X9 is a tiny, block-structured, procedural
language. Its compiler can compile itself in the blink of an eye
(0.05s on a 750MHz notebook). It currently generates ELF executables
for FreeBSD-x86. T3X9 is a tiny subset of T3X.
-
XT3X is a T3X9 compiler and Tcode machine extended with
functions for X11 graphics and OSS sound. Intended for writing simple
video games as they were ubiquituos in the 1970's and 80's.
-
- KiloLISP, a kilo byte-sized LISP system
-
KiloLISP is a purely symbolic LISP system that runs in 64 kilo
bytes of memory (hence its name). It is written in C89 and
compiles fine using SubC, TurboC, or any modern C
compiler. The code is about 25K bytes of comprehensible C and
LISP. There is also a CP/M version and an
extended version for DOS and Unix and a
self-hosting LISP system for an even more
extended and somewhat Common LISP compatible version (although
this is no longer in the kilobyte range).
- NMH BASIC
-
This is a very tiny (less than 5KB) interpreter for a minimalistic
dialect of BASIC that I invented back in the early 1990s. It runs
on {DR,MS,PC,whatever}-DOS on the 8086 or in a virtual machine on
Unix (included).
- T3XFORTH
-
T3XFORTH is an old-school, plain vanilla FORTH system that is mostly
compatible to FORTH-79 with some parts borrowed from FIG FORTH,
FORTH-83, and EFORTH. It runs on 8086-based PC's under {PC,MS,DR,etc}-DOS,
as a VM on Unix systems, or stand-alone as its own operating system.
-
Scheme 9 from Empty Space
-
S9fES is an interpreter for the R4RS Scheme programming language and a
book describing the implementation in great detail.
The interpreter is a very mature, portable and easily extendable
implementation of R4RS Scheme. It provides an interface to some common
Unix system calls, a large library, and compiles natively on Plan9.
- The SubC Compiler
-
SubC is a clean, fast, and simple compiler for a subset of C89 that
can compile itself on various BSDs, Linux, Windows, and other
systems. It also cross-compiles to DOS. Its code is in the public
domain.
- Klong, a simple array language
-
Klong is an array language, like K or APL. Its programs use operators
to manipulate lists (vectors) and (multi-dimensional) arrays. Klong
is a mathematical notation rather than a programming language. It
uses the ASCII alphabet and has simpler semantics than K. Its
interpreter is based on S9core and should run on all
systems providing a C89 compiler as well as on Plan9.
- LISP9, an experimental LISP system
-
A LISP system that is intended to be hackable and comprehensible.
The language is a cross between R4RS Scheme and ancient LISP with
terse keywords, low-level macros, and simple semantics. The
implementation is in C and LISP9. There is a comprehensive book
describing the implementation.
- mLite, a lightweight, dynamic functional language
-
mLite is a general-purpose, functional, lightweight, dynamic
programming language. It borrows ideas from both the Scheme and
Standard ML languages, taking most of its syntax from ML and its
dynamic nature from Scheme. It extends ML-style pattern matching
by adding guarded patterns and also introduces the principle of
"implicit guards".
- Lambda Calculator
-
A set of functions and a REPL for the λKβη-calculus,
providing normal-order and applicative-order reduction, tracing,
pretty-printing, various transformations, Church numerals, etc.
- Quasiquote in Scheme
-
Minimal
quasiquote
expander using just five syntax rules.
Papers & Essays
Humanities
- Pragmatic Buddhism
-
Pragmatic Buddhism, also called Secular Buddhism, is Buddhism without
esotericism. It teaches meditation and self-investigation as skills,
not as mystic states of mind (although the results of the practice
may surprise you). This is a subdomain of T3X.ORG. It also features
a meditation FAQ.
- What to do with a high IQ?
-
Most people think that a high IQ will make you successful, attractive,
socially respected, etc, but many people actually suffer from being
highly intelligent. This paper investigates the seeming paradox.
Basic statistics required.
-
The Gap – The Reconciliation of Intelligence and Culture
(PDF, also in EPUB format)
-
How do highly intelligent and highly sensitive people experience
the world? Why is intelligence such a touchy topic? Why are smart
people often marginalized instead of benefitting from their
capabilities? An unfinished book.
- Sensitivity as a Handicap
-
A short essay explaining sensitivity, why high sensitivity is a
disadvantage in our society, and why this is a loss for all of us.
- Attention in the Digital Age
-
How does the ubiquitous fight for attention form our habits? A
statistical analysis and opinionated essay based on data from the
web server logs of this site.
- Love, Impending Doom, and the Drake Equation
-
Why we are doomed as a civilization, and why this is both inevitable
and prefectly OK. An essay about a possible explanation of the Fermi
Paradox.
-
Where Do The Failed 0.1% Go? (PDF)
-
An article about two highly intelligent people who fell through the
social safety net. Including suggestions on how not to fail such
people in the future. Published in Vidya #324/325 in 2015.
Computing
- LISPy things you can do in 64K bytes of core
-
Some of the first machines that ran LISP had less than 64K bytes
of memory, and yet there are lots of fun things that you can do on
such a machine. An exploration of purely symbolic LISP in limited
memory.
- Prolog Control in Six Slides
-
The design and implementation of a pure PROLOG interpreter plus
cuts in R4RS Scheme, based on a set of slides explaining the control
algorithm behind depth-first resolution with negation as failure
(SLDNF).
- A Stackless Floodfill Automaton (PDF)
-
A simple finite state automaton that will floodfill a shape in an
array without using a stack or a queue, but by storing data directly
in the array.
- An Introduction to Statistics with Klong
-
An introduction to the statistics library of the Klong
programming language, covering data representation, visualization, basic
statistical functions, probability distributions, χ2 tests, and
linear and non-linear regression.
- Installing modern Software
-
A short statement about the desolate state of modern software.
Science Fiction
A collection of spaceship, robot, and other models, as well
as drawings and sketches. Mostly science fiction-related. Some modified
model kits, but also some scratch-built stuff.
I have built a lot of models when I was young, but most got
lost along the way. The collection contains a few things that remained,
and also a few things I created when momentarily taking up the hobby
again.
Retro-Computing
- Some Fun with the KIM Uno
-
The KIM Uno is a pocket calculator-sized replica of the KIM-1.
These pages contain the construction of a pocket-calculator case
and a pocket calculator program for the KIM Uno.
- CP/NC - A Control Program for the NC100
-
CP/NC is a CP/M-compatible operating system for the Amstrad NC100
Notepad Computer. It is based on Russell Marks's ZCN operating
system, but aims to feel more like an old-fashioned CP/M system.
- ---==[The DOS Vault]==---
-
Some DOS programs from the 1980's and 1990's, most of them written
by me, quite a few of them never published before. Includes a few
games, the T3X compiler, a small database program, etc.
- BTN11 (btn11.zip)
-
BTN11 is a two-pass assembler that generates absolute binaries for
various models of the PDP-11. It is written in K&R (pre-ANSI) C.
- unproto 1.7 (unproto-1.7.tar.Z)
-
This is a slightly modified version of
Wietse Venema's unproto
program that works more cooperatively with the Mark
Williams C compiler on Coherent3.x. Here are the
essential differences
between the last official version (1.6) and this one.
The Attic
- FOOGOL IV, V5
-
Lindberg's FOOGOL IV compiler hacked up to emit 386 assembly language.
Also converted to modern (ANSI,89) C. Compiles fine with SubC.
- MINBASIC
-
An interpreter and compiler for an obscure BASIC dialect that I
have created back in the early 1990's. Includes some simple games
as example programs. The compiler is written in MINBASIC.
- Mini Scheme v.3
-
An extended but still tiny version of Moriwaki and Kida's Mini
Scheme interpreter, featuring string operations, type checking,
file operations, improved macro syntax, and more complete error
checking.
- PD Korn Shell
-
A slightly patched version of pdksh, compiles on most modern BSD's
and has a clear-screen function that you can bind to a key. This
was the one tcsh feature I was missing most in pdksh. And: yes, I
actually use this shell. :)
- S9fES Interpreter, 2007 (1st ed.) version
-
The original version of the Scheme9 interpreter from the first
edition of the book, including fixes to the errata from 2009.
- S9fES Interpreter, 2014 (3rd ed.) version
-
The Scheme 9 interpreter from the third edition of the book.
- S9fES Interpreter, 2018 version
-
The last version of the original (pre-Reimagined) Scheme9 interpreter.
- SOL Operating System
-
SOL is a tiny, FORTH-based operating systems for the PDP-11
(sol-11.zip) and the IBM PC (sol-86.zip). There is also a generic version (sol3.zip) running on a
virtual stack machine. You need BTN11 (above) to compile the PDP-11 version.
Bootstrapping the other versions requires a working T3X compiler.
Good luck!
- USELESS
-
An interpreter, compiler, and editor for a super-terse dialect of
FORTH. Brevity = expressiveness? You decide. Lots of funny sample
programs included.