Skip to main content
1 of 3
user202729
  • 502
  • 3
  • 11

Mathematica 9 can't compile Increment Part with C

Why can't Mathematica 9 compile this code?

x = {1};
Compile[{}, x[[1]]++;,
    {{x[[1]]++, _Integer}, {x[[1]], _Integer}}, CompilationTarget :> "C"][]

After printed message CompiledFunction::cflist, the value of x is (in my case) {2 + Compile``Variable$29510}. (only 1 backquote in code)

Searching this site for "Compile Increment" found Faster list duplicate 'limiter', where an Increment is used in Compile and run correctly. I tried to fix my code using Block:

Compile[{}, Block[{x}, x = {1}; x[[1]]++; x[[1]] ], CompilationTarget :> "C"][]

Those also work.

x = {1}; Compile[{}, x[[1]] += 1;, CompilationTarget :> "C"][]

(replace ++ by +=1) or

x = {1}; Compile[{}, x[[1]]++;][]

(remove CompilationTarget -> "C" part)

This seems like a bug. Is that fixed in Mathematica 10?

user202729
  • 502
  • 3
  • 11