# Using varargs

**URL:** <https://discourse.julialang.org/t/using-varargs/25747>\
**Category:** New to Julia\
**Created:** [June 26, 2019, 9:15pm UTC](https://discourse.julialang.org/t/using-varargs/25747 "2019-06-26T21:15:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stu/32/8772_2.png) [@stu](https://discourse.julialang.org/u/stu)\
**Post date:** [June 26, 2019, 9:15pm UTC](https://discourse.julialang.org/t/using-varargs/25747/1 "2019-06-26T21:15:16Z")

</div>

I have the following code:

```julia
circ(x) = x./sqrt(sum(x .* x))

x -> cat(circ(x), circ(x); dims = 1)

```

but I want to be able to create a function where I input a number and it concatenates that number of circ(x)s.

so for example:

```julia
function Ncircs(n)
  #some way to make cat() have as its parameter circ n number of times
end

```

and I could call `Ncircs(2)` and get  
`x -> cat(circ(x), circ(x); dims = 1)`  
or `Ncircs(3)` and get  
`x -> cat(circ(x), circ(x), circ(x); dims = 1)`  
or `Ncircs(4)` and get  
`x -> cat(circ(x), circ(x), circ(x), circ(x); dims = 1)`

etc.

Is there a way of doing this? Do I have to use a macro?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [June 26, 2019, 9:27pm UTC](https://discourse.julialang.org/t/using-varargs/25747/2 "2019-06-26T21:27:58Z")

</div>

You can just return `x -> repeat(circ(x), n)`. Any reason you specifically specify `dims`? Is `x` not a regular `Vector`?

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [June 26, 2019, 9:34pm UTC](https://discourse.julialang.org/t/using-varargs/25747/3 "2019-06-26T21:34:19Z")

</div>

Also note the availability of the `LinearAlgebra.normalize` function, which does the same thing as `circ`.

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stu/32/8772_2.png) [@stu](https://discourse.julialang.org/u/stu)\
**Post date:** [June 27, 2019, 3:00pm UTC](https://discourse.julialang.org/t/using-varargs/25747/4 "2019-06-27T15:00:58Z")

</div>

> [@simeonschaub](#):
>
> repeat(circ(x), n)

When I try using repeat, I get the following error

> LoadError: MethodError: no method matching Float32(::Tracker.TrackedReal{Float32})

but if I do

```julia
reduce(vcat, Iterators.repeated(circ(x), n))

```

it works fine, the only issue is that reduce does not work if I want to sometimes be able to pass in zero for n

How could I address this?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [June 27, 2019, 3:30pm UTC](https://discourse.julialang.org/t/using-varargs/25747/5 "2019-06-27T15:30:01Z")

</div>

Could you provide a minimal working example of what exactly you are trying to do, otherwise people can’t really help you?

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stu/32/8772_2.png) [@stu](https://discourse.julialang.org/u/stu)\
**Post date:** [June 28, 2019, 8:26pm UTC](https://discourse.julialang.org/t/using-varargs/25747/6 "2019-06-28T20:26:29Z")

</div>

I was able to address it by simply using a special case if clause for n being zero where it just did nothing as I wanted it to.
