# \#function

**URL:** https://discourse.julialang.org/tag/function/325.md

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

---

## [Manual control of overloading existing methods](https://discourse.julialang.org/t/manual-control-of-overloading-existing-methods/133836)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 19\
**Last updated:** [August 15, 2026, 5:19pm UTC](https://discourse.julialang.org/t/manual-control-of-overloading-existing-methods/133836 "2026-08-15T17:19:25Z")

</div>

I am curious to know how much people want to have a feature/mechanism in Julia to manually control function overloading. Specifically, to disallow overloading already defined methods when intended. One direct motivation…

---

## [The current state of function naming style](https://discourse.julialang.org/t/the-current-state-of-function-naming-style/136849)

<div class="topic-metadata">

**Author:** [@lilachint](https://discourse.julialang.org/u/lilachint)\
**Replies:** 24\
**Last updated:** [May 2, 2026, 3:35am UTC](https://discourse.julialang.org/t/the-current-state-of-function-naming-style/136849 "2026-05-02T03:35:02Z")

</div>

I just came across this reply to a new package announcement. In it, they suggested removing underscores from function names to make them more idiomatic for Julia. The question is, is Julia today still strictly abiding …

---

## [Contradictory nested function performance and allocation](https://discourse.julialang.org/t/contradictory-nested-function-performance-and-allocation/136548)

<div class="topic-metadata">

**Author:** [@lilachint](https://discourse.julialang.org/u/lilachint)\
**Replies:** 2\
**Last updated:** [April 4, 2026, 8:38am UTC](https://discourse.julialang.org/t/contradictory-nested-function-performance-and-allocation/136548 "2026-04-04T08:38:44Z")

</div>

Recently when working on sorting data with Hilbert curves, I noticed something very peculiar when benchmarking. function hilbert\_sort(m::AbstractMatrix{\<:Integer}, b::Integer; rev::Bool = false) return m\[:, hilbert\_…

---

## [FixFunctionArgument.jl: Fix a function positional argument to a callable. Stand-in replacement for Base.Fix](https://discourse.julialang.org/t/fixfunctionargument-jl-fix-a-function-positional-argument-to-a-callable-stand-in-replacement-for-base-fix/132532)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 0\
**Last updated:** [September 21, 2025, 7:45am UTC](https://discourse.julialang.org/t/fixfunctionargument-jl-fix-a-function-positional-argument-to-a-callable-stand-in-replacement-for-base-fix/132532 "2025-09-21T07:45:42Z")

</div>

Suboptimal design in Base.Fix, also applying to Base.Fix1 and Base.Fix2, causes things like Base.Fix1(convert, Bool) to have a greater than zero representation in memory, because Bool isa Type. Fixing this in Base would …

---

## [\[ANN\] EnforcedTypeSignatureCallables.jl](https://discourse.julialang.org/t/ann-enforcedtypesignaturecallables-jl/117280)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 10\
**Last updated:** [September 5, 2025, 12:59pm UTC](https://discourse.julialang.org/t/ann-enforcedtypesignaturecallables-jl/117280 "2025-09-05T12:59:06Z")

</div>

The EnforcedTypeSignatureCallables package is being registered: New package: EnforcedTypeSignatureCallables v1.0.0 by JuliaRegistrator · Pull Request #111416 · JuliaRegistries/General · GitHub Once it’s registered, this…

---

## [Performance discrepancy for different ways of piping/composing functions for handling runtime dispatch](https://discourse.julialang.org/t/performance-discrepancy-for-different-ways-of-piping-composing-functions-for-handling-runtime-dispatch/129773)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 9\
**Last updated:** [June 13, 2025, 4:30am UTC](https://discourse.julialang.org/t/performance-discrepancy-for-different-ways-of-piping-composing-functions-for-handling-runtime-dispatch/129773 "2025-06-13T04:30:29Z")

</div>

MWE (tested on Julia 1.11.5): julia\> foo1(::Val{N}) where {N} = N foo1 (generic function with 1 method) julia\> foo2(n::Int) = Val(n) foo2 (generic function with 1 method) julia\> a = Val.(rand(Int, 1000)); julia\> usin…

---

## [Is it possible to know if a function has captured local variables?](https://discourse.julialang.org/t/is-it-possible-to-know-if-a-function-has-captured-local-variables/128934)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 11\
**Last updated:** [May 13, 2025, 1:40am UTC](https://discourse.julialang.org/t/is-it-possible-to-know-if-a-function-has-captured-local-variables/128934 "2025-05-13T01:40:57Z")

</div>

julia\> a = fill(1) 0-dimensional Array{Int64, 0}: 1 julia\> function foo(b) a\[\] + b end foo (generic function with 1 method) julia\> foo(1) 2 julia\> a\[\] = 2 2 julia\> foo(1) 3 julia\> some\_detector(foo…

---

## [Behaviors of \`deepcopy\` for a function constructed with different ways of referencing a global variable](https://discourse.julialang.org/t/behaviors-of-deepcopy-for-a-function-constructed-with-different-ways-of-referencing-a-global-variable/128939)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 2\
**Last updated:** [May 13, 2025, 1:30am UTC](https://discourse.julialang.org/t/behaviors-of-deepcopy-for-a-function-constructed-with-different-ways-of-referencing-a-global-variable/128939 "2025-05-13T01:30:07Z")

</div>

This discovery stemmed from the reply in another post, but since it’s less relevant to the initial post, I thought I would make a new post dedicated to it. julia\> box = fill(1) 0-dimensional Array{Int64, 0}: 1 julia\> f…

---

## [Difference between vector of functions typed explicitly or via list comprehension](https://discourse.julialang.org/t/difference-between-vector-of-functions-typed-explicitly-or-via-list-comprehension/128671)

<div class="topic-metadata">

**Author:** [@hawahe](https://discourse.julialang.org/u/hawahe)\
**Replies:** 4\
**Last updated:** [May 4, 2025, 10:16am UTC](https://discourse.julialang.org/t/difference-between-vector-of-functions-typed-explicitly-or-via-list-comprehension/128671 "2025-05-04T10:16:51Z")

</div>

Are the following two ways to make a vector of functions equivalent? The latter gives both anonymous functions the name #1 when I expected to see #1 and #2. julia\> Function\[(x) -\> x^2, (x) -\> x^3\] 2-element Vector{Funct…

---

## [Chained keyword assignment in function call leaks scope](https://discourse.julialang.org/t/chained-keyword-assignment-in-function-call-leaks-scope/126531)

<div class="topic-metadata">

**Author:** [@ncxst](https://discourse.julialang.org/u/ncxst)\
**Replies:** 1\
**Last updated:** [March 4, 2025, 3:29pm UTC](https://discourse.julialang.org/t/chained-keyword-assignment-in-function-call-leaks-scope/126531 "2025-03-04T15:29:08Z")

</div>

I tried to do a chained keyword assignment in a function call and got the following behavior julia\> function params(;kwargs...) for kw in kwargs println(kw) end end params (ge…

---

## [Naming convention for functions when an argument is optionally mutated](https://discourse.julialang.org/t/naming-convention-for-functions-when-an-argument-is-optionally-mutated/125180)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 5\
**Last updated:** [January 25, 2025, 4:20am UTC](https://discourse.julialang.org/t/naming-convention-for-functions-when-an-argument-is-optionally-mutated/125180 "2025-01-25T04:20:35Z")

</div>

I have a function f with a signature: f(x, y, cache::Union{T1, T2}) where cache will be mutated (modified) when it’s of type T1 and not mutated when it’s of type T2. The type of cache is determined by the combinations …

---

## [Error at structure initialization](https://discourse.julialang.org/t/error-at-structure-initialization/124893)

<div class="topic-metadata">

**Author:** [@Bogdan\_Virag](https://discourse.julialang.org/u/Bogdan_Virag)\
**Replies:** 1\
**Last updated:** [January 19, 2025, 12:06pm UTC](https://discourse.julialang.org/t/error-at-structure-initialization/124893 "2025-01-19T12:06:26Z")

</div>

Hi! I created a structure for ML (for a generalized linear modell) and i want to store the linking function by initializing the structure using the name of the distribution. The code of the structure: mutable struct G…

---

## [Function arguments](https://discourse.julialang.org/t/function-arguments/61717)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 37\
**Last updated:** [December 20, 2024, 4:56pm UTC](https://discourse.julialang.org/t/function-arguments/61717 "2024-12-20T16:56:59Z")

</div>

Is it possible to pass a named tuple to a function and have the components available as variables without explicitly specifying them as arguments. f( X ) = A + B X = (A=1,B=2) f( X ) output : 3 Background: I have ab…

---

## [Julia incorrect with function argument](https://discourse.julialang.org/t/julia-incorrect-with-function-argument/123520)

<div class="topic-metadata">

**Author:** [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Replies:** 1\
**Last updated:** [December 6, 2024, 12:33am UTC](https://discourse.julialang.org/t/julia-incorrect-with-function-argument/123520 "2024-12-06T00:33:47Z")

</div>

Hi! Please help me to understand whats wrong with julia logic. The following code print out: println(typeof(section)) \>\> CxxWrap.CxxWrapCore.CxxPtr{Main.CppTypes.ISection} I wish to write function which take this (an…

---

## [Return of split](https://discourse.julialang.org/t/return-of-split/122987)

<div class="topic-metadata">

**Author:** [@martin\_sanchez](https://discourse.julialang.org/u/martin_sanchez)\
**Replies:** 6\
**Last updated:** [November 23, 2024, 11:34am UTC](https://discourse.julialang.org/t/return-of-split/122987 "2024-11-23T11:34:21Z")

</div>

I was using split(str,separator) and it returned SubString (I verified it with typeof) and wa using the result in later functions: function instruct\_processor(db::Dict,op::String) arr=split(op," ",limit=2) print…

---

## [Can callable structs subtype Function? Should they?](https://discourse.julialang.org/t/can-callable-structs-subtype-function-should-they/121909)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 10\
**Last updated:** [October 29, 2024, 8:36pm UTC](https://discourse.julialang.org/t/can-callable-structs-subtype-function-should-they/121909 "2024-10-29T20:36:02Z")

</div>

The docstring of Function doesn’t specify any constraints on subtypes, so I’m wondering whether it makes sense to define callable structs (functors) as \<: Function.

---

## [Vectorise summation over index in nested for loop](https://discourse.julialang.org/t/vectorise-summation-over-index-in-nested-for-loop/121158)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 7\
**Last updated:** [October 10, 2024, 11:33pm UTC](https://discourse.julialang.org/t/vectorise-summation-over-index-in-nested-for-loop/121158 "2024-10-10T23:33:32Z")

</div>

Given a function using LinearAlgebra function test(arr1, arr2, arr3, g) return 1 ./ (arr1 .+ arr2 .+ arr3 .+ im\*g) end N1 = 100000; arr1 = range(0,10,N1); N2 = 5000; arr2 = range(0,10,N2); N3 = 5000; arr3 = range…

---

## [Unclear allocations with in-place mutating functions](https://discourse.julialang.org/t/unclear-allocations-with-in-place-mutating-functions/119896)

<div class="topic-metadata">

**Author:** [@fmor](https://discourse.julialang.org/u/fmor)\
**Replies:** 14\
**Last updated:** [September 26, 2024, 6:50pm UTC](https://discourse.julialang.org/t/unclear-allocations-with-in-place-mutating-functions/119896 "2024-09-26T18:50:48Z")

</div>

I am fitting a statistical model and I refactored the code to reduce the allocations it generated. I morally halved them, with respect to the first version, but there are still some unclear sections which I see from runn…

---

## [\`Vector{Function}\` behaves strangely when length is one](https://discourse.julialang.org/t/vector-function-behaves-strangely-when-length-is-one/119197)

<div class="topic-metadata">

**Author:** [@Mikhail\_Kagalenko](https://discourse.julialang.org/u/Mikhail_Kagalenko)\
**Replies:** 3\
**Last updated:** [September 8, 2024, 8:11pm UTC](https://discourse.julialang.org/t/vector-function-behaves-strangely-when-length-is-one/119197 "2024-09-08T20:11:09Z")

</div>

julia\> f(x)=x+1 f (generic function with 1 method) julia\> isa(f, Function) true julia\> typeof(\[f\]) Vector{typeof(f)} (alias for Array{typeof(f), 1}) julia\> f1(x)=x+1 f1 (generic function with 1 method) julia\> typeof(…

---

## [Understanding error "function type in method definition is not a type" for function-like types](https://discourse.julialang.org/t/understanding-error-function-type-in-method-definition-is-not-a-type-for-function-like-types/116105)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 9\
**Last updated:** [July 23, 2024, 5:16pm UTC](https://discourse.julialang.org/t/understanding-error-function-type-in-method-definition-is-not-a-type-for-function-like-types/116105 "2024-07-23T17:16:15Z")

</div>

I don’t understand why the second way to construct a method (dispatched by ::Val{2}) is not allowed: julia\> abstract type MyFunc \<: Function end julia\> struct MyF1 \<: MyFunc end julia\> (f::MyFunc)(::Val{1}) = "method …

---

## [Best way to implement and solve an ODE with a linearized RHS?](https://discourse.julialang.org/t/best-way-to-implement-and-solve-an-ode-with-a-linearized-rhs/117297)

<div class="topic-metadata">

**Author:** [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)\
**Replies:** 2\
**Last updated:** [July 21, 2024, 4:33pm UTC](https://discourse.julialang.org/t/best-way-to-implement-and-solve-an-ode-with-a-linearized-rhs/117297 "2024-07-21T16:33:22Z")

</div>

Say, I have a system \\dot{u} = f(u(t),t). I want to linearize the RHS at u(t\_{n}) and have \\dot{u} = f(u(t\_n),t\_n) + f\_{u}'(u(t\_n),t\_n)\\cdot(u(t)-u(t\_{n})). In terms of DifferentialEquations.jl I can define f(u,p,t) whe…

---

## [Query regarding namespaces when adding a method using a macro](https://discourse.julialang.org/t/query-regarding-namespaces-when-adding-a-method-using-a-macro/115392)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 4\
**Last updated:** [June 10, 2024, 2:07pm UTC](https://discourse.julialang.org/t/query-regarding-namespaces-when-adding-a-method-using-a-macro/115392 "2024-06-10T14:07:24Z")

</div>

I am confused about how namespaces are being applied in the following code, and would appreciate some help. module A using LinearAlgebra abstract type AbsType end struct SubType \<: AbsType end macro newmethod() quo…

---

## [Type Inference Inferring Any for function that returns Float64](https://discourse.julialang.org/t/type-inference-inferring-any-for-function-that-returns-float64/115007)

<div class="topic-metadata">

**Author:** [@BenCichos](https://discourse.julialang.org/u/BenCichos)\
**Replies:** 11\
**Last updated:** [June 1, 2024, 6:21am UTC](https://discourse.julialang.org/t/type-inference-inferring-any-for-function-that-returns-float64/115007 "2024-06-01T06:21:45Z")

</div>

Hello everyone, I am currently trying to code an Optical Ray Tracing package in Julia, and while trying to optimise the code for performance I ran into some issues that the function trace that performs the tracing does a…

---

## [Is there a way to know in advance if a function definition will overwrite a previous one?](https://discourse.julialang.org/t/is-there-a-way-to-know-in-advance-if-a-function-definition-will-overwrite-a-previous-one/114670)

<div class="topic-metadata">

**Author:** [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Replies:** 30\
**Last updated:** [May 25, 2024, 3:00pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-know-in-advance-if-a-function-definition-will-overwrite-a-previous-one/114670 "2024-05-25T15:00:01Z")

</div>

I’d like to know if there is any way to know in advance if this can be done, e.g. say I have f(x::Int) = 3 In pseudo-code I’m trying to do something like m = method overwritten by f(x::Int) = 4 if m !== nothing Ba…

---

## [Proper way to deal with \`Vector{Any}\` when defining a function](https://discourse.julialang.org/t/proper-way-to-deal-with-vector-any-when-defining-a-function/114422)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 12\
**Last updated:** [May 19, 2024, 10:37am UTC](https://discourse.julialang.org/t/proper-way-to-deal-with-vector-any-when-defining-a-function/114422 "2024-05-19T10:37:54Z")

</div>

function catstr(arr::Vector{String}) return reduce(\*, arr) end # Method-1: OK arr = \["hello", "world"\] catstr(arr) # Method-2: Not OK arr = \[\] push!(arr, "hello") push!(arr, "world") catstr(arr) Whose fault? Is th…

---

## [Improper function nesting causes boxing/runtime dispatch?](https://discourse.julialang.org/t/improper-function-nesting-causes-boxing-runtime-dispatch/114307)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 3\
**Last updated:** [May 17, 2024, 7:00am UTC](https://discourse.julialang.org/t/improper-function-nesting-causes-boxing-runtime-dispatch/114307 "2024-05-17T07:00:01Z")

</div>

Note the code example below: struct Radix{N} Radix(n::Integer) = new{n}(); end # Nesting: testfunc! -\> \_add, \_addpositions function testfunc!(array, num, radix) \_add(a, b, ::Radix{2}) = a ⊻ b \_add(a, …

---

## [How to conveniently pass arguments from a function to another?](https://discourse.julialang.org/t/how-to-conveniently-pass-arguments-from-a-function-to-another/114385)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 4\
**Last updated:** [May 17, 2024, 5:31am UTC](https://discourse.julialang.org/t/how-to-conveniently-pass-arguments-from-a-function-to-another/114385 "2024-05-17T05:31:04Z")

</div>

function f(x=1, y=2, z=3; a=1, b=2, c=3) # How do I know if a/b/c is assigned a value? 2 \* g(x, y, z; a=a, b=b, c=c) # Do I have to pass the arguments one by one to g? end function g(x=1, y=2, z=3; a=1, b=2, c=3…

---

## [How to Use Operator Overloading with Optional Arguments in Julia](https://discourse.julialang.org/t/how-to-use-operator-overloading-with-optional-arguments-in-julia/114375)

<div class="topic-metadata">

**Author:** [@Akhil\_Akkapelli](https://discourse.julialang.org/u/Akhil_Akkapelli)\
**Replies:** 2\
**Last updated:** [May 16, 2024, 8:56pm UTC](https://discourse.julialang.org/t/how-to-use-operator-overloading-with-optional-arguments-in-julia/114375 "2024-05-16T20:56:44Z")

</div>

I’m working on a Julia project and I’ve defined a custom function with operator overloading. My function, which I’ve defined using the | operator, initializes a matrix of Box objects with properties derived from a parent…

---

## [Failed optimization with function](https://discourse.julialang.org/t/failed-optimization-with-function/114290)

<div class="topic-metadata">

**Author:** [@nouha941](https://discourse.julialang.org/u/nouha941)\
**Replies:** 4\
**Last updated:** [May 15, 2024, 4:49pm UTC](https://discourse.julialang.org/t/failed-optimization-with-function/114290 "2024-05-15T16:49:53Z")

</div>

Hello everyone, I have a problem with optimizing my function. I keep getting an error. Could you please help me? function optimize\_Cs(Q\_e, PT501, PT401, P\_HP, R\_m, R\_p, Qp, Pe) #calcul initial de Cs Pe = (( ((Q\_…

---

## [Matching any vector in function dispatch](https://discourse.julialang.org/t/matching-any-vector-in-function-dispatch/113075)

<div class="topic-metadata">

**Author:** [@suvayu](https://discourse.julialang.org/u/suvayu)\
**Replies:** 4\
**Last updated:** [April 18, 2024, 8:59am UTC](https://discourse.julialang.org/t/matching-any-vector-in-function-dispatch/113075 "2024-04-18T08:59:19Z")

</div>

I’m having trouble with function dispatch where I want to have two different implementations when the values in a dictionary are vectors or not These work as I would expect: function fn(val::Vector{Any}) @info "fn,…

[Next page](https://discourse.julialang.org/tag/function/325.md?match_all_tags=true&page=1&tags%5B%5D=function)
