
Learn C and Build Your Own Lisp (2014) - AlexeyBrin
http://www.buildyourownlisp.com/contents
======
cabaalis
I have been following this for the past few weeks in my off-time and would
recommend it to everyone. It is also geared towards teaching C. I wrote in C
many years ago but with the past 8 or so years writing exclusively C# it feels
like a homecoming.

It does make use of the author's grammar parser, which is my only minor
complaint. Does anyone know a good resource in which the author handcrafts a
parser? I'm aware of the various parser generators that exist. I also read the
dragon book in my college's compiler design course ~12 years ago. But we also
used a parser generator in that class.

~~~
drblast
[http://www.lispworks.com/documentation/HyperSpec/Body/02_b.h...](http://www.lispworks.com/documentation/HyperSpec/Body/02_b.htm)

That's the algorithm for the common lisp reader. Writing a recursive descent
parser based on that spec is fairly straightforward.

And once you hand write your own recursive descent parser you'll probably not
want to give up the control that gives you to a parser generator. Yuck.

~~~
amorphid
I was playing with a parser generator last summer, and it was immensely
frustrating to bump into bugs it had & features it lacked. In the end, it was
much easier easier to write the entire parser myself. So if I understand the
point you're making, I agree that giving up control can suck!

~~~
Jugglerofworlds
You should check out parser combinators. I've also used parser generators in
the past and experienced similar frustrations. Parser combinators are just so
much easier to use.

~~~
atomical
Hey, I saw your comment on ketamine but couldn't reply. Are you still taking
it?

------
iafisher
I read this book about a year ago and later wrote another Lisp [1] from
scratch but based on the design in the book. It's still one of my favorite
computer science books. He covers quite a range of topics (C programming,
traditional Lisp stuff, some other functional programming topics like
currying) and the quality is superb. One thing the Lisp interpreter described
in the book lacks (if I recall correctly) is a proper garbage collector, which
can be an interesting extension to the project if you're up for a challenge.

[1] [https://github.com/iafisher/scam](https://github.com/iafisher/scam)

------
deepaksurti
Previous discussions

[https://news.ycombinator.com/item?id=7530427](https://news.ycombinator.com/item?id=7530427)
and

[https://news.ycombinator.com/item?id=10474717](https://news.ycombinator.com/item?id=10474717)

------
mysterydip
Semi-related, racket [http://racket-lang.org/](http://racket-lang.org/) is a
lisp dialect and touts itself as "the world’s first ecosystem for developing
and deploying new languages. Make your dream language"

------
guywithahat
Honest question: why do people like lisp so much? Everything I've been able to
learn about the language is that it was designed for a non-register based
hardware that never caught on, so now it's just a less effective language that
doesn't run as fast as anything else and has a steep learning curve since you
need to learn a new programming paradigm. The only good thing I've heard about
it is it's simple to implement since it doesn't have a ton of functions, but
that doesn't seem like a very good reason to do something just because it's
easy to write the code.

~~~
bjoli
SBCL is together with luajit the fastest dynamic programming implementation
there is. It runs laps around things like python and ruby. It does not have a
steep learning curve. You become quite capable quite fast,but there is a lot
to an implementation like SBCL and it will take a long time to understand all
of it.

The metaprogramming utilities of lisp are still unmatched.

Scheme (my daily driver) is a smaller language. It consists of a small set of
well chosen primitives that easily compose to build higher abstractions. It is
really nice to work with.

~~~
pjmlp
Are there benchmarks of SBCL against LispWorks and Allegro?

~~~
lispm
Generally they are in the same league. I would expect that SBCL is faster in
some benchmarks and applications, but slightly slower in real life Lisp
applications. Allegro CL and LispWorks have been used for some very large
commercial applications - where the application developers demanded special
optimizations for those over the years. The implementors actually don't put
too much attention to benchmark performance - but application developers pay
for real-life performance.

I would expect that SBCL might have an advantage in some areas where it's
easier to write fast code, because of its type inference and compiler hints.
That's very useful.

Some benchmarks on smaller machines like Macs and ARM-boards.
[http://lispm.de/lisp/benchmarks.html](http://lispm.de/lisp/benchmarks.html)

~~~
pjmlp
Thanks for the insight.

------
sus_007
You can also support the author by purchasing the book from Amazon. (:
[http://www.amazon.com/Build-Your-Lisp-Daniel-
Holden/dp/15010...](http://www.amazon.com/Build-Your-Lisp-Daniel-
Holden/dp/1501006622)

------
kuwze
There is also "Write Yourself a Scheme in 48 Hours"[0].

I am looking towards following this tutorial.

[0]:
[https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_...](https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours)

------
pjmlp
As usual, the classical book for anyone interested digging into Lisp
development environments, is "Lisp in Small Pieces".

~~~
convolvatron
this book is really beautiful. it is in fact filled with exposition about how
to build a lisp, but also how to bootstrap a language (or more generally any
non-trivial environment).

queinnec went to some pains to make this book accessible, in particular by
heavily reducing his usual reliance on denotational semantics. but its not
really a good causal introduction to the topic, it requires a certain amount
of work to get through.

but can't recommend this book strongly enough, maybe as the ideal followon to
SICP

------
pankajdoharey
Not a very good tutorial if you want to learn how to make a lisp interpreter.
It uses a parser combinator library, when in reality a lisp parser is so
simple to implement that all you need is basic C skills. Infact it feels like
a self promotion of his combinator library than an actual tutorial. Better
study MAL.

------
JasonFruit
I've spent an hour on this now, and I've learned more about actual C
programming than in several previous attempts put together. What a teacher!

------
spraak
Is there a guide like this that uses Golang instead of C?

~~~
phoe-krk
You could try MAL (Make A Lisp) - it has a go version.

[https://github.com/kanaka/mal/tree/master/go](https://github.com/kanaka/mal/tree/master/go)

~~~
schoen
Another way to describe the MAL concept is that it aspires to be
implementation-language agnostic, so that it gives you a series of steps that
you're meant to follow regardless of what language you're writing your
interpreter in. So the fact that someone else has (or hasn't) already
succeeded in doing it in language X needn't affect your ability to do it
yourself with language X.

I worked through most of MAL with Python and am currently doing it in Haskell.
It's a great experience! (I think a few of the concepts could be explained in
more detail, though. Maybe I should send in a patch.)

------
nojvek
Pretty comprehensive site I should say. Even if not for LISP, it contains good
patterns for C, lexers, parsers, interpreters, etc.

As someone interested in Language. I’ll definitely be giving more thought to
it.

------
User23
This is a solid exercise. I particularly enjoy reimplementing the C primitives
in Lisp once the system is bootstrapped. I used a quine as one of my unit
tests for EVAL too.

------
Const-me
I recently wrote slightly similar example, much simpler, where I essentially
implemented 10% of Basic in modern C++: [https://github.com/Const-
me/MicroScript](https://github.com/Const-me/MicroScript)

------
htor
the question is which one learns you c the better? learn c and build your own
lisp? or learn lisp and build your own c? both poses challenges with regards
to the inner workings of c.

------
gsaga
The comments here mention a lot of advanced stuff like recursive decent and
compiler design. Should a second year student get into this book?

~~~
rwnspace
That's a question that doesn't have any really good answer, right? Unless
you're looking for someone to say 'yes, unconditionally' or 'actually [x]
requires masters-level+ mathematics'.

I'm self-studying and have been working through 'the Dragon book', regarding
compilers. I like Lisp due to beginning my learning with HtDP and SICP, and
the functional paradigm appeals to me. I'm just beginning K&R C, and
Kernighan's Unix Programming Environment. Naturally I'm really excited to find
this here so I'll definitely be working through it.

Were I more concerned about ticking boxes on my CV for the person in HR then I
probably wouldn't bother.

------
masayune
Is this a good resource to beat the fear of recursion out of me? I get
recursion, but it’s still really uncomfortable to think about.

~~~
chuchana
I liked Common Lisp: A Gentle Introduction to Symbolic Computation. You can
find its first edition online (free of charge):
[https://www.cs.cmu.edu/~dst/LispBook/](https://www.cs.cmu.edu/~dst/LispBook/)

Apart from explanations, it also contains exercises and their solutions.

~~~
masayune
Woah! Thank you for the suggestion!

------
p0nce
A great way to learn about the value of syntax.

------
aecorredor
Does this cover memory management?

~~~
shakna
Kinda?

Every value has both a constructor that assigns memory, and a destructor that
frees it. Every expression also reallocates it's memory as it processes. So
memory is managed and doesn't leak, but it doesn't quite fit with what we know
as a GC, and could trash performance in some cases.

And Tail-Call-Optimisation isn't really touched on.

~~~
nils-m-holm
If you excuse the plug:

Scheme 9 from Empty Space
([https://www.t3x.org/s9book/index.html](https://www.t3x.org/s9book/index.html))
explains GC, tail call elimination, continuations, macros, bignums, flonums,
etc.

------
agumonkey
Find the style and code lovely.

------
mastrsushi
If you want a job as an entry level programmer, do not bother learning C, go
with something like C#, JavaScript, Java, or Python.

The author doesn't really list any viable reasons to use C over any more
modern, convenient language. Just the whole "shows you how memory management
really works". A lot of C programmers remind me of the die hard Gentoo/Arch
Linux people who think it'll help them "show you how Linux really works".

~~~
tannhaeuser
The value of learning asm and C doesn't necessarily come from using these
languages, but lies in understanding how a CPU works and how memory is laid
out and managed. So that you can put abstractions and automatic memory
management to good work. There's a reason Knuth uses his MIX assembler
language for discussing algorithms and algorithmitic complexity analysis. If
you don't know these things, you basically don't know what you're doing when
you're programming a computer.

