Hacker News·4 min read·hard

Needed 1+1, built a functional programming language

B
birdculture
Needed 1+1, built a functional programming language
✦AI Summary

A programmer recounts the process of building a custom functional programming language in C to solve a data structure problem. The project evolved from a simple expression evaluator into a complex system including closures and garbage collection.

Why it matters

It provides insight into the low-level implementation details of programming language design and compiler construction.

✦Dive DeeperCreate a free account to unlock

I was given a data structures problem of converting an arithmetic expression into a binary tree. Naturally, I decided to build an evaluator.

A few days later I implemented closures, a garbage collector, a custom memory allocator, a REPL, an FFI, and a whole bunch of other stuff in C.

The problem was: Evaluate 1 + 1 + 1 to 3 using a binary tree.

(+) / \ (+) (1) / \ (1) (1) The operator becomes the root, with its two operands as children.

First, we evaluate the root’s left operand. It’s another + expression, so we have to collapse it down to a value before the outer + can execute.

(3) <--- that's our result We just performed the equivalent of

Continue reading on Headlinne

Create a free account to read the full article.

Read full article →
technologyeducation
✦

Get smarter about the news

Sign up free for a feed built around what you actually care about, Dive Deeper research on any story, and the full text of every article.

Create free account

Already have an account? Sign in