Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I have just bought Mathematica and I'm in the process of plowing through Shifrin's great book. On page 74 the function oddSublists doesn't give me the expected output.

Since I'm a true beginner, I of course suspect mistakes on my behalf. I get: {{}, {, 2}, {, 2, 3, 4, 5}, {, 2, 3, 4, 5, 6}}

However the function oddSublistsNew gives me the expected output.{{1}, {1, 2}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}}

Anyone had similar experience?

And here is the code I forgot to include:

Clear[oddSublists];
oddSublists[x_List] := 
 Part[x, Union[
   Flatten[Cases[
     Map[First, 
      Split[Position[x, _?OddQ], First[#1] == First[#2] &], {2}], 
      y_List /; OddQ[Length[y]]]]]]
share|improve this question

marked as duplicate by Oleksandr R., Yves Klett, rasher, rm -rf Apr 27 at 16:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Welcome to Mathematica.Stackexchange. We prefer self-contained questions, so it would be better if you could post the code for oddSublists and ask why it doesn't work. –  Pickett Mar 8 at 21:47
    
I suspect a transcription error, so as @Pickett notes please post the code you are actually using. –  Mr.Wizard Mar 8 at 21:48
    
With complextestlist1 = Range /@ Range[6] the code you posted gives me the expected output. –  Pickett Mar 8 at 22:11
    
@Pickett: That's odd. I run the complextestlist1 = Range /@ Range[6]on the line before oddSublists[] and that output looks correct: {{1}, {1, 2}, {1, 2, 3}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}}but the function returns the before mentioned output. –  MathLind Mar 8 at 22:14
    
@MathLind Try restarting your kernel and run the code again. Can't see why it would help in this particular scenario, but it's a thing to try. –  Pickett Mar 8 at 22:53

1 Answer 1

It seems that I have found the cause of my problem. Since I do not use an English keyboard, I often need to press Alt and Shift keys to obtain a } or ]. Sometimes I accidentally press ctrl or other key combinations. This seems to create three problems: 1. The notebook alerts with an orange color despite no visible errors. 2. The notebook alerts with a brown color and backspacing seems to be hampered. 3. The code does not work, in spite of no visible problems.

With errors 1 and 2, it is often sufficient to remove one or a few lines. But with error 3, I needs to erase the whole package because I cannot see where the error is.

Since practice makes perfect, these errors occur more rarely for me.

This is so far the best solution I have found. If anyone knows a better method for visualizing hidden characters, please comment.

Leonid Shifrins advice to develop more complex code by first writing and evaluating one-liners, seems at this point very relevant and appropriate.

share|improve this answer
1  
You could put a double quote on the start and on the end of your code and evaluate. My guess is that the invisible character should be visible in the output. Another option is to use Ctrl-Shift-E (Show Expression) on your cell to reveal its internal structure. The result may sometimes somewhat overwhelming but with some luck you should be able to spot the offender, remove it and restore the cell with the same key code. –  Sjoerd C. de Vries Apr 27 at 7:37
    
@SjoerdC.deVries: Certainly an overwhelming output, but this gives me a new handle on the problem. Haven't seen those tricks before. Thanks. –  MathLind Apr 27 at 8:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.