# Slurping and splatting in JuMP

**URL:** <https://discourse.julialang.org/t/slurping-and-splatting-in-jump/6892>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 5, 2017, 2:29am UTC](https://discourse.julialang.org/t/slurping-and-splatting-in-jump/6892 "2017-11-05T02:29:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [November 5, 2017, 2:29am UTC](https://discourse.julialang.org/t/slurping-and-splatting-in-jump/6892/1 "2017-11-05T02:29:09Z")

</div>

I need to define a function that takes a large number of arguments. I am trying to follow JuMP documentation:

> All arguments to user-defined functions are scalars, not vectors. To define a function which takes a large number of arguments, you may use the splatting syntax f(x…) = …

So did this, but it does not work:

```julia
m = JuMP.Model(solver=Ipopt.IpoptSolver())
f(x...) = x[1] + x[2]
JuMP.register(m, :f, 2, f, autodiff=true)
JuMP.@variable(m, x[i=1:2], start = 0.)
JuMP.@NLobjective(m, :Min, f(x...) + 100(x[2]-x[1]^2)^2)

```

I also tried different things using setNLobjective and raw expression input, but it also didn’t work.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [November 5, 2017, 3:18am UTC](https://discourse.julialang.org/t/slurping-and-splatting-in-jump/6892/2 "2017-11-05T03:18:06Z")

</div>

I found the answer I was looking for here:

> <https://stackoverflow.com/questions/44710900/juliajump-variable-number-of-arguments-to-function/44711305#44711305>

To gist is to use something like:

```julia
JuMP.setNLobjective(m, :Min, Expr(:call, :myf, x...))

```
