January 13th, 2025

Lambda Calculus in 383 Bytes

SectorLambda is a 383-byte binary lambda calculus implementation featuring a virtual machine with garbage collection and lazy lists, suitable for education and data compression, with compact program examples provided.

Read original articleLink Icon
CuriosityConfusionAdmiration
Lambda Calculus in 383 Bytes

The blog post discusses a new implementation of binary lambda calculus, which is a minimalist programming language, in just 383 bytes as an x86-64 Linux ELF executable. This implementation, called SectorLambda, features a Church-Krivine-Tromp virtual machine capable of garbage collection, lazy lists, and tail recursion. The interpreter processes input by extracting the least significant bit from each byte, producing binary output. While the 383-byte version is suitable for learning, a larger 520-byte version is available for more complex applications. The post highlights the compactness of programs written in binary lambda calculus, with examples demonstrating how small programs can be. It also discusses potential applications in compression formats, suggesting that the interpreter could be used to create self-extracting archives. The post includes details on how to compile and run programs, as well as examples of lambda calculus expressions and their corresponding outputs. Additionally, it provides insights into the programming constructs and definitions used within the language, emphasizing its efficiency and expressiveness compared to traditional programming languages.

- SectorLambda is a 383-byte implementation of binary lambda calculus.

- It features a virtual machine with capabilities like garbage collection and lazy lists.

- The language allows for extremely compact programs, with examples showing programs as small as 43 bytes.

- The implementation can be used for educational purposes and has potential applications in data compression.

- The post includes instructions for compiling and running programs in binary lambda calculus.

AI: What people are saying
The comments reflect a mix of curiosity, confusion, and appreciation for the binary lambda calculus implementation discussed in the article.
  • Several users express difficulty in understanding the core concepts of lambda calculus, seeking simpler explanations or introductions.
  • One commenter shares an example of a program that can be run on the virtual machine, highlighting its capabilities.
  • There is a mention of the compactness and expressiveness of the implementation, with some users surprised by its efficiency.
  • Some users draw comparisons to other programming languages and concepts, indicating a diverse range of backgrounds among commenters.
  • Technical issues are noted, with one user reporting that the implementation does not work on macOS.
Link Icon 13 comments
By @exikyut - 2 days
I've been attracted to this - along with 2D cellular automata - a bit like a moth to a flame for some time. I find the little machine visualisations mesmerising, the heavily parenthesized Greek representation charming (they look like standing orders written in an alien language, looking for all the world like space invaders) and the tiny code sizes magical.

But I can't quite wrap my mind around the core concepts and internalize them into a mental model. It's too different from the simple world of imperative C or scripting languages I guess I call home. So I'm left watching das blinkenlights from the outside, as my attention span chokes on the layers of computer science incorporated into typical explanations. *shrug*

I'd be very interested if anyone knows of an ELI5-style alternate path I could walk to break each of the concepts down one at a time. (I ask because I think this is (currently) the kind of thing I think ChatGPT would struggle to present as effectively as a human.)

By @jart - 2 days
Author here. If anyone wants to see an example of an awesome program you can run on the 520 byte version of my lambda calculus virtual machine (Blc) then check out https://github.com/woodrush/lambdalisp If you run the command in that project, it'll download my VM from the blog post, build a 20kb lambda expression you can pipe into it, and BOOM a fully object-oriented LISP REPL will appear in your terminal. It's like magic. For an example expression, try typing (+ 2 3) and hit enter. Then type (let ((a 2) (b 3)) (+ a b)) and hit enter. You need an x86 linux machine to do this right now.
By @Joker_vD - 2 days
Does anyone have a gentle introduction on binary λ-calculus? I've tried reading other pages on this site but it goes a bit too fast for me understand what the hell is going on with it.
By @memming - 5 days
"our 521 byte virtual machine is expressive enough to implement itself in just 43 bytes" whaat!
By @dang - 2 days
Discussed at the time (but before it shrank):

Lambda Calculus in 400 Bytes - https://news.ycombinator.com/item?id=30493713 - Feb 2022 (63 comments)

By @stackghost - 2 days
I feel like I've accidentally stumbled into /r/VXJunkies with some of the terminology being thrown around in here.
By @kgeist - 1 day
>nine="λλ [1 [1 [1 [1 [1 [1 [1 [1 [1 0]]]]]]]]]"

Looks like Brainfuck in disguise :)

By @jkrubin - 2 days
Anytime i see a Justine post it’s a banger — i had not read this one.
By @octagen - 1 day
Very interesting. Is it possible to imagine implementing an OS based on this ? I have been interested by lambda calculus for a while (implemented a lambda calculus interpreter in haskell) and was always wondering if people were working on "functional computers" and if it makes sense

Cheers,

By @bjourne - 2 days
Does it handle alpha-renaming? Most of the golfed interpreters I've seen over the years does not and hence does not handle the full untyped lambda calculus.
By @rizky05 - 2 days
Does not work on mac:

  > { printf 0010; printf 0101; } | ./lambda.com; echo
  zsh: done                { printf 0010; printf 0101; } |
  zsh: segmentation fault  ./lambda.com
By @jsmo - 2 days
Moar upboats plz!