# New array syntax inside functions

**URL:** <https://discourse.mc-stan.org/t/new-array-syntax-inside-functions/32892>\
**Category:** CmdStan\
**Created:** [September 26, 2023, 12:50pm UTC](https://discourse.mc-stan.org/t/new-array-syntax-inside-functions/32892 "2023-09-26T12:50:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxbiostat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/maxbiostat/32/1326_2.png) [@maxbiostat](https://discourse.mc-stan.org/u/maxbiostat)\
**Post date:** [September 26, 2023, 12:50pm UTC](https://discourse.mc-stan.org/t/new-array-syntax-inside-functions/32892/1 "2023-09-26T12:50:17Z")

</div>

I’m struggling to understand what the new (2.33.1) version of cmdstan expects from me.

I have code like this in the `functions` block

```stan
real logFunction(int k, real[] pars){
  real r = pars[1];
  real w = pars[2];
  real p = pars[3];
  real s = pars[4];
  real ans = lbin(s, k, p) + size_lpmf(k | r, w);
  return(ans);
}

```

which gives

```plaintext
Error in '/tmp/Rtmpk6Sttv/model-60c058a9b77d.stan', line 4, column 21: Declaration
    of arrays by placing brackets after a type was removed in Stan 2.33.0.
    Instead use the array keyword before the type. This can be changed
    automatically using the auto-format flag to stanc

```

OK. So I then change to

```stan
real logFunction(int k, array[4] real pars){
  real r = pars[1];
  real w = pars[2];
  real p = pars[3];
  real s = pars[4];
  real ans = lbin(s, k, p) + size_lpmf(k | r, w);
  return(ans);
}

```

which in turn gives

```plaintext
'/tmp/Rtmpk6Sttv/model-60c0517b60e9a.stan', line 2, column 2, parsing error:
   -------------------------------------------------
    12: }
    13: }
    14: real logFunction(int k, array[4] real pars){
                                       ^
    15: real r = pars[1];
    16: real w = pars[2];
   -------------------------------------------------

"[" (list of commas) "]" expected in unsized return type of function definition.

```

What exactly is a “list of commas”? Nevermind, let’s list out the commas manually then, I suppose:

```stan
real logFunction(int k, array[,,,] real pars){
  real r = pars[1];
  real w = pars[2];
  real p = pars[3];
  real s = pars[4];
  real ans = lbin(s, k, p) + size_lpmf(k | r, w);
  return(ans);
}

```

and now

```stan
'/tmp/Rtmpk6Sttv/model-60c052a33c004.stan', line 2, column 2:
   -------------------------------------------------
    13: }
    14: real logFunction(int k, array[,,,] real pars){
    15: real r = pars[1];
           ^
    16: real w = pars[2];
    17: real p = pars[3];
   -------------------------------------------------

Ill-typed arguments supplied to assignment operator =: lhs has type real and rhs has type array[,,] real

```

How do I get the right specification here? Consulting [the reference](https://mc-stan.org/docs/reference-manual/array-data-types.html) did very little for me, I’m afraid to say.

I’m confused as to (i) what is going on and (ii) where to look for guidance. I apologise if this is a silly question, but I’ve been coding in Stan for a long while and never had this much difficulty getting something this simple to work.

@rok_cesnovar@andrjohns

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [September 26, 2023, 12:58pm UTC](https://discourse.mc-stan.org/t/new-array-syntax-inside-functions/32892/2 "2023-09-26T12:58:27Z")

</div>

`real[] pars` becomes `array[] real pars`

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [September 26, 2023, 1:14pm UTC](https://discourse.mc-stan.org/t/new-array-syntax-inside-functions/32892/3 "2023-09-26T13:14:30Z")

</div>

@andrjohns answered the question, but to provide more information the relevant documentation is here: [9.4 Argument types and qualifiers | Stan Reference Manual](https://mc-stan.org/docs/reference-manual/argument-types-and-qualifiers.html#dimensionality-declaration)

---

<div class="post-metadata">

**Author:** ![maxbiostat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/maxbiostat/32/1326_2.png) [@maxbiostat](https://discourse.mc-stan.org/u/maxbiostat)\
**Post date:** [September 26, 2023, 1:28pm UTC](https://discourse.mc-stan.org/t/new-array-syntax-inside-functions/32892/4 "2023-09-26T13:28:12Z")

</div>

Thanks. What was throwing me off is that I have a bunch of other errors from other deprecated functions, and those were getting mixed up with this one. The deprecations in 2.33 caught me off guard.
