{
  "category": "Logical functions",
  "display_name": "LAMBDA",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.LAMBDA",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 28 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": false,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 28 recorded answers",
    "workbook_corpus": {
      "cells": 28,
      "matched": 28
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-fml/src/eval/compile.rs#L1417-L1474",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-fml/src/eval/compile.rs#L458-L461"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "eval/compile::declared_name",
        "eval/compile::parameter_key",
        "eval/compile::without_prefix",
        "eval/compile::only_token",
        "eval/compile::text",
        "syntax/token::Token::text"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-fml/src/eval/compile.rs#L1417-L1474",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 28 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.LAMBDA.json",
  "name": "LAMBDA",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\nUse [LET](FUNC.LET.md) to name intermediate values within one expression. Use a named LAMBDA to\nreuse a calculation. [MAP](FUNC.MAP.md) applies it to individual array positions; BYROW and BYCOL\npass an entire row or column at a time. VBA functions serve a different purpose when statements\nor interaction with the host are required.\n\n\n",
    "how-to-implement": "\nParse parameter declarations and the body as a binding form. Store a callable containing the\nparameter list, body and lexical environment. Do not evaluate the parameter identifiers as\nordinary arguments when constructing that callable.\n\nOn invocation, check the argument count, create a child scope, bind supplied arguments in order,\nand evaluate the body in that scope. Enclosing `LET` names must remain accessible after the\nouter expression has returned the callable. A reference captured by a body also needs its sheet\nand workbook context; a string containing its displayed address is insufficient.\n\nKeep callable values intact through selectors and helper functions. Apply the cell's display\nrule only when publishing a value to the grid. Guard recursive evaluation with a resource limit;\ntreat that implementation limit separately from a measured Excel recursion boundary.\n\n\n",
    "quirks": "\nAn uncalled `=LAMBDA(x,x+1)` displays `#CALC!` in a cell. The function must remain callable inside\nthe evaluator; replacing it with an error as soon as it is created would break higher-order\nformulas. Cell display and the function value are different concerns.\n\nMicrosoft documents `#VALUE!` for too many parameters or a call with the wrong argument count.\nToo much recursion can produce `#NUM!`; no universal recursion depth is specified here.\n\nA parameter is a name to bind, not a cell to look up while defining the lambda. Use a name such\nas `item` rather than one that Excel recognizes as a cell address. Do not assume that a function\nshown as `#CALC!` has lost its body: a selector can pass a callable on to a later call.\n\n\n",
    "sources": "\n- [Microsoft: LAMBDA function](https://support.microsoft.com/en-us/excel/functions/lambda-function).\n- [The formula call pipeline](../model/03-call-pipeline.md).\n\n",
    "try-it": "\nStart with `=LAMBDA(x,x+1)(4)`. Change the body to `x*x`, or try\n`=LET(offset,10,LAMBDA(x,x+offset)(4))` to explore an enclosing name.\n\n\n",
    "version-differences": "\nMicrosoft lists LAMBDA for Microsoft 365 and Excel 2024 on Windows and Mac. This is product\navailability, not an observation that specific builds evaluate every lambda alike. No comparison\nof recursion boundaries or captured-reference behaviour between named Excel builds is recorded here.\n\n\n",
    "what-it-does": "\n`LAMBDA([parameter1, …], calculation)` defines a function in a formula. Parameters come first;\nthe expression to calculate comes last. Creating the function and calling it are separate steps.\n\n`=LAMBDA(x,x+1)(4)` calls a one-parameter function with 4 and returns 5. Save the definition as a\nworkbook name to call it by that name elsewhere. A lambda can also be passed to `MAP`, `BYROW`,\n`BYCOL`, `REDUCE`, `SCAN` or `MAKEARRAY`.\n\nThe calculation is required. Microsoft allows up to 253 parameters. Parameter names follow\nExcel's naming rules, with no period in a parameter name.\n\n\n"
  },
  "signature": {
    "display": "LAMBDA([parameter1, …], calculation)",
    "max_arguments": 254,
    "min_arguments": 1,
    "parameters": [
      {
        "description": "Zero to 253 parameter names, before the final calculation.",
        "name": "parameter",
        "optional": true,
        "repeats": true
      },
      {
        "description": "The body expression, evaluated when called.",
        "name": "calculation",
        "optional": false,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "formula_layer",
        "reason": null
      },
      "arity": {
        "max": 254,
        "min": 2
      },
      "category": "Logical functions",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "Custom",
        "determinism_class": "Deterministic",
        "fec_dependency_profile": "None",
        "host_interaction_class": "None",
        "kernel_signature_class": "Custom",
        "surface_fec_dependency_profile": "RefOnly",
        "thread_safety_class": "SafePure",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "A function defined in the formula from parameters and a calculation",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Create custom, reusable functions and call them by a friendly name",
        "microsoft_url": "https://support.microsoft.com/en-us/office/lambda-function-bd212d27-1cd1-4321-a34a-ccbf254b8b67"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "LAMBDA"
        },
        {
          "locale": "bg-BG",
          "name": "LAMBDA"
        },
        {
          "locale": "cs-CZ",
          "name": "LAMBDA"
        },
        {
          "locale": "da-DK",
          "name": "LAMBDA"
        },
        {
          "locale": "de-DE",
          "name": "LAMBDA"
        },
        {
          "locale": "el-GR",
          "name": "LAMBDA"
        },
        {
          "locale": "en-AU",
          "name": "LAMBDA"
        },
        {
          "locale": "en-GB",
          "name": "LAMBDA"
        },
        {
          "locale": "en-US",
          "name": "LAMBDA"
        },
        {
          "locale": "es-ES",
          "name": "LAMBDA"
        },
        {
          "locale": "et-EE",
          "name": "LAMBDA"
        },
        {
          "locale": "fi-FI",
          "name": "LAMBDA"
        },
        {
          "locale": "fr-FR",
          "name": "LAMBDA*"
        },
        {
          "locale": "he-IL",
          "name": "LAMBDA"
        },
        {
          "locale": "hr-HR",
          "name": "LAMBDA"
        },
        {
          "locale": "hu-HU",
          "name": "LAMBDA"
        },
        {
          "locale": "id-ID",
          "name": "LAMBDA"
        },
        {
          "locale": "it-IT",
          "name": "LAMBDA"
        },
        {
          "locale": "ja-JP",
          "name": "LAMBDA"
        },
        {
          "locale": "ko-KR",
          "name": "LAMBDA"
        },
        {
          "locale": "lt-LT",
          "name": "LAMBDA"
        },
        {
          "locale": "lv-LV",
          "name": "LAMBDA"
        },
        {
          "locale": "nb-NO",
          "name": "LAMBDA"
        },
        {
          "locale": "nl-NL",
          "name": "LAMBDA"
        },
        {
          "locale": "pl-PL",
          "name": "LAMBDA"
        },
        {
          "locale": "pt-BR",
          "name": "LAMBDA"
        },
        {
          "locale": "pt-PT",
          "name": "LAMBDA"
        },
        {
          "locale": "ro-RO",
          "name": "LAMBDA"
        },
        {
          "locale": "ru-RU",
          "name": "LAMBDA"
        },
        {
          "locale": "sk-SK",
          "name": "LAMBDA"
        },
        {
          "locale": "sl-SI",
          "name": "LAMBDA"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "LAMBDA"
        },
        {
          "locale": "sv-SE",
          "name": "LAMBDA"
        },
        {
          "locale": "th-TH",
          "name": "LAMBDA"
        },
        {
          "locale": "tr-TR",
          "name": "LAMBDA"
        },
        {
          "locale": "uk-UA",
          "name": "LAMBDA"
        },
        {
          "locale": "vi-VN",
          "name": "LAMBDA"
        },
        {
          "locale": "zh-CN",
          "name": "LAMBDA"
        },
        {
          "locale": "zh-HK",
          "name": "LAMBDA"
        },
        {
          "locale": "zh-TW",
          "name": "LAMBDA"
        }
      ],
      "signature": {
        "display": "LAMBDA([parameter1], [parameter2], ..., calculation)",
        "parameters": [
          {
            "description": null,
            "name": "parameter1",
            "optional": true,
            "repeats": false
          },
          {
            "description": null,
            "name": "parameter2",
            "optional": true,
            "repeats": false
          },
          {
            "description": null,
            "name": "...",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "calculation",
            "optional": false,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "LAMBDA",
      "version_marker": null,
      "xlcall": null
    },
    "microsoft": "https://support.microsoft.com/en-us/office/lambda-function-bd212d27-1cd1-4321-a34a-ccbf254b8b67"
  },
  "try_it": {
    "formula": "=LAMBDA(x,x+1)(4)"
  },
  "url": "https://handbook.dnacalc.com/functions/LAMBDA.html",
  "variants": [],
  "versions": []
}