# \#anonymous-function

**URL:** https://discourse.julialang.org/tag/anonymous-function/1214.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Closures magic and how stable?](https://discourse.julialang.org/t/closures-magic-and-how-stable/135408)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 7\
**Last updated:** [February 2, 2026, 4:53pm UTC](https://discourse.julialang.org/t/closures-magic-and-how-stable/135408 "2026-02-02T16:53:47Z")

</div>

There is a feature in Julia that has enabled us to do some magical things. It is all thanks to this: julia\> adder(f, a) = ()-\> f() + a adder (generic function with 1 method) julia\> f = ()-\>5 #3 (generic function with 1…

---

## [Weird bug that shouldn't happen; Cannot declare anonymous.#XX#XX constant; it already has a value](https://discourse.julialang.org/t/weird-bug-that-shouldnt-happen-cannot-declare-anonymous-xx-xx-constant-it-already-has-a-value/133989)

<div class="topic-metadata">

**Author:** [@Qfl3x](https://discourse.julialang.org/u/Qfl3x)\
**Replies:** 2\
**Last updated:** [November 19, 2025, 2:58pm UTC](https://discourse.julialang.org/t/weird-bug-that-shouldnt-happen-cannot-declare-anonymous-xx-xx-constant-it-already-has-a-value/133989 "2025-11-19T14:58:28Z")

</div>

I was just playing around in Infiltrator and stumbled on this: Shouldn’t this be impossible? I have 2 other anonymous functions used in the script. Probably dozens if not hundreds in the packages I’m using. Couldn’…

---

## [Type instability seemingly due to redundant inner functions that are never called](https://discourse.julialang.org/t/type-instability-seemingly-due-to-redundant-inner-functions-that-are-never-called/133227)

<div class="topic-metadata">

**Author:** [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Replies:** 5\
**Last updated:** [October 18, 2025, 5:27pm UTC](https://discourse.julialang.org/t/type-instability-seemingly-due-to-redundant-inner-functions-that-are-never-called/133227 "2025-10-18T17:27:26Z")

</div>

I have created an MWE that can readily executed by copy-pasting to the REPL, provided package DispatchDoctor.jl is installed. What follows below is: A variable Z is created in global scope (see end of script below). …

---

## [Overloading anonymous functions](https://discourse.julialang.org/t/overloading-anonymous-functions/132823)

<div class="topic-metadata">

**Author:** [@AntonReinhard](https://discourse.julialang.org/u/AntonReinhard)\
**Replies:** 9\
**Last updated:** [October 3, 2025, 11:32am UTC](https://discourse.julialang.org/t/overloading-anonymous-functions/132823 "2025-10-03T11:32:20Z")

</div>

I was playing around with anonymous functions a bit and found that you can use where clauses with them, if you wrap the header in brackets: julia\> ((x::T) where {T\<:Int}) -\> x #11 (generic function with 1 method) julia\>…

---

## [Anonymous Functions and Overwriting Arguments](https://discourse.julialang.org/t/anonymous-functions-and-overwriting-arguments/127586)

<div class="topic-metadata">

**Author:** [@phK3](https://discourse.julialang.org/u/phK3)\
**Replies:** 7\
**Last updated:** [April 3, 2025, 4:41am UTC](https://discourse.julialang.org/t/anonymous-functions-and-overwriting-arguments/127586 "2025-04-03T04:41:38Z")

</div>

I’ve stumbled upon the following (in my mind) weird behavior: If you define a named function that returns a function f1 based on a parameter a, the returned function stays the same, even if a gets assigned another value…

---

## [How to apply a small anonymous function defined in a yaml file?](https://discourse.julialang.org/t/how-to-apply-a-small-anonymous-function-defined-in-a-yaml-file/126874)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 11\
**Last updated:** [March 13, 2025, 12:20pm UTC](https://discourse.julialang.org/t/how-to-apply-a-small-anonymous-function-defined-in-a-yaml-file/126874 "2025-03-13T12:20:12Z")

</div>

I am trying to define simple anonimous “transformation” functions (something like “x → x/100”) in a yaml file (in a dictionary keyed by climatic variables) and then trying to apply the transformation to a Raster file. I …

---

## [Use of anonymous functions has high compilation time](https://discourse.julialang.org/t/use-of-anonymous-functions-has-high-compilation-time/125923)

<div class="topic-metadata">

**Author:** [@thomasc791](https://discourse.julialang.org/u/thomasc791)\
**Replies:** 3\
**Last updated:** [February 14, 2025, 10:17pm UTC](https://discourse.julialang.org/t/use-of-anonymous-functions-has-high-compilation-time/125923 "2025-02-14T22:17:58Z")

</div>

Hi everyone, I am currently struggling with the usage of anonymous functions. I have a function dirichlet! that takes a function as one of its inputs. The function returns a value based on the position x. function diri…

---

## [BoundsError -\> NaN ? (in Interpolations)](https://discourse.julialang.org/t/boundserror-nan-in-interpolations/110372)

<div class="topic-metadata">

**Author:** [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Replies:** 2\
**Last updated:** [February 19, 2024, 5:40am UTC](https://discourse.julialang.org/t/boundserror-nan-in-interpolations/110372 "2024-02-19T05:40:03Z")

</div>

I need a NaN when the target isn’t in the “interior” in linear interpolation: using Distributions using Interpolations const imax\_in = 20 const imax\_out = 20 xax\_in, v\_in = let dx = rand(Uniform(1.0, 10.0), imax\_in)…

---

## [Bad performance of anonymous functions even when they are type-stable](https://discourse.julialang.org/t/bad-performance-of-anonymous-functions-even-when-they-are-type-stable/108173)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 2\
**Last updated:** [December 30, 2023, 6:56am UTC](https://discourse.julialang.org/t/bad-performance-of-anonymous-functions-even-when-they-are-type-stable/108173 "2023-12-30T06:56:46Z")

</div>

MWE: julia\> f1 = function (x) x/2 end #3 (generic function with 1 method) julia\> function f1\_2(x) x/2 end f1\_2 (generic function with 1 method) julia\> f2 = function (x) …

---

## [Trying to understand how lazy computation works](https://discourse.julialang.org/t/trying-to-understand-how-lazy-computation-works/98871)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 6\
**Last updated:** [May 15, 2023, 2:34pm UTC](https://discourse.julialang.org/t/trying-to-understand-how-lazy-computation-works/98871 "2023-05-15T14:34:57Z")

</div>

Trying to understand the following argument A zero-argument anonymous function is written as ()-\>3. The idea of a function with no arguments may seem strange, but is useful for “delaying” a computation. In this usage, …

---

## [Performant Recursive Anonymous Functions](https://discourse.julialang.org/t/performant-recursive-anonymous-functions/90984)

<div class="topic-metadata">

**Author:** [@uniment](https://discourse.julialang.org/u/uniment)\
**Replies:** 23\
**Last updated:** [November 30, 2022, 11:01pm UTC](https://discourse.julialang.org/t/performant-recursive-anonymous-functions/90984 "2022-11-30T23:01:28Z")

</div>

What’s the preferred way to write recursive anonymous functions? Consider a demo function: julia\> function fib(n) n ≤ 1 && return n return fib(n-1) + fib(n-2) end fib (generic function with…
