Callable
A callable is an entity that can be invoked like a function. In many programming languages, callables include plain functions, methods bound to objects, anonymous functions (closures), and objects that implement a special call operation.
Callables are first-class citizens in many languages, meaning they can be assigned to variables, passed as arguments,
Common representations include: function pointers; closures capturing an environment; bound methods; and functors, which are objects
- Python: callable(obj) checks if obj is a function or defines __call__; many callables can be used
- Java: the Callable<V> interface defines a single method V call() used for tasks that return a value
- JavaScript: functions are first-class; any function can be invoked, passed as a value, or stored in
- PHP: the callable type and the is_callable() function support type checking and validation of values that
- C++: callables include function pointers, std::function, and functor objects; operator() enables object instances to be invoked
- Other languages such as Kotlin, Ruby, and many functional languages provide analogous concepts (for example, Proc,
Limitations and considerations:
Arity, return types, and exception behavior may differ between callables and language syntax. Dynamic invocation can