# Anonymous Functions

**URL:** <https://discourse.julialang.org/t/anonymous-functions/87106>\
**Category:** New to Julia\
**Created:** [September 12, 2022, 3:01am UTC](https://discourse.julialang.org/t/anonymous-functions/87106 "2022-09-12T03:01:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoshi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoshi/32/38259_2.png) [@yoshi](https://discourse.julialang.org/u/yoshi)\
**Post date:** [September 12, 2022, 3:01am UTC](https://discourse.julialang.org/t/anonymous-functions/87106/1 "2022-09-12T03:01:23Z")

</div>

There’s a block of code example that I’m trying to understand [here](https://github.com/SciML/DiffEqGPU.jl):

```julia
using DiffEqGPU, OrdinaryDiffEq
function lorenz(du,u,p,t)
    du[1] = p[1]*(u[2]-u[1])
    du[2] = u[1]*(p[2]-u[3]) - u[2]
    du[3] = u[1]*u[2] - p[3]*u[3]
end

u0 = Float32[1.0;0.0;0.0]
tspan = (0.0f0,100.0f0)
p = [10.0f0,28.0f0,8/3f0]
prob = ODEProblem(lorenz,u0,tspan,p)
prob_func = (prob,i,repeat) -> remake(prob,p=rand(Float32,3).*p)

```

I’m having trouble interpreting the syntax for prob\_func. I think its an anonymous function that is feeding (prob, i, repeat) into ODEproblem. But i is undefined and repeat is a function in julia – how are these being used by remake?

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [September 12, 2022, 5:19am UTC](https://discourse.julialang.org/t/anonymous-functions/87106/2 "2022-09-12T05:19:50Z")

</div>

Yes, the syntax `(prob,i,repeat) -> remake(prob,p=rand(Float32,3).*p)` defines an anonymous function which takes three parameters, `prob`, `i` and `repeat` and uses only the first one of the three. The anonymous function is then bound to the name `prob_func` and you may as well have defined it directly as `prob_func(prob,i,repeat) = remake(prob,p=rand(Float32,3).*p)`.

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [September 12, 2022, 8:42am UTC](https://discourse.julialang.org/t/anonymous-functions/87106/3 "2022-09-12T08:42:02Z")

</div>

> [@yoshi](#):
>
> But i is undefined and repeat is a function in julia – how are these being used by remake?

`i` is a parameter to the function, so it doesn’t have to be already defined - just like `du` and `u` in `lorenz` function’s definition don’t have to already exist. They get assigned values when they’re called.

As for `repeat`, within the context of this function, it gets defined to be the argument value instead. Globally, `repeat` still refers to the function `Base.repeat`, but in this local scope, `repeat` instead refers only to the argument that was passed in.
