# \#functions

**URL:** https://discourse.julialang.org/tag/functions/613.md

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

---

## [Unfamiliar syntax in function definition: function (arg1::type1)(arg2::type2)](https://discourse.julialang.org/t/unfamiliar-syntax-in-function-definition-function-arg1-type1-arg2-type2/138884)

<div class="topic-metadata">

**Author:** [@ducksoverip](https://discourse.julialang.org/u/ducksoverip)\
**Replies:** 2\
**Last updated:** [August 18, 2026, 2:56am UTC](https://discourse.julialang.org/t/unfamiliar-syntax-in-function-definition-function-arg1-type1-arg2-type2/138884 "2026-08-18T02:56:18Z")

</div>

I’m testing out an unregistered, abandoned package from 2020 (FEDVR.jl) because it looks like it might actually suit my research needs. I dev’d it locally, tossed the old manifest file (so it would use the latest version…

---

## [Coupling finite\`Union\` with \`T\` in \`NTuple{2, T} where {T}\`](https://discourse.julialang.org/t/coupling-finite-union-with-t-in-ntuple-2-t-where-t/133567)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 7\
**Last updated:** [November 11, 2025, 10:48am UTC](https://discourse.julialang.org/t/coupling-finite-union-with-t-in-ntuple-2-t-where-t/133567 "2025-11-11T10:48:15Z")

</div>

We know that for UnionAll of Tuple that uses the same type parameter (e.g., T) for all the element types (in default) requires the element types to be the same concrete type: julia\> f1(a::Tuple{T, T}) where {T\<:Real} = …

---

## [A question about redefining a function in Julia](https://discourse.julialang.org/t/a-question-about-redefining-a-function-in-julia/133579)

<div class="topic-metadata">

**Author:** [@quantum2025](https://discourse.julialang.org/u/quantum2025)\
**Replies:** 37\
**Last updated:** [November 3, 2025, 5:51pm UTC](https://discourse.julialang.org/t/a-question-about-redefining-a-function-in-julia/133579 "2025-11-03T17:51:42Z")

</div>

Hello. I just tested the following small code on Julia, and found that the value g() is changed after redefining the function f, but c is unchanged. I was wondering the reason behind this difference, and how to keep g() …

---

## [Function to determine number of parameters in a differential equation model function](https://discourse.julialang.org/t/function-to-determine-number-of-parameters-in-a-differential-equation-model-function/132377)

<div class="topic-metadata">

**Author:** [@macmy048](https://discourse.julialang.org/u/macmy048)\
**Replies:** 2\
**Last updated:** [September 15, 2025, 3:48pm UTC](https://discourse.julialang.org/t/function-to-determine-number-of-parameters-in-a-differential-equation-model-function/132377 "2025-09-15T15:48:19Z")

</div>

I want a function to determine the number of parameters in a differential equation model but I’ve been unable to figure out what function I’m looking for. Here’s a MWE (differential equation from this example) where cou…

---

## [Scope in functions](https://discourse.julialang.org/t/scope-in-functions/22096)

<div class="topic-metadata">

**Author:** [@alee](https://discourse.julialang.org/u/alee)\
**Replies:** 13\
**Last updated:** [May 17, 2025, 4:28am UTC](https://discourse.julialang.org/t/scope-in-functions/22096 "2025-05-17T04:28:40Z")

</div>

One of my collaborators found the following behaviour confusing. function foo() function bar() x = 3 return x end x = 1 bar() return x end foo() which outputs 3 (and not 1). This behaviour is differe…

---

## [Functionality like the SAVE statement in Fortran?](https://discourse.julialang.org/t/functionality-like-the-save-statement-in-fortran/127268)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 30\
**Last updated:** [March 25, 2025, 2:37pm UTC](https://discourse.julialang.org/t/functionality-like-the-save-statement-in-fortran/127268 "2025-03-25T14:37:38Z")

</div>

I am converting some Fortran code to Julia, and I noticed the fortran code uses the SAVE statement (SAVE (FORTRAN 77 Language Reference)). I have very little experience in Fortran, but it seems like this statement allow…

---

## [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…

---

## [Creating the instance of a function type](https://discourse.julialang.org/t/creating-the-instance-of-a-function-type/122355)

<div class="topic-metadata">

**Author:** [@brainandforce](https://discourse.julialang.org/u/brainandforce)\
**Replies:** 13\
**Last updated:** [November 7, 2024, 3:53pm UTC](https://discourse.julialang.org/t/creating-the-instance-of-a-function-type/122355 "2024-11-07T15:53:41Z")

</div>

The type of a standard Julia function f is typeof(f), which is a singleton. julia\> function f end f (generic function with 0 methods) julia\> typeof(f) typeof(f) (singleton type of function f, subtype of Function) But …

---

## [Create a more unified syntax for requesting a specific return type of functions?](https://discourse.julialang.org/t/create-a-more-unified-syntax-for-requesting-a-specific-return-type-of-functions/122067)

<div class="topic-metadata">

**Author:** [@stephancb](https://discourse.julialang.org/u/stephancb)\
**Replies:** 18\
**Last updated:** [November 1, 2024, 3:33pm UTC](https://discourse.julialang.org/t/create-a-more-unified-syntax-for-requesting-a-specific-return-type-of-functions/122067 "2024-11-01T15:33:19Z")

</div>

round(1.1) --\> 1.0 round(Int, 1.1) --\> 1 works, but not sqrt(Complex, -1) acos(Complex, 1.1) ... and other inverse trigonometric functions where the real domain is limited. In these cases the desired result is obtaina…

---

## [Intellisense not working with kwargs](https://discourse.julialang.org/t/intellisense-not-working-with-kwargs/120808)

<div class="topic-metadata">

**Author:** [@Farouk](https://discourse.julialang.org/u/Farouk)\
**Replies:** 0\
**Last updated:** [October 2, 2024, 10:09am UTC](https://discourse.julialang.org/t/intellisense-not-working-with-kwargs/120808 "2024-10-02T10:09:50Z")

</div>

Hi everyone, I am using VS Code (windows 10) with the Julia extension, however I have a problem with code auto completion. As you can see in the first image, when I enter the positional arguments IntelliSense works fine …

---

## [How can you call a function inside a taylor model function for reachability analysis?](https://discourse.julialang.org/t/how-can-you-call-a-function-inside-a-taylor-model-function-for-reachability-analysis/119945)

<div class="topic-metadata">

**Author:** [@Muhammad\_Arsal](https://discourse.julialang.org/u/Muhammad_Arsal)\
**Replies:** 2\
**Last updated:** [September 29, 2024, 9:46am UTC](https://discourse.julialang.org/t/how-can-you-call-a-function-inside-a-taylor-model-function-for-reachability-analysis/119945 "2024-09-29T09:46:12Z")

</div>

I am using Jupyter Notebook. And I have a grid interploation function. Which gives me the value of a variable based upon the data of other two. But the problem is when I try to run reachability analysis, it starts throwi…

---

## [Tidiest way to reuse variables inside a function to reduce gc time](https://discourse.julialang.org/t/tidiest-way-to-reuse-variables-inside-a-function-to-reduce-gc-time/119509)

<div class="topic-metadata">

**Author:** [@fmor](https://discourse.julialang.org/u/fmor)\
**Replies:** 8\
**Last updated:** [September 18, 2024, 9:09am UTC](https://discourse.julialang.org/t/tidiest-way-to-reuse-variables-inside-a-function-to-reduce-gc-time/119509 "2024-09-18T09:09:22Z")

</div>

I’m writing a function to fit a spatio-temporal model for clustering. At each iteration it has to compute spatial cohesions on subsets of units, and I saw that this takes a lot of the execution time, which is spent in ga…

---

## [Function property differs based on the position of the generic type](https://discourse.julialang.org/t/function-property-differs-based-on-the-position-of-the-generic-type/119340)

<div class="topic-metadata">

**Author:** [@akrishnamoorthy](https://discourse.julialang.org/u/akrishnamoorthy)\
**Replies:** 2\
**Last updated:** [September 12, 2024, 6:08pm UTC](https://discourse.julialang.org/t/function-property-differs-based-on-the-position-of-the-generic-type/119340 "2024-09-12T18:08:58Z")

</div>

Let julia\> using LinearAlgebra julia\> id(X,T) = T(Matrix{eltype(X)}(I, size(X)...)) id (generic function with 1 method) julia\> A = complex.(randn(2,2),randn(2,2)); julia\> typeof(transpose(id(A,Hermitian))) Transpose{…

---

## [Inline functions with default parameters](https://discourse.julialang.org/t/inline-functions-with-default-parameters/118548)

<div class="topic-metadata">

**Author:** [@martin\_sanchez](https://discourse.julialang.org/u/martin_sanchez)\
**Replies:** 6\
**Last updated:** [August 24, 2024, 1:58pm UTC](https://discourse.julialang.org/t/inline-functions-with-default-parameters/118548 "2024-08-24T13:58:06Z")

</div>

I have a doubt about default arguments. In the Functions documentation it says that I can use optional arguments aswell as defining a function with a simplyfied syntax of y(x)=x\*\*2, but can’t I have such a function with…

---

## [Converting a multivariate function to a single variate function](https://discourse.julialang.org/t/converting-a-multivariate-function-to-a-single-variate-function/21661)

<div class="topic-metadata">

**Author:** [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Replies:** 14\
**Last updated:** [August 13, 2024, 12:57pm UTC](https://discourse.julialang.org/t/converting-a-multivariate-function-to-a-single-variate-function/21661 "2024-08-13T12:57:05Z")

</div>

I want to convert a multivariate function into a single variable function. Aka to perform partial differentiation. While my attempt works but it is such an ugly kludge. Is there a better way of doing this? func1(x,y) = …

---

## [Function with argument of generic parametric type, and another argument subtyping the parameter](https://discourse.julialang.org/t/function-with-argument-of-generic-parametric-type-and-another-argument-subtyping-the-parameter/117813)

<div class="topic-metadata">

**Author:** [@Oblomov](https://discourse.julialang.org/u/Oblomov)\
**Replies:** 1\
**Last updated:** [August 4, 2024, 4:30pm UTC](https://discourse.julialang.org/t/function-with-argument-of-generic-parametric-type-and-another-argument-subtyping-the-parameter/117813 "2024-08-04T16:30:14Z")

</div>

Hello all, I’m still trying to understand how generic type dependencies work in Julia. As a follow-up to my question here, I would like to have a dyadic function f(a, b) with the following conditions: a should be a ve…

---

## [Understanding generic functions and parametric types](https://discourse.julialang.org/t/understanding-generic-functions-and-parametric-types/117810)

<div class="topic-metadata">

**Author:** [@Oblomov](https://discourse.julialang.org/u/Oblomov)\
**Replies:** 3\
**Last updated:** [August 4, 2024, 3:58pm UTC](https://discourse.julialang.org/t/understanding-generic-functions-and-parametric-types/117810 "2024-08-04T15:58:15Z")

</div>

Hello all, I’m new to Julia and I’m trying to understand how type deduction works for generic functions with parametric types. To test my hands at things, I tried to define a function that takes one argument that should…

---

## [Can I restrict access to module functions?](https://discourse.julialang.org/t/can-i-restrict-access-to-module-functions/115830)

<div class="topic-metadata">

**Author:** [@martin\_sanchez](https://discourse.julialang.org/u/martin_sanchez)\
**Replies:** 6\
**Last updated:** [July 13, 2024, 4:17pm UTC](https://discourse.julialang.org/t/can-i-restrict-access-to-module-functions/115830 "2024-07-13T16:17:27Z")

</div>

Hi, I am trying to develop a set of automated workshops for students to follow (similar to the ones you access in Coursera or similar). I was wondering if I can (by design, something similar to oop) mask or restrict acce…

---

## [How to pass variables to several levels up without going through headings (arguments) in functions](https://discourse.julialang.org/t/how-to-pass-variables-to-several-levels-up-without-going-through-headings-arguments-in-functions/112582)

<div class="topic-metadata">

**Author:** [@fmontans](https://discourse.julialang.org/u/fmontans)\
**Replies:** 24\
**Last updated:** [April 6, 2024, 12:28pm UTC](https://discourse.julialang.org/t/how-to-pass-variables-to-several-levels-up-without-going-through-headings-arguments-in-functions/112582 "2024-04-06T12:28:46Z")

</div>

In fortran90, there are two ways to pass variables that is not through the function/subroutine heading/arguments. Those are common blocks (old Fortran77 style) or modules (new fortran90 style). This is extremely useful i…

---

## [What is the difference between a variable that contains a function an a function?](https://discourse.julialang.org/t/what-is-the-difference-between-a-variable-that-contains-a-function-an-a-function/111652)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 4\
**Last updated:** [March 15, 2024, 9:44am UTC](https://discourse.julialang.org/t/what-is-the-difference-between-a-variable-that-contains-a-function-an-a-function/111652 "2024-03-15T09:44:11Z")

</div>

Why is there a difference between f = x-\>5 and f(x) = 5 Why does the compiler treat these differently? Since if you run both of the above you get ERROR: cannot define function f; it already has a value But they bo…

---

## [Issue with Wildcard Import in Julia Module](https://discourse.julialang.org/t/issue-with-wildcard-import-in-julia-module/111613)

<div class="topic-metadata">

**Author:** [@Daniel\_S](https://discourse.julialang.org/u/Daniel_S)\
**Replies:** 4\
**Last updated:** [March 14, 2024, 2:23pm UTC](https://discourse.julialang.org/t/issue-with-wildcard-import-in-julia-module/111613 "2024-03-14T14:23:15Z")

</div>

I’m encountering an issue with wildcard imports (“import .ModuleName: \*”) in Julia. Specifically, when attempting to import all symbols from a module using the wildcard syntax, the symbols do not seem to be available in …

---

## [Calling functions from another script](https://discourse.julialang.org/t/calling-functions-from-another-script/109978)

<div class="topic-metadata">

**Author:** [@Mishal](https://discourse.julialang.org/u/Mishal)\
**Replies:** 2\
**Last updated:** [February 9, 2024, 2:58pm UTC](https://discourse.julialang.org/t/calling-functions-from-another-script/109978 "2024-02-09T14:58:11Z")

</div>

Hi Guys I am currently converting my FEM toolbox I made on Matlab to Julia. I am having issues calling functions from other scripts. the function is: function assembly(q, T, ke, npe, dof, n) # Create a blank globa…

---

## [Defining a function that modifies its argument in place defines a new function instead](https://discourse.julialang.org/t/defining-a-function-that-modifies-its-argument-in-place-defines-a-new-function-instead/109462)

<div class="topic-metadata">

**Author:** [@keynescoefen](https://discourse.julialang.org/u/keynescoefen)\
**Replies:** 2\
**Last updated:** [January 30, 2024, 5:42pm UTC](https://discourse.julialang.org/t/defining-a-function-that-modifies-its-argument-in-place-defines-a-new-function-instead/109462 "2024-01-30T17:42:33Z")

</div>

Hello! I have the following function using SpecialFunctions function CDFFoldedNormal(x,μ,σ) #follow the example: https://en.wikipedia.org/wiki/Folded\_normal\_distribution #Note that the folded normal is NOT the h…

---

## [Check if function accepts specific keyword argument](https://discourse.julialang.org/t/check-if-function-accepts-specific-keyword-argument/108605)

<div class="topic-metadata">

**Author:** [@sandyspiers](https://discourse.julialang.org/u/sandyspiers)\
**Replies:** 3\
**Last updated:** [January 10, 2024, 7:06am UTC](https://discourse.julialang.org/t/check-if-function-accepts-specific-keyword-argument/108605 "2024-01-10T07:06:15Z")

</div>

Suppose I have julia\> f(;y=1) = y f (generic function with 1 method) If I want to check whether f accepts y as a keyword argument I can do julia\> hasmethod(f, Tuple{}, (:y,)) true But this requires knowing the number…

---

## [How to apply an in-place function to a slice of a vector?](https://discourse.julialang.org/t/how-to-apply-an-in-place-function-to-a-slice-of-a-vector/108520)

<div class="topic-metadata">

**Author:** [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)\
**Replies:** 11\
**Last updated:** [January 9, 2024, 11:02am UTC](https://discourse.julialang.org/t/how-to-apply-an-in-place-function-to-a-slice-of-a-vector/108520 "2024-01-09T11:02:07Z")

</div>

I want to have an in-place function that takes a vector as an argument and applies another in-place function to a subarray (in general sense). How do I do this? function f!(du, u) println("\\nf called") @show u …

---

## [How to delete a function?](https://discourse.julialang.org/t/how-to-delete-a-function/108422)

<div class="topic-metadata">

**Author:** [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Replies:** 7\
**Last updated:** [January 8, 2024, 1:47pm UTC](https://discourse.julialang.org/t/how-to-delete-a-function/108422 "2024-01-08T13:47:15Z")

</div>

I want to experiment with a small function. Before defining it, I want to make sure that the function name is not used before, or it does not exist in the workspace. How can I do it? In Matlab, it is simple with ‘clear’ …

---

## [Mutating arrays inside function](https://discourse.julialang.org/t/mutating-arrays-inside-function/108431)

<div class="topic-metadata">

**Author:** [@pratikvn](https://discourse.julialang.org/u/pratikvn)\
**Replies:** 13\
**Last updated:** [January 8, 2024, 6:30am UTC](https://discourse.julialang.org/t/mutating-arrays-inside-function/108431 "2024-01-08T06:30:09Z")

</div>

Hello, I am new to Julia and just trying out things and ran into something that I found unintuitive and wanted to understand the canonical way. Basically, I am trying to pass in an array to a function and have the func…

---

## [Create a function as a attribute to a struct](https://discourse.julialang.org/t/create-a-function-as-a-attribute-to-a-struct/107817)

<div class="topic-metadata">

**Author:** [@Maddy](https://discourse.julialang.org/u/Maddy)\
**Replies:** 5\
**Last updated:** [December 19, 2023, 4:44pm UTC](https://discourse.julialang.org/t/create-a-function-as-a-attribute-to-a-struct/107817 "2023-12-19T16:44:20Z")

</div>

I want to create a clock object with the attributes clock.initial, clock.current and clock.elapsed. I now want functions like initialize, update, play and pause. Is there a way to have something like clock.initialize(…

---

## [Any way to multiple dispatch on functions?\`](https://discourse.julialang.org/t/any-way-to-multiple-dispatch-on-functions/107318)

<div class="topic-metadata">

**Author:** [@Jad\_Zeitouni](https://discourse.julialang.org/u/Jad_Zeitouni)\
**Replies:** 7\
**Last updated:** [December 8, 2023, 9:50am UTC](https://discourse.julialang.org/t/any-way-to-multiple-dispatch-on-functions/107318 "2023-12-08T09:50:01Z")

</div>

I defined two abstract types, call them MyType and MyFrozenType{T\<:MyType}. Subtypes SpecificFrozenType \<: MyFrozenStruct{SpecificType} are usually defined as SpecificFrozenType(x::SpecificType, v::Vector) Now, I have …

---

## [How can I give a function to eigs() in julia like matlab](https://discourse.julialang.org/t/how-can-i-give-a-function-to-eigs-in-julia-like-matlab/105699)

<div class="topic-metadata">

**Author:** [@Meteoooor](https://discourse.julialang.org/u/Meteoooor)\
**Replies:** 6\
**Last updated:** [November 3, 2023, 7:57am UTC](https://discourse.julialang.org/t/how-can-i-give-a-function-to-eigs-in-julia-like-matlab/105699 "2023-11-03T07:57:05Z")

</div>

I have the following matlab code: function \[ DomRVec, DomEig, Error \] = MyEigs( Tup, Tdn, NumofValue, SpeString, Dbond, Dspin, InitVec ) VecDim = Dbond^2; Tup = reshape( permute( Tup, \[ 1, 3, 2 \] ), \[ Dbond \* Dspin, D…

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