Comment by ndriscoll
17 hours ago
Not just function pointers. E.g. in Scala:
def addX(x: Int): Function[Int,Int] = {
y => x+y
}
addX(5) then returns a function that adds 5. So closures, which are equivalent to objects (behind the scenes, the compiler needs to allocate a structure to remember that 5 and know the "member function" to call to do the plus), and usually more straightforward.
Once you get used to doing this, you realize it's useful everywhere.
In a decent language with functional programming and generics support a lot of GoF patterns can be directly encoded as a simple type signature where you receive, return, or both some function, so there's not really much else to say about them. Like half of the behavioral patterns become variations of the interpreter pattern.
Pardon my ignorance, isn't that a lambda in c++?
Yes, and in Java and other languages (e.g. in Lean you can literally use the syntax λ x ↦ x + 5). When OOP was more of the zeitgeist, these languages didn't have lambda functions.