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.

I am creating a Mathematica document which contains a list of proofs in various fields of Mathematics so that I can easily review whenever I would like. First, I create a large set I call 'proofs' that is of this format:

proofs={
  {1, "Analysis Proof", "Hint", "Solution"},
  {2, "Algebra Proof",  "Hint", "Solution"}
};

where the number represents the field of Mathematics (so I can later possibly specify the type of review), the next input is the proof statement, the hint is a hint, and the solution is either a reference of where to find the proof or the proof itself.

I then wrote the following function (code found below) which picks random problems from 'proofs' and asks you to prove the statement. You can then move on to the next question, ask for a hint, or see the solution. The idea is that when you ask for a hint, you can read the hint and when you click 'Ok', it gives the solution which you can read over, you click 'Okay' then it moves on to the next problem. Similarly, if you chose 'Solution', it would bring up the solution which you could read, then you would click 'Ok' and move on. If you chose 'Next Problem', you get another question. Finally, if you chose 'End Practice', it quits the review and prints how many practice proofs, i.e. the variable i, you did.

My question: The code works up to a point. The code I wrote does not force the program to 'wait'. Meaning, if I chose 'Hint', it gives the hint but does not wait for the user to hit 'Okay' before giving the solution and printing the next problem. Or if one chose 'Solution', it does not wait for the person to read it over before creating a new dialog box with the next question. This creates a problem of compiling text boxes that become very irritating and get in the way.

What code would you need to add to make Mathematica wait before printing the next question/solution? Of course, my code may be generally very inefficient or non-practical for creating this type of program, so any advice to how I am creating this is of course welcomed!

prob[x_] := Module[{},
  i = 1;

  Label[begin];
  p = RandomInteger[{1, Length[proofs]}];
  do = ChoiceDialog[
    proofs[[p, 2]], {"Hint" -> 1, "Solution" -> 2, 
     "Next Problem" -> 3, "End Pracitce" -> 4}];

  i++;

  If[do == 1, Goto[hint], 
  If[do == 2, Goto[solution], If[do == 3, Goto[begin], Goto[end]]]];

  Label[hint];
  CreateDialog[{TextCell[proofs[[p, 3]]], DefaultButton[]}];
  MessageDialog[proofs[[p, 4]]];
  Goto[begin];

  Label[solution];
  MessageDialog[proofs[[p, 4]]];
  Goto[begin];

  Label[end];
  Print["You did", i "proof review."];
  ]
share|improve this question
    
You need something more like (e.g. for the "hint") DialogInput[{TextCell[proofs[[p, 3]]], Button["OK", DialogReturn[1]]}]. Probably worth your time to fully absorb the documentation re: interactive notebooks. Many good examples. Also, writing MM code like visual basic tends to make things hard to follow, and is generally inefficient. Many good examples again in the docs. –  rasher Feb 2 at 5:09
    
@rasher I am a mathematician by trade so my coding layout is just what is most natural for me to read and follow since I lack formal training. But thank you, I had read through the Interactive Notebook on user inputs and it was not readily apparent to me what I needed. This worked perfectly. Feel free to post this as your answer so you can get something at least for settling the issue so quickly and efficiently. Thanks again! –  mathematics2x2life Feb 2 at 18:32
    
Glad it was useful, many ways to do the same thing. As far as code style, understood, and I'm sure you're aware of the trade-offs. –  rasher Feb 2 at 23:04
    
Indeed, but I am thankful for a forum such as this where I can ask questions such as this as well as view other questions/answers to see examples to improve my MM coding syntax. –  mathematics2x2life Feb 2 at 23:47
add comment

1 Answer

up vote 2 down vote accepted

You need something more like (e.g. for the "hint"):

DialogInput[{TextCell[proofs[[p, 3]]], Button["OK", DialogReturn[1]]}]. 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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