Show HN: Lambduck, a Functional Programming Brainfuck

28 jorkingit 11 6/5/2025, 11:29:35 PM imjakingit.github.io ↗
What if Brainfuck was less like C and more like Scheme?

The interpreter implemetation is pretty bad. It's not very fast, it's not very good, and it's probably not very correct. But maybe there's some vaguely interesting programs you could write with it!

For example, the Y combinator:

  λf. (λx. f (x x)) (λx. f (x x))
is written as:

  \` \`1 `0 0 \`1 `0 0

Comments (11)

mmoskal · 5h ago
This seems way too readable! I think you should remove the character literals in the name of purity.

Also, this is likely way more compact than Brainfuck, as the lambda calculus is written essentially as usual.

And seriously, very cool!

jorkingit · 4h ago
Thanks! I'm torn on having the character literals actually; they're definitely syntactical sugar, but I was struggling to write programs that printed anything without them getting super unwieldy! If someone smarter than me can write a compact-looking enough Hello World program then consider them gone ;-)
fc417fc802 · 2h ago
Yeah there's something wrong with the idea of brainfuck having character literals. The de bruijn indexing is definitely on point but the lack of continuations feels wrong to me given the stated goal.

Also shouldn't the indexes be expressed as a repeated character? Like "---" would be index 3. Integer literals are decidedly non-brainfuck as well.

jorkingit · 1h ago
getchar does take a continuation of sorts (as in continuation passing) which is passed the input. In one my initial drafts, getchar was a special form that would accept input at the point of evaluation, which was really funny and unpredictable.

putchar I feel kind of weird about, it acting as an identity function with a side effect is kind of weird; I'm not sure changing it to take a second argument as a continuation would make it better or worse.

Regarding the de Bruijn indices, I don't think there's a huge distinction between writing 3 vs writing ---: it would still form a single lexical token, so I feel like --- is just more noise.

Perhaps a de Bruijn index register you could move around and dereference? e.g. from index 1, index 3 is >>*, then index 2 from there is <*. But that feels less functional, because you're now imperatively manipulating some hidden state.

fc417fc802 · 1h ago
Entirely agreed that it's nothing but more noise, but isn't that exactly how BF is? Why ----- instead of 5-? Well, because BF of course. The point of the exercise (IMO) is having the bare minimum in parsed characters to achieve the turing tarpit.

I quite like the movable register idea but as you say that's no longer a "BF except lambda calculus" it's some other esolang at that point.

I think my objection about the lack of continuations was misplaced given that appears to be a BF take on the lambda calculus rather than a BF take on scheme.

jorkingit · 1h ago
You can always write it in continuation-passing style if you really want continuations! It's not pleasant but none of this is supposed to be ;-)

Agreed on having too many characters though, I don't like that having numerical indices makes the syntax whitespace-sensitive, too.

And once I figure out how to write hello world, those character literals are gone!

fc417fc802 · 31m ago
Maybe my brain just isn't functioning right now but I don't think writing in CPS is the same as having access to first class continuations? But as previously noted I think that was a misplaced request on my part to begin with.
90s_dev · 5h ago
This is far too clever for me to even begin to understand.

How do you get the hello world working?

I tried pasting ,--('\< into the code and if it walks like a lamb and quacks like a duck into the stdin field.

jorkingit · 4h ago
Hello world should be:

  ``\\1`.'h``\\1`.'e``\\1`.'l``\\1`.'l``\\1`.'o``\\1`.' ``\\1`.'w``\\1`.'o``\\1`.'r``\\1`.'l``\\1`.'d`.'!
Groxx · 3h ago
I feel like adding a bit more brainfuckery would help obscure stuff. Make people use Church numerals to form ASCII characters - it'll encourage golfing it down to something equally as obtuse as

    ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
jzemeocala · 5h ago
Do Malborge next