2

I've been having a strange problem with Module. Oddly it seems to be linked to my use of Import and then applying a function such as Flatten to my Import. I pasted images of my code and output because there also seems to be an issues with regard to the cells that the code is in. I'm using 64 bit version 10.0.1.0.

enter image description here

Now I apply Flatten to inputData:

enter image description here

Oddly, if I put the statement inputData in the first cell, then everything works.

enter image description here

If I go back to my second set of code, but remove the Module, then again everything works.

enter image description here

The spreadsheet is just 4 rows, as you see in the output. This is simplified from the actual problem I'm working on. It seems that Mathematica is not making the assignment to inputData, but rather somehow keeping it linked to the Import statement until the end of the Module.

Mitchell Kaplan
  • 3,696
  • 22
  • 34
  • Really weird. This behavior doesn't exist if you input the entire file path into the Import function (C:\\Users\\username\\test1.xlsx). – kale Oct 13 '14 at 17:45
  • 1
    Could you please insert FullForm@inputData before the Flatten? – Dr. belisarius Oct 13 '14 at 17:47
  • @kale I tried that in my full version and sometimes it worked and other times it didn't. But that was getting so complicated that I can't be sure that I repeated my steps accurately. – Mitchell Kaplan Oct 13 '14 at 17:49
  • Even weirder, if you place Trace around the x = Flatten[inputData];, all values seem to be assigned correctly. Otherwise x still equals Flatten[$Failed]. – kale Oct 13 '14 at 17:50
  • @belisarius inputData is okay if I put in Flatten[FullForm@inputData], but it doesn't flatten the lists. I also tried putting FullForm around Flatten, which sometimes fixes it - as long as I put a semicolon at the end. If I don't put the semicolon it displays FullForm, but then inputData in the next cell fails. I tried the semicolon before and after the last square bracket. They both worked? – Mitchell Kaplan Oct 13 '14 at 18:05
  • I cannot duplicate this problem on my Mac running OS X (10.9.5) and Mma 10.0.1 – Bob Hanlon Oct 13 '14 at 18:16
  • I can confirm this exhibits the odd demonstrated behavior on a linux install of MMA 10.0.1 - out of curiosity - what are you trying to do with this strange scoping in the first place? – SEngstrom Oct 13 '14 at 18:18
  • @SEngstrom This was the smallest example I could think of to demonstrate the problems I'm having. In "real life" I'm reading a bunch of data and then transforming it over the next few statements. During a lot of the transforming I create some variables (objects?) that won't be needed later. So I wanted to encapsulate the whole thing in a Module and make these temporary variables local. Primarily so that next month when I'm looking at the code I won't worry about whether they're needed. Maybe there's a better way to do that? – Mitchell Kaplan Oct 13 '14 at 18:32
  • Might want to contact support with a concise example that demonstrates the problem. – Daniel Lichtblau Oct 14 '14 at 01:06
  • @DanielLichtblau I submitted it to support this morning. – Mitchell Kaplan Oct 14 '14 at 13:29
  • Thanks. I'm sure they will ask but just to note: make sure they have full version/platform info if they do not already. – Daniel Lichtblau Oct 14 '14 at 14:53
  • @DanielLichtblau Yes, I gave them everything. They couldn't replicate it, but sent me a notebook they put together and asked me to evaluate it on my machine. I did, it had fails in it. They did try both Mac and Windows. – Mitchell Kaplan Oct 14 '14 at 15:15
  • 1
    If you have the Suggestions Bar turned on, does it make any difference if you turn it off? There have been reports of the Suggestions Bar mangling output. – WReach Oct 14 '14 at 16:31
  • @WReach I think that fixes it!!! I did a few tests and they succeeded. Thanks very much! I'll let Wolfram support know. – Mitchell Kaplan Oct 14 '14 at 16:37

1 Answers1

3

There have been reports in version 10.0.1 that the Suggestions Bar (aka Predictive Interface) sometimes mangles output values in notebooks. Try turning off the Suggestions Bar as described in this Wolfram Support Article.

Preferences dialog screenshot

WReach
  • 68,832
  • 4
  • 164
  • 269