# Syntax errors for a user defined function

**URL:** <https://discourse.mc-stan.org/t/syntax-errors-for-a-user-defined-function/21601>\
**Category:** Modeling\
**Created:** [March 30, 2021, 4:56pm UTC](https://discourse.mc-stan.org/t/syntax-errors-for-a-user-defined-function/21601 "2021-03-30T16:56:03Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![zcai](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zcai/32/10242_2.png) [@zcai](https://discourse.mc-stan.org/u/zcai)\
**Post date:** [April 6, 2021, 8:19pm UTC](https://discourse.mc-stan.org/t/syntax-errors-for-a-user-defined-function/21601/4 "2021-04-06T20:19:14Z")

</div>

Hi @martinmodrak, thanks a lot for asking. It was my mistake. I solved it by replacing `int evt_idx` with `int[] evt_idx` , since evt\_idx is a vector with integers in it.

May I ask another question regarding how to reverse a vector in a user-defined function? I found a similar post [Dot products of vectors to perform 1D convolution - #8 by zcai](https://discourse.mc-stan.org/t/dot-products-of-vectors-to-perform-1d-convolution/9053/8) and tried the solutions but they did not work. There is indeed a reverse() function but not yet available in rstan. Let’s say we have a for loop and inside it we just do a dot\_product between two vectors a and b, but we reverse the index of b from i to 1 instead of 1 to i. I tried the suggestion in the above post `dot_product(a[1:i], b[sort_desc(1:i)]);`, but I got syntax error. Do you think I can only do it with a user-defined reverse funciton? or I just missed something here. Sorry I am not familiar with stan lib for user defined functions.

---

_[View the full topic](https://discourse.mc-stan.org/t/syntax-errors-for-a-user-defined-function/21601)._
