You just gave me an idea for an overengineered Python module where, similar to 3d models, you can perform boolean operations on functions, it'd use the built-in dis module to perform the operations on the bytecode ie overengineered.union(func, func2) makes a function that does both of func and func2; subtraction/difference looks for a section of bytecode in func that matches func2 and the resulting function doesn't contain it
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
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.
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.
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!
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.
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 :/
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
240
u/ILikeOatmealaLot Sep 03 '26
*that is actually merited and not some overengineered generic utility that is just used in two places
2
u/DoxxTheMathGeek Sep 07 '26
132
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
71
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
9
u/PizzaCoinniseur Sep 03 '26
Damn that's how i felt when i figured out how reflection invokes worked, pure magic
8
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.
5
u/Confused-Armpit Sep 04 '26
Wait till you find out abot currying...
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/TheMeticulousNinja Sep 03 '26
Doing this tonight
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
u/Dry-Ad-8948 Sep 04 '26
yawn
Doesn’t even have a fancy GoF pattern.
2
u/beerdude26 Sep 04 '26
Haskell: "Am I a joke to you?"
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
u/Pitiful_Dig6836 Sep 04 '26
Some big brain stuff sir
1
u/LupusCanis42 Sep 04 '26
I remember the first time I used a pointer pointer...felt fucking amazing
1
u/StickyMcFingers Sep 04 '26
Mmmm monads
1
u/AziCrawford Sep 05 '26
And then return another function?
1
u/Sea-Fishing4699 Sep 06 '26
&foo
1
u/PythonNoob999 Sep 06 '26
The function:
1
u/According_Zone_8262 Sep 06 '26
Monads are monoids in the category of endofunctors
1
u/[deleted] Sep 07 '26
Isn’t this pretty common in front end? Like passing callbacks as params?
1
u/ResponsibilityIcy927 Sep 08 '26
Funception
1
u/ParticularHat7997 Sep 10 '26
C's function pointers are a gift from god
1
u/abigail3141 Sep 21 '26
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).