alashworth / test-issue-import

0 stars 0 forks source link

Add integer increment operator "++" to Stan language #145

Open alashworth opened 5 years ago

alashworth commented 5 years ago

Issue by mitzimorris Tuesday Jun 13, 2017 at 22:16 GMT Originally opened as https://github.com/stan-dev/stan/issues/2322


Summary:

Add the postfix version of the increment operator "++" to Stan language for integer types, which can be in expressions or as a statement, e.g.:

`int i;
...
i++;

The semantics of the postfix increment operator are:

The same result can be gotten from:

i += 1;

https://github.com/stan-dev/stan/issues/1787, which has been implemented here: https://github.com/stan-dev/stan/tree/feature/1787-compound-assign-ops-scalars

It's not clear we need this feature as well.

Description:

The "++" operator is useful when incrementing (and decrementing) counters.

Both Java and C++ (hence the name) support this operator. However R and Python don't. Java and C++ have both prefix and postfix versions of this operator, with different semantics.

Current Version:

v2.15.0

alashworth commented 5 years ago

Comment by bob-carpenter Wednesday Jun 14, 2017 at 02:53 GMT


I asked @mitzimorris to file the issue, but wanted to add what we were discussing with @seantalts:

  1. The operators aren't in either R or Python

  2. The postfix form in particular has a confusing semantics (as noted in the issue).

  3. The prefix form will actually change behavior of --x and ++x, which are equal to -(-(x)) and +(+(x)) and both evaluate to x. Now they are prefix operators.

  4. The operation is restricted to indexed variables, just like assignments, rather than everything else we have which is restricted to assignments.

The main reason we have n = n + 1 and whatnot in the code is that we are either counting or incremeting some index that isn't tracking the loop indexes.