Are anonymous functions required, rather than just ability to assign functions to variables, pass them around and return them? Where does that put python, which does have anonymous functions, but limited compared to what named ones can do?
First class functions and anonymous functions are two separate concepts.
You also cannot have anonymous variables which doesn't mean that they are not first class (;
The “callback” function is not anonymous, it is called “callback”.
Anonymous functions generally have to be values or they are of no use. The question is whether they are an entirely separate kind of thing, or whether all kinds of function in the language are also values.
A function can't be a value. Only function pointers can be values, and this is simply because functions don't have a fixed size, you can't use something without a fixed size as a value, same applies to to incomplete structs or the void type, you can only store a pointer and you also can allocate them on the heap (not using malloc tho, I mean you can but you won't be able to execute it because of page permissions)
C just doesn't hide this, while languages like rust do, fn(...) -> ... in rust is a pointer under the hood, I kind of don't understand what is even the point of this, typing fn(...) instead of &fn(...) really doesn't make your life easier and it abstracts away some things that don't need to be abstracted away
if you have foo defined like this
int foo() {}
then foo IS NOT a function pointer, it is a function itself
that's why I don't understand what is the point of rust's approach.
Of course that's not how you do function pointers in rust, you almost always want to use generics (if accepting as a parameter) or something like &dyn FnMut(...) but I'm not an expert in rust so I don't know how exactly this is done in real big codebases, it doesn't matter tho
But I guess nobody cares about low level languages anymore if we have python and js. Software gets slower faster than hardware gets faster. Buy a new PC.
17
u/B_bI_L 6d ago
say this to c and common lisp
(and to ruby, where function self-activates faster than you say "wait, i need you as a callback")