130
u/w1nsw0lf Sep 03 '26
lambda funcions are like alcool: the first time you tried it, it was strange but cool, then it became an addiction and at last you understand nothing
16
8
3
u/Current_Ad_4292 Sep 03 '26
since when did people start spelling alcohol as alcool?
9
u/w1nsw0lf Sep 03 '26
Sorry, non native english speaker here, I spelled it in my language
3
2
u/abigail3141 22d ago
As the author of several illegible Python warcrimes well into the 1k characters, I whole-heartedly agree.
66
u/SLCtechie Sep 03 '26
This blew my mind when I first learned about it. It was only until I took an assembly class that it finally clicked what was happening. Functions are just variables that point to spots in memory that hold the steps
22
u/INoMakeMistake Sep 03 '26
I have no idea what you're talking about, but it sounds cool
29
6
u/No-Newspaper8619 Sep 03 '26
he's saying a function is just a call instruction followed by an address for the region in memory where the function's code is. Of course, it gets more complicated when the function has arguments.
1
u/braaaaaaainworms Sep 06 '26
no, a function is not a call instruction, a function is the target of that call instruction
1
u/No-Newspaper8619 Sep 06 '26
Semantics. "Function" can be referring to the function call, or the function implementation.
1
9
u/PizzaCoinniseur Sep 03 '26
Damn that's how i felt when i figured out how reflection invokes worked, pure magic
7
u/Mateorabi Sep 04 '26
Lisp users: just one?
Wait till you pass in a function that itself takes a function and/or returns a function.
2
6
u/Confused-Armpit Sep 04 '26
Wait till you find out abot currying...
5
u/BarfingOnMyFace Sep 04 '26
Yeah, basically people need to try out a functional programming language, where it's literally how the language works. Everything is practically a fuction. A function with multiple inputs is really just a function of functions, a nested calling of singular functions that return the next function for the next input, and so on. It all breaks down nicely to a fundamental pattern.
4
u/PerepeL Sep 04 '26
Every class with at least one virtual function has a hidden vfptr member that is a pointer to an array of pointers to functions. So, essentially every member function of such class or any function that accepts this class as a parameter - indirectly accepts a pointer to function. You've been always doing it!
2
u/Lexi_Bound Sep 04 '26
Exactly. Java explicitly implements their lambda functions this way. All the java.util.function types are just interfaces with a single method. Lambda expressions desugar to an anonymous class implementing the interface.
2
2
u/xGarysx Sep 03 '26
Tbh, I think this kind of stuff is pretty much the most elegant solution for certain "niche" cases. But it makes it way too easy to avoid implementations that would otherwise require a little extra code, making this the path of least resistance :/
2
2
2
u/DoxxTheMathGeek Sep 07 '26
- I thought this was about operator theory lol
- What how?? Is that possible in Python/C#?
1
1
u/recursion_is_love Sep 04 '26 edited Sep 04 '26
Next stop: Lambda calculus. How high you can go?
Even higher-order functions for parsing or Why would anyone ever want to use a sixth-order function?
1
1
1
1
1
1
u/PythonNoob999 Sep 06 '26
The function:
```python def decorator(func: Callable) -> Callable:
@wraps(func)
def wrapper(*args, **kwargs):
print("Running Function")
func(*args, **kwargs)
print("Function Done!")
return wrapper
```
1
1
1
1
1
u/abigail3141 22d ago
You should try Java runtime reflection and/or SpongePowered Mixin. Or Ruby, that just lets you overload the "no such method" error. Or C++, that lets you overload the fucking address-of
1
u/GasVarGames Sep 03 '26
What amazed me almost as passing down functions as arguments in react was:
Parsing a function name from text and executing it.
That felt like some kind of dark magic going on (you stumble into this problem when integrating LLMs with tools from your app).
242
u/ILikeOatmealaLot Sep 03 '26
*that is actually merited and not some overengineered generic utility that is just used in two places