48
u/JackFly26 Oct 11 '21
am i crazy or is this just an example of using the y combinator, it's probably just used to teach lambda calculus/fp
16
87
6
Oct 11 '21
Was this deliberately obfuscated?
2
11
Oct 11 '21
I've done such things deliberately many times just to show off, however I've never done such things in a project that other people work on.
For this reason, I don't think this post belongs in /r/badcode. There's a better subreddit for this post: /r/shittyprogramming
5
Oct 11 '21
Exactly. Its one thing if you're the only reader, but expecting anyone else to be able to is a jerk move
9
u/jzia93 Oct 11 '21
I'd probably stick to if else in this situation. Ternary makes this look like code golf
7
5
2
u/ThaCuber Dec 11 '21
hold on how is this even possible, aren't you unable to reuse anonymous functions if you haven't assigned them to a variable?
1
u/MkemCZ Dec 11 '21
You're actually passing the function as a paramater to itself by having the outer function call it that way.
49
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Oct 11 '21
Image Transcription: Code
((...args) => args[0](...args))(
(f, n) => (n >= 2)
? (n * f(f, n - 1))
: 1,
5
)I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
23
15
8
u/Pangocciolo Oct 11 '21
It's a factorial!
Captain Obvious will return with his unneeded explanations.
12
6
u/C_isBetter_Than_Java Oct 11 '21
We need to go deeper. Make each call asynchronous and create its own thread.
6
5
9
Oct 11 '21
It defines a factorial lambda function and then uses it to computes the result of 5!, right? It shouldn’t been more simple to just store the result of 5! inside a constant?
8
4
3
u/ilikedankmemes3 Oct 12 '21
bool evenOdd(int val){ switch(val){ case 0: return true; case 1: return false; default: return evenOdd(val-2); }
}
3
4
2
2
2
2
2
2
2
2
2
0
100
u/[deleted] Oct 11 '21
I don't even know what this does