Skip to main content
edited tags
Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
edited body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

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

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

Compile[nCompile[{}, Module[{a = 7, b = a}, b + 1]] @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?

  • CanIf undocumented can it be relied upon or should this "trick" be avoided?

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?

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

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

Compile[{}, Module[{a = 7, b = a}, b + 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?

  • If undocumented can it be relied upon or should this "trick" be avoided?

Tweeted twitter.com/#!/StackMma/status/303403318137475072
Source Link
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?