On this page:
Callable
9.0.0.4

9.9 Callables🔗ℹ

Provided only in the class space, not the annot or namespace space.

An interface that a class can implement (publicly or privately) to make instances of the class callable as functions. The interface has one abstract method, which must be overridden to implement the behavior of function calls:

  • call receives the arguments that are passed to the instance that is called as a function, and the method’s result is the result of the function call.

When a class implements Callable, then methods of Function also for work instances of the class, such as Function.map. Any same-named methods or fields in the class take precedence over Function methods.

class Posn(x, y):

  private implements Callable

  private override method call(dx, dy):

    Posn(x + dx, y + dy)

> def p = Posn(1, 2)

> p

#<function:Posn>

> p(3, 4)

#<function:Posn>

> p.map([0, 0], [1, 2])

[#<function:Posn>, #<function:Posn>]