alashworth / test-issue-import

0 stars 0 forks source link

Feature request: disallow ++ #64

Open alashworth opened 5 years ago

alashworth commented 5 years ago

Issue by ksvanhorn Friday Mar 13, 2015 at 18:04 GMT Originally opened as https://github.com/stan-dev/stan/issues/1365


I had some Stan code that had the lines

idx <- 0;
shparms[++idx] <- logit_lambda;

thinking that I was using the pre-increment operator on idx. Instead, it appears that "++idx" was interpreted as +(+idx), i.e., just idx. This is correct according to the published syntax reference, but unexpected. I suggest that "++" should be parsed as one token and, as long as pre-increment isn't supported, should give an error.

alashworth commented 5 years ago

Comment by bob-carpenter Saturday Mar 14, 2015 at 00:07 GMT


Good point. This is very confusing. And it'll probably also crop up with x-- + x, which I'm guessing would get parsed as (x - (-+x)) == (x + x).

I see four options

Does anyone else have an opinion? And if we go with the first option, do we also add post increment,

On Mar 14, 2015, at 5:04 AM, Kevin S. Van Horn notifications@github.com wrote:

I had some Stan code that had the lines

idx <- 0; shparms[++idx] <- logit_lambda;

thinking that I was using the pre-increment operator on idx. Instead, it appears that "++idx" was interpreted as +(+idx), i.e., just idx. This is correct according to the published syntax reference, but unexpected. I suggest that "++" should be parsed as one token and, as long as pre-increment isn't supported, should give an error.

— Reply to this email directly or view it on GitHub.

alashworth commented 5 years ago

Comment by syclik Saturday Mar 14, 2015 at 00:57 GMT


Would it be possible to only allow x++ and ++x for ints only?

If so, I would vote including ++ for ints and option 3, trap and raise an error.

If not, then option 1. I'd also want a += type operator, but not sure what that would look like. <+ looks weird to me, but I also had to get used to <-.

On Friday, March 13, 2015, Bob Carpenter notifications@github.com wrote:

Good point. This is very confusing. And it'll probably also crop up with x-- + x, which I'm guessing would get parsed as (x - (-+x)) == (x + x).

I see four options

  • add ++x and --x to Stan's language with the usual semantics
  • trap uses of ++x, --x, x++, x-- and print warnings
  • trap uses and raise an error
  • just get rid of (+x) as it's useless from within Stan itself (and frankly, also pretty useless within C++ itself, but we want to leave it there so all C++ programs work as expected).

Does anyone else have an opinion? And if we go with the first option, do we also add post increment,

  • add x++ and x-- to the language
  • Bob

On Mar 14, 2015, at 5:04 AM, Kevin S. Van Horn <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:

I had some Stan code that had the lines

idx <- 0; shparms[++idx] <- logit_lambda;

thinking that I was using the pre-increment operator on idx. Instead, it appears that "++idx" was interpreted as +(+idx), i.e., just idx. This is correct according to the published syntax reference, but unexpected. I suggest that "++" should be parsed as one token and, as long as pre-increment isn't supported, should give an error.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/stan-dev/stan/issues/1365#issuecomment-79549935.