Skip to main content
1 of 3
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Is the sharing of variables in Module/Block within Compile documented behavior?

Today I noticed something, I think for the first time.

When used inside Compile variable values within Module (and Block) are sequentially shared:

Compile[n, Module[{a = 7, b = a}, b + 1]] @ 1
8

Compare the behavior outside of Compile:

Module[{a = 7, b = a}, b + 1]
1 + a
  • Is this documented behavior or just a happy accident?

  • Can it be relied upon or should this "trick" be avoided?

Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k