# Memoize a vararg function

**URL:** <https://discourse.julialang.org/t/memoize-a-vararg-function/11151>\
**Category:** General Usage\
**Tags:** bug, memoize\
**Created:** [May 25, 2018, 6:40pm UTC](https://discourse.julialang.org/t/memoize-a-vararg-function/11151 "2018-05-25T18:40:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmouts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gmouts/32/9896_2.png) [@gmouts](https://discourse.julialang.org/u/gmouts)\
**Post date:** [May 25, 2018, 6:40pm UTC](https://discourse.julialang.org/t/memoize-a-vararg-function/11151/1 "2018-05-25T18:40:49Z")

</div>

I tried to use Memoize.jl fro a vararg function. The following code

```julia
@memoize function test(lst::Vararg{Int})
    return length(lst)
end

test(1,2)

```

gives

`TypeError: test: in typeassert, expected Vararg{Int64,N} where N, got Tuple{Int64,Int64}`

I flagged it as bug but I am not sure if it is actually. It seems that since `Tuple{Int64,Int64}` is not a subtype of `Vararg{Int64,N} where N` the macro cannot work, but I don’t know whether trying to fix that will break something else.

Anyway, is it possible to memoize such functions at the moment? Will this be fixed in the future?

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [May 25, 2018, 6:48pm UTC](https://discourse.julialang.org/t/memoize-a-vararg-function/11151/2 "2018-05-25T18:48:50Z")

</div>

This seems like a bug, it really ought to check against `NTuple{N,Int}` wherever it’s doing that. For the hell of it, you might try my package [Anamnesis.jl](https://github.com/ExpandingMan/Anamnesis.jl) and see if you get the same error, though to be honest I’m not quite sure if I supported that.

I never registered Anamnesis so you’d have to clone it.

You might also try doing

```julia
@memoize function test(lst::Int...) = length(lst)

```

it shouldn’t make a difference but might be worth a shot.

---

<div class="post-metadata">

**Author:** ![gmouts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gmouts/32/9896_2.png) [@gmouts](https://discourse.julialang.org/u/gmouts)\
**Post date:** [May 26, 2018, 4:03am UTC](https://discourse.julialang.org/t/memoize-a-vararg-function/11151/3 "2018-05-26T04:03:52Z")

</div>

After I clone it, how do I tell Julia to use it?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [May 26, 2018, 5:26am UTC](https://discourse.julialang.org/t/memoize-a-vararg-function/11151/4 "2018-05-26T05:26:58Z")

</div>

Same way as with any other package.

```julia
Pkg.clone("https://github.com/ExpandingMan/Anamnesis.jl")
using Anamnesis

```
