Class Lambda

extends Object
A lambda, or closure.
Use this as a type for Lambdas (:: ...).
Lambdas are also known as closures in other languages.
Lambdas are executable pieces of code that can be passed around in a program and called for execution. A lambda can reference globals, fields, and variables. Local variables can be captured.
Aliases
  • Closure
Advanced
Lambdas and blocks both represent some code that can be called at a later point. This is why they look syntactically similar. However, contrary to blocks, lambdas can survive the function that created it. They can be returned, or stored in fields and globals.
When a lambda is called, the function that created it might not be alive anymore. As such, lambdas can not use non-local returns.

Class summary


call -> any
Calls this lambda with no arguments.
call a/any -> any
Calls this lambda with one argument.
call a/any b/any -> any
Calls this lambda with two argument.
call a/any b/any c/any -> any
Calls this lambda with three arguments.
call a/any b/any c/any d/any -> any
Calls this lambda with four arguments.
stringify -> any
See super.
hash-code -> any
Returns the hash code of this lambda.
operator == other/any -> bool
Whether this object is equal to the other.

Methods

call -> any
Calls this lambda with no arguments.

call a/any -> any
Calls this lambda with one argument.

call a/any b/any -> any
Calls this lambda with two argument.

call a/any b/any c/any -> any
Calls this lambda with three arguments.

call a/any b/any c/any d/any -> any
Calls this lambda with four arguments.

hash-code -> any
Returns the hash code of this lambda.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

stringify -> any
See super.