# Unrolled.jl – problems with "where" keyword

**URL:** <https://discourse.julialang.org/t/unrolled-jl-problems-with-where-keyword/9715>\
**Category:** General Usage\
**Tags:** unrolling\
**Created:** [March 14, 2018, 12:33pm UTC](https://discourse.julialang.org/t/unrolled-jl-problems-with-where-keyword/9715 "2018-03-14T12:33:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lhupe](https://avatars.discourse-cdn.com/v4/letter/l/9fc348/32.png) [@lhupe](https://discourse.julialang.org/u/lhupe)\
**Post date:** [March 14, 2018, 12:33pm UTC](https://discourse.julialang.org/t/unrolled-jl-problems-with-where-keyword/9715/1 "2018-03-14T12:33:21Z")

</div>

I have a function that takes an `SVector` of some type, i.e.

```julia
function foo(vec::SVector{2,T}) where T
    for x in vec
        #do something with x
    end
end

```

and want to use [`Unrolled.jl`](https://github.com/cstjean/Unrolled.jl) on it. However, when I add the `@unroll` macro like this

```julia
@unroll function foo(vec::SVector{2,T}) where T
    @unroll for x in vec
        #do something with x
    end
end

```

I get an error message: `LoadError: AssertionError: `@unroll` must precede a function definition`

Is there anything I’m doing wrong or is `Unrolled.jl` just not able to deal with `where`s?

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [March 14, 2018, 1:40pm UTC](https://discourse.julialang.org/t/unrolled-jl-problems-with-where-keyword/9715/2 "2018-03-14T13:40:44Z")

</div>

Haven’t used Unrolled.jl before, but the readme and tests don’t show any examples of `@unroll function ...`, it’s just applied to `for` loops.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 14, 2018, 1:49pm UTC](https://discourse.julialang.org/t/unrolled-jl-problems-with-where-keyword/9715/3 "2018-03-14T13:49:46Z")

</div>

This looks like a bug in Unrolled.jl to me. The relevant line is here: [https://github.com/cstjean/Unrolled.jl/blob/b71319847801847426886ca0720a7b5277ca09ff/src/Unrolled.jl#L70](https://github.com/cstjean/Unrolled.jl/blob/b71319847801847426886ca0720a7b5277ca09ff/src/Unrolled.jl#L70) and should probably include an `@capture` that matches against functions with `where` clauses. You can play around with this yourself using MacroTools.jl:

```julia
julia> using MacroTools

julia> @capture(:(function foo(x); end), function fname_(args__) body__ end)
true

julia> @capture(:(function foo(x) where {T}; end), function fname_(args__) body__ end)
false

julia> @capture(:(function foo(x) where {T}; end), function fname_(args__) where {T__} body__ end)
true

```

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [March 17, 2018, 8:14pm UTC](https://discourse.julialang.org/t/unrolled-jl-problems-with-where-keyword/9715/4 "2018-03-17T20:14:36Z")

</div>

Should be fixed on Unrolled.jl’s `master`. Thank you for the bug report.

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [March 17, 2018, 8:23pm UTC](https://discourse.julialang.org/t/unrolled-jl-problems-with-where-keyword/9715/5 "2018-03-17T20:23:45Z")

</div>

If you’re using MacroTools, you might be interested in [`splitdef`](https://github.com/MikeInnes/MacroTools.jl#function-definitions) and `combinedef` for processing function definitions.
