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
Also, this is likely way more compact than Brainfuck, as the lambda calculus is written essentially as usual.
And seriously, very cool!
Also shouldn't the indexes be expressed as a repeated character? Like "---" would be index 3. Integer literals are decidedly non-brainfuck as well.
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.
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.
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!
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.